nacos编写瀚高数据库插件

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 {@Overridepublic 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 {@Overridepublic 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);}@Overridepublic 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 {@Overridepublic 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());}@Overridepublic 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";@Overridepublic 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));}@Overridepublic 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());}@Overridepublic 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());}@Overridepublic 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)));}@Overridepublic 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());}@Overridepublic 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)));}@Overridepublic 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);}@Overridepublic 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());}@Overridepublic 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);}@Overridepublic 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);}@Overridepublic 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)));}@Overridepublic 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();}@Overridepublic 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()));}@Overridepublic 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 {@Overridepublic 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());}@Overridepublic 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 {@Overridepublic 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);}@Overridepublic 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();}@Overridepublic 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 {@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}@Overridepublic 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 {@Overridepublic 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)));}@Overridepublic 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)));}@Overridepublic 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 {@Overridepublic String getDataSource() {return DataSourceConstant.HIGHGO;}@Overridepublic 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 {@Overridepublic 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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/22105.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

讯飞唤醒+VOSK语音识别+DEEPSEEK大模型+讯飞离线合成实现纯离线大模型智能语音问答。

在信息爆炸的时代&#xff0c;智能语音问答系统正以前所未有的速度融入我们的日常生活。然而&#xff0c;随着数据泄露事件的频发&#xff0c;用户对于隐私保护的需求日益增强。想象一下&#xff0c;一个无需联网、即可响应你所有问题的智能助手——这就是纯离线大模型智能语音…

后端Java Stream数据流的使用=>代替for循环

API讲解 对比 示例代码对比 for循环遍历 package cn.ryanfan.platformback.service.impl;import cn.ryanfan.platformback.entity.Algorithm; import cn.ryanfan.platformback.entity.AlgorithmCategory; import cn.ryanfan.platformback.entity.DTO.AlgorithmInfoDTO; im…

UE 播放视频

一.UI播放视频 1.导入视频文件至工程文件夹 2.文件夹内右健选择Media -> File Meida Source创建testFileMeidaSource文件。 编辑FilePath为当前视频 3.右键->Media->Media Player 创建testMediaPlayer文件 4.右键创建testMediaTexture。编辑MediaPlayer设置testMedia…

推荐一款AI大模型托管平台-OpenWebUI

推荐一款AI大模型托管平台-OpenWebUI 1. OpenWebUI 1. OpenWebUI什么? 官网地址&#xff1a;https://openwebui.com/ GitHub地址&#xff1a; https://github.com/open-webui/open-webui Open WebUI 是一个可扩展、功能丰富且用户友好的自托管 AI 平台&#xff0c;旨在完全离…

【Python项目】基于知识图谱的百科问答系统

【Python项目】基于知识图谱的百科问答系统 技术简介&#xff1a; 采用Python技术、MySQL数据库、Django框架、Scrapy爬虫等技术实现。 系统简介&#xff1a; 百科问答系统是一个基于知识图谱的问答平台&#xff0c;旨在为用户提供快速、准确的百科知识查询服务。系统通过爬…

stm32rtc实时时钟详解文章

目录 stm32 后备区域基础知识详解 stm32 bkp基础知识详解 Unix时间戳基础知识详解 stm32 rtc实时时钟基础知识详解 相关代码初始化配置 欢迎指正&#xff0c;希望对你&#xff0c;有所帮助&#xff01;&#xff01;&#xff01; stm32 后备区域基础知识详解 stm32芯片的 …

Spring Boot项目@Cacheable注解的使用

Cacheable 是 Spring 框架中用于缓存的注解之一&#xff0c;它可以帮助你轻松地将方法的结果缓存起来&#xff0c;从而提高应用的性能。下面详细介绍如何使用 Cacheable 注解以及相关的配置和注意事项。 1. 基本用法 1.1 添加依赖 首先&#xff0c;确保你的项目中包含了 Spr…

windows上vscode cmake工程搭建

安装vscode插件&#xff1a; 1.按装fastc&#xff08;主要是安装MinGW\mingw64比较方便&#xff09; 2.安装C&#xff0c;cmake&#xff0c;cmake tools插件 3.准备工作完成之后&#xff0c;按F1&#xff0c;选择cmake:Quick Start就可以创建一个cmake工程。 4.设置Cmake: G…

SpringMVC详解

文章目录 1 什么是MVC 1.1 MVC设计思想1.2 Spring MVC 2 SpringMVC快速入门3 SpringMVC处理请求 3.1 请求分类及处理方式 3.1.1 静态请求3.1.2 动态请求 3.2 处理静态请求 3.2.1 处理html文件请求3.2.2 处理图片等请求 3.3 处理动态请求 3.3.1 注解说明3.3.2 示例 3.4 常见问题…

