NACOS 2.3.2适配瀚高数据库
1.背景
.jpg)
2.适配步骤
2.1 源码下载
Release 2.3.2 (Apr 3rd, 2024) · alibaba/nacos (github.com)

2.2 解压导入idea
compile编译


2.2.3 pom文件增加瀚高依赖
2.2.3.1 nacos-all
<dependency>
<groupId>com.highgo</groupId>
<artifactId>HgdbJdbc</artifactId>
<version>6.2.3</version>
</dependency>

2.2.3.2 nacos-config
<dependency>
<groupId>com.highgo</groupId>
<artifactId>HgdbJdbc</artifactId>
</dependency>

2.2.4 代码改造
2.2.4.1 nacos-config 模块修改数据库驱动名称
com/alibaba/nacos/persistence/datasource/ExternalDataSourceProperties.java
private static final String JDBC_DRIVER_NAME = "com.highgo.jdbc.Driver";
public static final String HIGHGO = "highgo";


根据SPI机制进行代码扩展
在 com/alibaba/nacos/plugin/datasource/impl 目录新建 highgo 目录,再在 highgo 目录新增实现类

ConfigInfoAggrMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.util.List;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class ConfigInfoAggrMapperByHighgo extends AbstractMapper implements ConfigInfoAggrMapper {
@Override
public MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) {
final Integer startRow = context.getStartRow();
final Integer pageSize = context.getPageSize();
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String groupId = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
String sql =
"SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
+ "group_id= ? AND tenant_id= ? ORDER BY datum_id " + " OFFSET " + startRow + " LIMIT " + pageSize;
List<Object> paramList = CollectionUtils.list(dataId, groupId, tenantId);
return new MapperResult(sql, paramList);
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_AGGR;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
ConfigInfoBetaMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.util.List;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class ConfigInfoBetaMapperByHighgo extends AbstractMapper implements ConfigInfoBetaMapper {
@Override
public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext context) {
final int startRow = context.getStartRow();
final int pageSize = context.getPageSize();
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String groupId = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
String sql =
" SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
+ " FROM ( SELECT id FROM config_info_beta ORDER BY id OFFSET " + startRow + " LIMIT " + pageSize + " )"
+ " g, config_info_beta t WHERE g.id = t.id ";
List<Object> paramList = CollectionUtils.list(dataId, groupId, tenantId);
return new MapperResult(sql, paramList);
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_BETA;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
ConfigInfoMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.ContextConstant;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class ConfigInfoMapperByHighgo extends AbstractMapper implements ConfigInfoMapper {
private static final String DATA_ID = "dataId";
private static final String GROUP = "group";
private static final String APP_NAME = "appName";
private static final String CONTENT = "content";
private static final String TENANT = "tenant";
@Override
public MapperResult findConfigInfoByAppFetchRows(MapperContext context) {
final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
String sql =
"SELECT ID,data_id,group_id,tenant_id,app_name,content FROM config_info "
+ "WHERE tenant_id LIKE ? AND "
+ "app_name = ?" + " OFFSET " + context.getStartRow() + " ROWS FETCH NEXT "
+ context.getPageSize() + " ROWS ONLY";
return new MapperResult(sql, CollectionUtils.list(tenantId, appName));
}
@Override
public MapperResult getTenantIdList(MapperContext context) {
return new MapperResult(
"SELECT tenant_id FROM config_info WHERE tenant_id != '" + NamespaceUtil.getNamespaceDefaultId()
+ "' GROUP BY tenant_id OFFSET " + context.getStartRow() + " LIMIT "
+ context.getPageSize(), Collections.emptyList());
}
@Override
public MapperResult getGroupIdList(MapperContext context) {
return new MapperResult(
"SELECT group_id FROM config_info WHERE tenant_id ='" + NamespaceUtil.getNamespaceDefaultId()
+ "' GROUP BY group_id OFFSET " + context.getStartRow() + " ROWS FETCH NEXT "
+ context.getPageSize() + " ROWS ONLY", Collections.emptyList());
}
@Override
public MapperResult findAllConfigKey(MapperContext context) {
String sql = " SELECT data_id,group_id,app_name FROM "
+ " ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id OFFSET " + context.getStartRow()
+ " ROWS FETCH NEXT " + context.getPageSize() + " ROWS ONLY ) "
+ "g, config_info t WHERE g.id = t.id ";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID)));
}
@Override
public MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) {
return new MapperResult(
"SELECT t.id,data_id,group_id,content,md5 " + " FROM ( SELECT id FROM config_info ORDER BY id OFFSET "
+ context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize() + " ROWS ONLY ) "
+ " g, config_info t WHERE g.id = t.id ", Collections.emptyList());
}
@Override
public MapperResult findAllConfigInfoFragment(MapperContext context) {
String contextParameter = context.getContextParameter(ContextConstant.NEED_CONTENT);
boolean needContent = contextParameter != null && Boolean.parseBoolean(contextParameter);
return new MapperResult("SELECT id,data_id,group_id,tenant_id,app_name," + (needContent ? "content," : "")
+ "md5,gmt_modified,type FROM config_info WHERE id > ? " + "ORDER BY id ASC OFFSET "
+ context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize() + " ROWS ONLY",
CollectionUtils.list(context.getWhereParameter(FieldConstant.ID)));
}
@Override
public MapperResult findChangeConfigFetchRows(MapperContext context) {
final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT);
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
final Timestamp startTime = (Timestamp) context.getWhereParameter(FieldConstant.START_TIME);
final Timestamp endTime = (Timestamp) context.getWhereParameter(FieldConstant.END_TIME);
List<Object> paramList = new ArrayList<>();
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM"
+ " config_info WHERE ";
String where = " 1=1 ";
if (!StringUtils.isBlank(dataId)) {
where += " AND data_id LIKE ? ";
paramList.add(dataId);
}
if (!StringUtils.isBlank(group)) {
where += " AND group_id LIKE ? ";
paramList.add(group);
}
if (!StringUtils.isBlank(tenant)) {
where += " AND tenant_id = ? ";
paramList.add(tenant);
}
if (!StringUtils.isBlank(appName)) {
where += " AND app_name = ? ";
paramList.add(appName);
}
if (startTime != null) {
where += " AND gmt_modified >=? ";
paramList.add(startTime);
}
if (endTime != null) {
where += " AND gmt_modified <=? ";
paramList.add(endTime);
}
return new MapperResult(
sqlFetchRows + where + " OFFSET " + context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize()
+ " ROWS ONLY", paramList);
}
@Override
public MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) {
return new MapperResult(" SELECT t.id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified "
+ "FROM ( SELECT id FROM config_info ORDER BY id OFFSET " + context.getStartRow() + " ROWS FETCH NEXT "
+ context.getPageSize() + " ROWS ONLY ) g, config_info t WHERE g.id = t.id", Collections.emptyList());
}
@Override
public MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) {
final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT);
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
List<Object> paramList = new ArrayList<>();
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
String where = " 1=1 AND tenant_id='" + NamespaceUtil.getNamespaceDefaultId() + "' ";
if (!StringUtils.isBlank(dataId)) {
where += " AND data_id LIKE ? ";
paramList.add(dataId);
}
if (!StringUtils.isBlank(group)) {
where += " AND group_id LIKE ? ";
paramList.add(group);
}
if (!StringUtils.isBlank(tenant)) {
where += " AND content LIKE ? ";
paramList.add(tenant);
}
return new MapperResult(
sqlFetchRows + where + " OFFSET " + context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize()
+ " ROWS ONLY", paramList);
}
@Override
public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
List<Object> paramList = new ArrayList<>();
final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id=? ");
paramList.add(tenantId);
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
paramList.add(dataId);
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
paramList.add(group);
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
paramList.add(appName);
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
paramList.add(content);
}
return new MapperResult(
sql + where + " OFFSET " + context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize()
+ " ROWS ONLY", paramList);
}
@Override
public MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) {
return new MapperResult(
"SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? " + "AND tenant_id=?" + " OFFSET "
+ context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize() + " ROWS ONLY",
CollectionUtils.list(context.getWhereParameter(FieldConstant.GROUP_ID),
context.getWhereParameter(FieldConstant.TENANT_ID)));
}
@Override
public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
List<Object> paramList = new ArrayList<>();
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id LIKE ? ");
paramList.add(tenantId);
if (!StringUtils.isBlank(dataId)) {
where.append(" AND data_id LIKE ? ");
paramList.add(dataId);
}
if (!StringUtils.isBlank(group)) {
where.append(" AND group_id LIKE ? ");
paramList.add(group);
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND app_name = ? ");
paramList.add(appName);
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
paramList.add(content);
}
String sql =
sqlFetchRows + where + " OFFSET " + context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize()
+ " ROWS ONLY";
return new MapperResult(sql, paramList);
}
@Override
public MapperResult findAllConfigInfoFetchRows(MapperContext context) {
return new MapperResult(" SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "
+ " FROM ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id OFFSET ? ROWS FETCH NEXT ? ROWS ONLY )"
+ " g, config_info t WHERE g.id = t.id ",
CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID), context.getStartRow(),
context.getPageSize()));
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
@Override
public MapperResult findChangeConfig(MapperContext context) {
String sql =
"SELECT id, data_id, group_id, tenant_id, app_name, content, gmt_modified, encrypted_data_key FROM config_info WHERE "
+ "gmt_modified >= ? and id > ? order by id OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME),
context.getWhereParameter(FieldConstant.LAST_MAX_ID),
context.getWhereParameter(FieldConstant.PAGE_SIZE)));
}
}
ConfigInfoTagMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.util.Collections;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class ConfigInfoTagMapperByHighgo extends AbstractMapper implements ConfigInfoTagMapper {
@Override
public MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext context) {
String sql = "SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "
+ " FROM ( SELECT id FROM config_info_tag ORDER BY id OFFSET " + context.getStartRow()
+ " ROWS FETCH NEXT " + context.getPageSize() + " ROWS ONLY ) "
+ " g, config_info_tag t WHERE g.id = t.id";
return new MapperResult(sql, Collections.emptyList());
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_TAG;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
ConfigTagsRelationMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.util.ArrayList;
import java.util.List;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class ConfigTagsRelationMapperByHighgo extends AbstractMapper implements ConfigTagsRelationMapper {
@Override
public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);
List<Object> paramList = new ArrayList<>();
StringBuilder where = new StringBuilder(" WHERE ");
final String baseSql =
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id";
where.append(" a.tenant_id=? ");
paramList.add(tenantId);
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
paramList.add(dataId);
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
paramList.add(group);
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
paramList.add(appName);
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
paramList.add(content);
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagArr.length; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
paramList.add(tagArr[i]);
}
where.append(") ");
String sql = baseSql + where + " OFFSET " + context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize()
+ " ROWS ONLY";
return new MapperResult(sql, paramList);
}
@Override
public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
final String tenantId = (String) context.getWhereParameter(FieldConstant.TENANT_ID);
final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);
List<Object> paramList = new ArrayList<>();
StringBuilder where = new StringBuilder(" WHERE ");
final String baseSql =
"SELECT a.ID,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id ";
where.append(" a.tenant_id LIKE ? ");
paramList.add(tenantId);
if (!StringUtils.isBlank(dataId)) {
where.append(" AND a.data_id LIKE ? ");
paramList.add(dataId);
}
if (!StringUtils.isBlank(group)) {
where.append(" AND a.group_id LIKE ? ");
paramList.add(group);
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND a.app_name = ? ");
paramList.add(appName);
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
paramList.add(content);
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagArr.length; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
paramList.add(tagArr[i]);
}
where.append(") ");
String sql = baseSql + where + " OFFSET " + context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize()
+ " ROWS ONLY";
return new MapperResult(sql, paramList);
}
@Override
public String getTableName() {
return TableConstant.CONFIG_TAGS_RELATION;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
GroupCapacityMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class GroupCapacityMapperByHighgo extends AbstractMapper implements GroupCapacityMapper {
@Override
public String getTableName() {
return TableConstant.GROUP_CAPACITY;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
@Override
public MapperResult selectGroupInfoBySize(MapperContext context) {
String sql = "SELECT id, group_id FROM group_capacity WHERE id > ? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
return new MapperResult(sql,
CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize()));
}
}
HistoryConfigInfoMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class HistoryConfigInfoMapperByHighgo extends AbstractMapper implements HistoryConfigInfoMapper {
@Override
public MapperResult removeConfigHistory(MapperContext context) {
String sql = "DELETE FROM his_config_info WHERE id IN( "
+ "SELECT id FROM his_config_info WHERE gmt_modified < ? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY)";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME),
context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
}
@Override
public MapperResult pageFindConfigHistoryFetchRows(MapperContext context) {
String sql =
"SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC OFFSET "
+ context.getStartRow() + " ROWS FETCH NEXT " + context.getPageSize() + " ROWS ONLY";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.DATA_ID),
context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID)));
}
@Override
public String getTableName() {
return TableConstant.HIS_CONFIG_INFO;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
@Override
public MapperResult findDeletedConfig(MapperContext context) {
return new MapperResult(
"SELECT data_id, group_id, tenant_id,gmt_modified,nid FROM his_config_info WHERE op_type = 'D' AND "
+ "gmt_modified >= ? and nid > ? order by nid OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY",
CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME),
context.getWhereParameter(FieldConstant.LAST_MAX_ID),
context.getWhereParameter(FieldConstant.PAGE_SIZE)));
}
}
TenantCapacityMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class TenantCapacityMapperByHighgo extends AbstractMapper implements TenantCapacityMapper {
@Override
public String getTableName() {
return TableConstant.TENANT_CAPACITY;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
@Override
public MapperResult getCapacityList4CorrectUsage(MapperContext context) {
String sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),
context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
}
}
TenantInfoMapperByHighgo.java
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper;
/**
* The derby implementation of ConfigInfoMapper.
*
* @author lizzu
**/
public class TenantInfoMapperByHighgo extends AbstractMapper implements TenantInfoMapper {
@Override
public String getTableName() {
return TableConstant.TENANT_INFO;
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
com.alibaba.nacos.plugin.datasource.mapper.Mapper 文件需添加如下内容:
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoAggrMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoBetaMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigInfoTagMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.ConfigTagsRelationMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.HistoryConfigInfoMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.TenantInfoMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.TenantCapacityMapperByHighgo
com.alibaba.nacos.plugin.datasource.impl.highgo.GroupCapacityMapperByHighgo
nacos-console模块
路径:nacos-2.3.2/console/src/main/resources/application.properties
server.servlet.contextPath=/nacos
server.error.include-message=ALWAYS
server.port=8848
spring.sql.init.platform=highgo
db.num=1
db.url.0=jdbc:highgo://IP:5866/nacos
db.user.0=nacos
db.password.0=Qwer@1234
db.pool.config.driverClassName=com.highgo.jdbc.Driver
spring.security.user.name=nacos
spring.security.user.password=nacos
nacos.naming.empty-service.auto-clean=true
nacos.naming.empty-service.clean.initial-delay-ms=50000
nacos.naming.empty-service.clean.period-time-ms=30000
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.max-days=30
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
server.tomcat.basedir=file:.
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false
nacos.core.auth.server.identity.key=authKey
nacos.core.auth.server.identity.value=sdzj-lizz-securty
nacos.core.auth.plugin.nacos.token.cache.enable=false
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
nacos.core.auth.plugin.nacos.token.secret.key=SecretKeyW6LqDmNvzzfZyFrL5cJAKH72YUfH2KNxmHYc2kPdt3yVyUgzkdUcWGgq7Rygv66b123
nacos.istio.mcp.server.enabled=false
2.2.5 瀚高DDL
-- 创建nacos用户
CREATE USER nacos WITH PASSWORD 'Qwer@1234';
-- 创建nacos数据库
CREATE DATABASE nacos OWNER nacos;
主要表结构(节选,完整见原文)
CREATE TABLE config_info (
id serial NOT NULL,
data_id varchar(255) NOT NULL,
group_id varchar(255) DEFAULT NULL,
content text NOT NULL,
md5 varchar(32) DEFAULT NULL,
gmt_create timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
gmt_modified timestamp NOT NULL DEFAULT '2010-05-05 00:00:00',
src_user text,
src_ip varchar(50) DEFAULT NULL,
app_name varchar(128) DEFAULT NULL,
tenant_id varchar(128) DEFAULT '',
c_desc varchar(256) DEFAULT NULL,
c_use varchar(64) DEFAULT NULL,
effect varchar(64) DEFAULT NULL,
type varchar(64) DEFAULT NULL,
c_schema text,
encrypted_data_key text NOT NULL,
PRIMARY KEY (id),
constraint uk_configinfo_datagrouptenant unique(data_id,group_id,tenant_id)
);
-- 其他表结构同理...
2.2.6 启动测试
设置单机启动参数: -Dnacos.standalone=true

本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Muzi
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果