1、下载nacos源码
git clone git@github.com:alibaba/nacos.git
2、引入瀚高驱动
<dependency>
<groupId>com.highgo</groupId>
<artifactId>jdbc</artifactId>
<version>${highgo.version}</version>
</dependency>
3、DataSourceConstant定义瀚高数据库类型
public static final String HIGHGO = "highgo";
4、 新增TrustedHighgoFunctionEnum枚举,定义相关函数
/*
* Copyright 1999-2018 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.enums.highgo;
import java.util.HashMap;
import java.util.Map;
/**
* The TrustedSqlFunctionEnum enum class is used to enumerate and manage a list of trusted built-in SQL functions.
* By using this enum, you can verify whether a given SQL function is part of the trusted functions list
* to avoid potential SQL injection risks.
*
* @author blake.qiu
*/
public enum TrustedHighgoFunctionEnum {
/**
* NOW().
*/
NOW("NOW()", "CURRENT_TIMESTAMP(3)");
private static final Map<String, TrustedHighgoFunctionEnum> LOOKUP_MAP = new HashMap<>();
static {
for (TrustedHighgoFunctionEnum entry : TrustedHighgoFunctionEnum.values()) {
LOOKUP_MAP.put(entry.functionName, entry);
}
}
private final String functionName;
private final String function;
TrustedHighgoFunctionEnum(String functionName, String function) {
this.functionName = functionName;
this.function = function;
}
/**
* Get the function name.
*
* @param functionName function name
* @return function
*/
public static String getFunctionByName(String functionName) {
TrustedHighgoFunctionEnum entry = LOOKUP_MAP.get(functionName);
if (entry != null) {
return entry.function;
}
throw new IllegalArgumentException(String.format("Invalid function name: %s", functionName));
}
}
5、 编写瀚高实现类
package com.alibaba.nacos.plugin.datasource.impl.highgo;
import com.alibaba.nacos.plugin.datasource.enums.highgo.TrustedHighgoFunctionEnum;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
/**
* The abstract highgo mapper contains CRUD methods.
*
* @author blake.qiu
**/
public abstract class AbstractMapperByHighgo extends AbstractMapper {
@Override
public String getFunction(String functionName) {
return TrustedHighgoFunctionEnum.getFunctionByName(functionName);
}
}
/*
* 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.mapper.ConfigInfoBetaMapper;
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 highgo implementation of ConfigInfoBetaMapper.
*
* @author hyx
**/
public class ConfigInfoBetaMapperByHighgo extends AbstractMapperByHighgo implements ConfigInfoBetaMapper {
@Override
public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext context) {
int startRow = context.getStartRow();
int pageSize = context.getPageSize();
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 LIMIT " + startRow + "," + pageSize + " )"
+ " g, config_info_beta t WHERE g.id = t.id ";
List<Object> paramList = new ArrayList<>();
paramList.add(startRow);
paramList.add(pageSize);
return new MapperResult(sql, paramList);
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
/*
* 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.mapper.ConfigInfoGrayMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.util.Collections;
/**
* The highgo implementation of ConfigInfoGrayMapper.
*
* @author rong
**/
public class ConfigInfoGrayMapperByHighgo extends AbstractMapperByHighgo implements ConfigInfoGrayMapper {
@Override
public MapperResult findAllConfigInfoGrayForDumpAllFetchRows(MapperContext context) {
String sql = " SELECT id,data_id,group_id,tenant_id,gray_name,gray_rule,app_name,content,md5,gmt_modified "
+ " FROM config_info_gray ORDER BY id LIMIT " + context.getStartRow() + "," + context.getPageSize();
return new MapperResult(sql, Collections.emptyList());
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
/*
* 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.ArrayUtils;
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.mapper.ConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ext.WhereBuilder;
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 highgo implementation of ConfigInfoMapper.
*
* @author hyx
**/
public class ConfigInfoMapperByHighgo extends AbstractMapperByHighgo 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= ?" + " LIMIT " + context.getStartRow() + ","
+ context.getPageSize();
return new MapperResult(sql, CollectionUtils.list(tenantId, appName));
}
@Override
public MapperResult getTenantIdList(MapperContext context) {
String sql = "SELECT tenant_id FROM config_info WHERE tenant_id != '" + NamespaceUtil.getNamespaceDefaultId()
+ "' GROUP BY tenant_id LIMIT " + context.getStartRow() + "," + context.getPageSize();
return new MapperResult(sql, Collections.emptyList());
}
@Override
public MapperResult getGroupIdList(MapperContext context) {
String sql = "SELECT group_id FROM config_info WHERE tenant_id ='" + NamespaceUtil.getNamespaceDefaultId()
+ "' GROUP BY group_id LIMIT " + context.getStartRow() + "," + context.getPageSize();
return new MapperResult(sql, 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 LIMIT " + context.getStartRow() + ","
+ context.getPageSize() + " )" + " 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) {
String sql =
"SELECT t.id,data_id,group_id,content,md5" + " FROM ( SELECT id FROM config_info ORDER BY id LIMIT "
+ context.getStartRow() + "," + context.getPageSize() + " )"
+ " g, config_info t WHERE g.id = t.id ";
return new MapperResult(sql, Collections.emptyList());
}
@Override
public MapperResult findAllConfigInfoFragment(MapperContext context) {
String contextParameter = context.getContextParameter(ContextConstant.NEED_CONTENT);
boolean needContent = contextParameter != null && Boolean.parseBoolean(contextParameter);
String sql = "SELECT id,data_id,group_id,tenant_id,app_name," + (needContent ? "content," : "")
+ "md5,gmt_modified,type,encrypted_data_key FROM config_info WHERE id > ? ORDER BY id ASC LIMIT "
+ context.getStartRow() + "," + context.getPageSize();
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID)));
}
@Override
public MapperResult findChangeConfigFetchRows(MapperContext context) {
final String tenant = (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 tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
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,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(tenantTmp)) {
where += " AND tenant_id = ? ";
paramList.add(tenantTmp);
}
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 + " AND id > " + context.getWhereParameter(FieldConstant.LAST_MAX_ID)
+ " ORDER BY id ASC" + " LIMIT " + 0 + "," + context.getPageSize(), paramList);
}
@Override
public MapperResult listGroupKeyMd5ByPageFetchRows(MapperContext context) {
String sql = "SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "
+ "( SELECT id FROM config_info ORDER BY id LIMIT " + context.getStartRow() + ","
+ context.getPageSize() + " ) g, config_info t WHERE g.id = t.id";
return new MapperResult(sql, Collections.emptyList());
}
@Override
public MapperResult findConfigInfoBaseLikeFetchRows(MapperContext context) {
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 sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
String where = " 1=1 AND tenant_id='" + NamespaceUtil.getNamespaceDefaultId() + "' ";
List<Object> paramList = new ArrayList<>();
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(content)) {
where += " AND content LIKE ? ";
paramList.add(content);
}
return new MapperResult(sqlFetchRows + where + " LIMIT " + context.getStartRow() + "," + context.getPageSize(),
paramList);
}
@Override
public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
final String tenant = (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,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id=? ");
paramList.add(tenant);
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 + " LIMIT " + context.getStartRow() + "," + context.getPageSize(),
paramList);
}
@Override
public MapperResult findConfigInfoBaseByGroupFetchRows(MapperContext context) {
String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=?" + " LIMIT "
+ context.getStartRow() + "," + context.getPageSize();
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.GROUP_ID),
context.getWhereParameter(FieldConstant.TENANT_ID)));
}
@Override
public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
final String tenant = (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);
final String[] types = (String[]) context.getWhereParameter(FieldConstant.TYPE);
WhereBuilder where = new WhereBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key,type FROM config_info");
where.like("tenant_id", tenant);
if (StringUtils.isNotBlank(dataId)) {
where.and().like("data_id", dataId);
}
if (StringUtils.isNotBlank(group)) {
where.and().like("group_id", group);
}
if (StringUtils.isNotBlank(appName)) {
where.and().eq("app_name", appName);
}
if (StringUtils.isNotBlank(content)) {
where.and().like("content", content);
}
if (!ArrayUtils.isEmpty(types)) {
where.and().in("type", types);
}
where.limit(context.getStartRow(), context.getPageSize());
return where.build();
}
@Override
public MapperResult findAllConfigInfoFetchRows(MapperContext context) {
String sql = "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 LIMIT ?,? )"
+ " g, config_info t WHERE g.id = t.id ";
return new MapperResult(sql,
CollectionUtils.list(context.getWhereParameter(FieldConstant.TENANT_ID), context.getStartRow(),
context.getPageSize()));
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
/*
* 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.mapper.ConfigInfoTagMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.util.Collections;
/**
* The highgo implementation of ConfigInfoTagMapper.
*
* @author hyx
**/
public class ConfigInfoTagMapperByHighgo extends AbstractMapperByHighgo 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 LIMIT " + context.getStartRow() + ","
+ context.getPageSize() + " ) " + "g, config_info_tag t WHERE g.id = t.id ";
return new MapperResult(sql, Collections.emptyList());
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
/*
* 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.ArrayUtils;
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.mapper.ConfigTagsRelationMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ext.WhereBuilder;
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 highgo implementation of ConfigTagsRelationMapper.
*
* @author hyx
**/
public class ConfigTagsRelationMapperByHighgo extends AbstractMapperByHighgo implements ConfigTagsRelationMapper {
@Override
public MapperResult findConfigInfo4PageFetchRows(MapperContext context) {
final String tenant = (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);
final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);
List<Object> paramList = new ArrayList<>();
StringBuilder where = new StringBuilder(" WHERE ");
final String sql =
"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(tenant);
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(") ");
return new MapperResult(sql + where + " LIMIT " + context.getStartRow() + "," + context.getPageSize(),
paramList);
}
@Override
public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
final String tenant = (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);
final String[] tagArr = (String[]) context.getWhereParameter(FieldConstant.TAG_ARR);
final String[] types = (String[]) context.getWhereParameter(FieldConstant.TYPE);
WhereBuilder where = new WhereBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content,a.type "
+ "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id");
where.like("a.tenant_id", tenant);
if (StringUtils.isNotBlank(dataId)) {
where.and().like("a.data_id", dataId);
}
if (StringUtils.isNotBlank(group)) {
where.and().like("a.group_id", group);
}
if (StringUtils.isNotBlank(appName)) {
where.and().eq("a.app_name", appName);
}
if (StringUtils.isNotBlank(content)) {
where.and().like("a.content", content);
}
if (!ArrayUtils.isEmpty(tagArr)) {
where.and().in("b.tag_name", tagArr);
}
if (!ArrayUtils.isEmpty(types)) {
where.and().in("a.type", types);
}
where.limit(context.getStartRow(), context.getPageSize());
return where.build();
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
/*
* 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.mapper.GroupCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
/**
* The highgo implementation of {@link GroupCapacityMapper}.
*
* @author lixiaoshuang
*/
public class GroupCapacityMapperByHighgo extends AbstractMapperByHighgo implements GroupCapacityMapper {
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
@Override
public MapperResult selectGroupInfoBySize(MapperContext context) {
String sql = "SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize()));
}
}
/*
* 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.mapper.HistoryConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
/**
* The highgo implementation of HistoryConfigInfoMapper.
*
* @author hyx
**/
public class HistoryConfigInfoMapperByHighgo extends AbstractMapperByHighgo implements HistoryConfigInfoMapper {
@Override
public MapperResult removeConfigHistory(MapperContext context) {
String sql = "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";
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,ext_info,publish_type,gray_name,gmt_create,gmt_modified "
+ "FROM his_config_info " + "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC LIMIT "
+ context.getStartRow() + "," + context.getPageSize();
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.DATA_ID),
context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID)));
}
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
/*
* 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.mapper.TenantCapacityMapper;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
/**
* The highgo implementation of TenantCapacityMapper.
*
* @author hyx
**/
public class TenantCapacityMapperByHighgo extends AbstractMapperByHighgo implements TenantCapacityMapper {
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
@Override
public MapperResult getCapacityList4CorrectUsage(MapperContext context) {
String sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID),
context.getWhereParameter(FieldConstant.LIMIT_SIZE)));
}
}
/*
* 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.mapper.TenantInfoMapper;
/**
* The highgo implementation of TenantInfoMapper.
*
* @author hyx
**/
public class TenantInfoMapperByHighgo extends AbstractMapperByHighgo implements TenantInfoMapper {
@Override
public String getDataSource() {
return DataSourceConstant.HIGHGO;
}
}
6、在META-INF/services/com.alibaba.nacos.plugin.datasource.mapper.Mapper 文件中添加瀚高Mapper类的全路径名
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.ConfigInfoGrayMapperByHighgo
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
7、 nacos-server打包
mvn -Prelease-nacos clean install -U
8、修改application.properties配置
spring.sql.init.platform=highgo
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:highgo://127.0.0.1:5866/nacos_dev?currentSchema=nacos_dev&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai
db.user.0=highgo
db.password.0=highgo
db.pool.config.driverClassName=com.highgo.jdbc.Driver