【用deepseek和chatgpt做算法竞赛】——还得DeepSeek来 -Minimum Cost Trees_5

往期 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_0&#xff1a;介绍了题目和背景【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_1&#xff1a;题目输入的格式说明&#xff0c;选择了邻接表…

面试题汇总

1. 判断大小端问题 大端&#xff1a;低字节存放在高地址&#xff1b; 小端&#xff1a;低字节存放在低地址 如 : 0x12345678 bool is_little_endian() {unsigned int x 1;return ((char*)&x)[0]; }bool is_big_endian() {unsigned int x 1;return !((char*)&x)[0];…

jsherp importItemExcel接口存在SQL注入

一、漏洞简介 很多人说管伊佳ERP&#xff08;原名&#xff1a;华夏ERP&#xff0c;英文名&#xff1a;jshERP&#xff09;是目前人气领先的国产ERP系统虽然目前只有进销存财务生产的功能&#xff0c;但后面将会推出ERP的全部功能&#xff0c;有兴趣请帮点一下 二、漏洞影响 …

体验用ai做了个python小游戏

体验用ai做了个python小游戏 写在前面使用的工具2.增加功能1.要求增加视频作为背景。2.我让增加了一个欢迎页面。3.我发现中文显示有问题。4.我提出了背景修改意见&#xff0c;欢迎页面和结束页面背景是视频&#xff0c;游戏页面背景是静态图片。5.提出增加更多游戏元素。 总结…

动态存储斐波那契数列(递归优化)

递归 递归是c当中一种自身调用自身的算法。 普通递归解决斐波那契数列问题 #include<iostream> using namespace std; int f(int n){int sum;if(n<2){sum1;}else{sumf(n-1)f(n-2);}return sum; } int main() {int n;cin>>n;cout<<f(n);return 0;}当数据…

php文件上传

文章目录 文件上传机制文件上传脚本文件上传绕过php后缀替换为空web服务器的解析漏洞绕过nginxiisapache 高级文件上传nginx自定义配置文件&#xff08;默认三分钟刷新一次&#xff09;服务端内容检测结合伪协议使用配合日志包含只允许图片上传 上传实战训练 文件上传机制 文件…

播放器系列1——总概述

播放器核心架构 模块解释 文件读取 读取视频文件、读取网络文件、读取音频文件&#xff0c;大概分为这三种&#xff0c;目前代码中仅实现了读取视频文件播放&#xff0c;也就是当没有video数据的时候播放器不可使用。 解复用 容器指的是多媒体文件中的封装格式&#xff0c;…

【存储中间件API】MySQL、Redis、MongoDB、ES常见api操作及性能比较

常见中间件api操作及性能比较 ☝️ MySQL crud操作✌️ maven依赖✌️ 配置✌️ 定义实体类✌️ 常用api ☝️ Redis crud操作✌️ maven依赖✌️ 配置✌️ 常用api ☝️ MongoDB crud操作✌️ maven依赖✌️ 配置文件✌️ 定义实体类✌️ MongoDB常用api ☝️ ES crud操作 ⭐️…

【进程与线程】Linux 线程、同步以及互斥

每个用户进程有自己的地址空间。 线程是操作系统与多线程编程的基础知识。 系统为每个用户进程创建一个 task_struct 来描述该进程&#xff1a;该结构体中包含了一个指针指向该进程的虚拟地址空间映射表&#xff1a; 实际上 task_struct 和地址空间映射表一起用来表示一个进程…

实现动态翻转时钟效果的 HTML、CSS 和 JavaScript,附源码

实现动态翻转时钟效果的 HTML、CSS 和 JavaScript 在现代网页设计中&#xff0c;动画效果可以极大地增强用户体验。本文将介绍如何利用 HTML、CSS 和 JavaScript 创建一个动态翻转时钟的效果&#xff0c;模拟经典机械翻页时钟的视觉效果。我们将通过详细的步骤讲解如何实现时钟…

Spring Boot与MyBatis

Spring Boot与MyBatis的配置 一、简介 Spring Boot是一个用于创建独立的、基于Spring的生产级应用程序的框架&#xff0c;它简化了Spring应用的初始搭建以及开发过程。MyBatis是一款优秀的持久层框架&#xff0c;它支持定制化SQL、存储过程以及高级映射。将Spring Boot和MyBa…