当前位置:   article > 正文

nacos2.2.3多数据源适配,包括对达梦、kingbase等国产数据库适配_nacos适配达梦

nacos适配达梦

目录

1. 概要

版本

2. 具体解决方案细节

2.1 ExternalDataSourceProperties.java源码修改

2.2 plugin模块改造

2.2.1 DataSourceConstant.java

2.2.2 增加PrimaryKeyConstant.java类

2.2.3 新增对dialect的管理

2.2.3.1 新增DatabaseDialectManager类

2.2.3.2 新增package:com.alibaba.nacos.plugin.datasource.dialect

1. 新增接口 DatabaseDialect

2. 新增抽象类 AbstractDatabaseDialect

3. 新增默认实现类 DefaultDatabaseDialect

2.2.4 抽象BaseMapper

新增BaseConfigInfoAggrMapper

新增BaseConfigInfoBetaMapper

新增BaseConfigInfoMapper

新增BaseConfigInfoTagMapper

新增BaseConfigTagsRelationMapper

新增BaseGroupCapacityMapper

新增BaseTenantCapacityMapper

新增BaseTenantInfoMapper

2.2.5 达梦dm适配

1. 新增达梦的dialect实现以及Mapper

2. 支持达梦数据库错误码

3. 增加SPI加载

4. 达梦jdbc配置

5. dm脚本

6. 打包、指定加载依赖运行

2.2.6 kingbase8适配

1. 新增kingbase的dialect实现以及Mapper

2. 增加SPI加载

3. kingbase8 jdbc配置

4. kingbase8脚本

5. 打包、指定加载依赖运行

2.2.7 其他数据库的适配

1.脚本的适配

2.创建对应的Dialect以及mapper

3.配置SPI

4.修改datasource配置

5.jdbc驱动问题

6.打包运行


1. 概要

主要是为了信创,需要各种开源组件以及自身开发的产品对国产环境进行验证,其中最重要的一环就是国产数据库的适配,在借鉴了各位大佬的文章以及查阅了无数国产数据库官方文档之后,最后整理出了一版兼容以上数据库的案例,本人已经测试过了,完美运行。整理不易,望诸君高台贵手,点赞支持。

版本

nacos:2.2.3 

nacos源码下载什么的在这里就不做赘述了,直接github下载的,数据库版本也没多大限制,只要能跑脚本的一般都没啥问题

2. 具体解决方案细节

2.1 ExternalDataSourceProperties.java源码修改

修改这里主要是为了能自定义在配置文件里面配置driverClassName、testQuery等等自定义配置,反正都是源码修改,不在乎修改多少,这里一改,其他地方就能直接配置使用了,主打的就是省心,可直接复制下面代码覆盖源码,源码:com.alibaba.nacos.config.server.service.datasource.ExternalDataSourceProperties。

  1. /*
  2. * Copyright 1999-2018 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  5. * the License. You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  10. * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. * specific language governing permissions and limitations under the License.
  12. */
  13. package com.alibaba.nacos.config.server.service.datasource;
  14. import com.alibaba.nacos.common.utils.Preconditions;
  15. import com.alibaba.nacos.common.utils.StringUtils;
  16. import com.zaxxer.hikari.HikariDataSource;
  17. import org.apache.commons.collections.CollectionUtils;
  18. import org.springframework.boot.context.properties.bind.Bindable;
  19. import org.springframework.boot.context.properties.bind.Binder;
  20. import org.springframework.core.env.Environment;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.Objects;
  24. import static com.alibaba.nacos.common.utils.CollectionUtils.getOrDefault;
  25. /**
  26. * Properties of external DataSource.
  27. *
  28. * @author Nacos
  29. */
  30. public class ExternalDataSourceProperties {
  31. private static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
  32. private static final String TEST_QUERY = "SELECT 1";
  33. private Integer num;
  34. private List<String> url = new ArrayList<>();
  35. private List<String> user = new ArrayList<>();
  36. private List<String> password = new ArrayList<>();
  37. private List<String> driverClassName = new ArrayList<>();
  38. private List<String> testQuery = new ArrayList<>();
  39. public void setNum(Integer num) {
  40. this.num = num;
  41. }
  42. public void setUrl(List<String> url) {
  43. this.url = url;
  44. }
  45. public void setUser(List<String> user) {
  46. this.user = user;
  47. }
  48. public void setPassword(List<String> password) {
  49. this.password = password;
  50. }
  51. public List<String> getDriverClassName() {
  52. return driverClassName;
  53. }
  54. public void setDriverClassName(List<String> driverClassName) {
  55. this.driverClassName = driverClassName;
  56. }
  57. public void setTestQuery(List<String> testQuery) {
  58. this.testQuery = testQuery;
  59. }
  60. /**
  61. * Build serveral HikariDataSource.
  62. *
  63. * @param environment {@link Environment}
  64. * @param callback Callback function when constructing data source
  65. * @return List of {@link HikariDataSource}
  66. */
  67. List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {
  68. List<HikariDataSource> dataSources = new ArrayList<>();
  69. Binder.get(environment).bind("db", Bindable.ofInstance(this));
  70. Preconditions.checkArgument(Objects.nonNull(num), "db.num is null");
  71. Preconditions.checkArgument(CollectionUtils.isNotEmpty(user), "db.user or db.user.[index] is null");
  72. Preconditions.checkArgument(CollectionUtils.isNotEmpty(password), "db.password or db.password.[index] is null");
  73. Preconditions.checkArgument(CollectionUtils.isNotEmpty(driverClassName), "db.driverClassName or db.driverClassName.[index] is null");
  74. for (int index = 0; index < num; index++) {
  75. int currentSize = index + 1;
  76. Preconditions.checkArgument(url.size() >= currentSize, "db.url.%s is null", index);
  77. DataSourcePoolProperties poolProperties = DataSourcePoolProperties.build(environment);
  78. poolProperties.setDriverClassName(getOrDefault(driverClassName, index, JDBC_DRIVER_NAME).trim());
  79. poolProperties.setJdbcUrl(url.get(index).trim());
  80. poolProperties.setUsername(getOrDefault(user, index, user.get(0)).trim());
  81. poolProperties.setPassword(getOrDefault(password, index, password.get(0)).trim());
  82. HikariDataSource ds = poolProperties.getDataSource();
  83. if (StringUtils.isEmpty(ds.getConnectionTestQuery())) {
  84. ds.setConnectionTestQuery(getOrDefault(testQuery, index, TEST_QUERY).trim());
  85. }
  86. dataSources.add(ds);
  87. callback.accept(ds);
  88. }
  89. Preconditions.checkArgument(CollectionUtils.isNotEmpty(dataSources), "no datasource available");
  90. return dataSources;
  91. }
  92. interface Callback<D> {
  93. /**
  94. * Perform custom logic.
  95. *
  96. * @param datasource dataSource.
  97. */
  98. void accept(D datasource);
  99. }
  100. }

2.2 plugin模块改造

2.2.3版本的nacos已经适配了最新spring spi规范了,所以总体来讲开发一个nacos的插件是很容易的,并且源码里面已经给出了模板了,所以做一个nacos-datasource的plugin就直接在plugin模块下面对datasource模块进行改造即可,具体改造如下:

注意:以下代码改造都是在plugin模块-datasource模块下进行的改造,因此代码都是在datasource下进行的

2.2.1 DataSourceConstant.java

在该常量类中增加需要支持的数据库类型,后续有其他要支持数据库类型都统一定义在该类中即可,类:com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant

  1. /*
  2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.alibaba.nacos.plugin.datasource.constants;
  17. /**
  18. * The data source name.
  19. *
  20. * @author hyx
  21. **/
  22. public class DataSourceConstant {
  23. public static final String MYSQL = "mysql";
  24. public static final String DM = "dm";
  25. public static final String DERBY = "derby";
  26. public static final String POSTGRESQL = "postgresql";
  27. public static final String KINGBASE8 = "kingbase8";
  28. }
2.2.2 增加PrimaryKeyConstant.java类

这个常量类主要是为了适配数据库的大小写问题,放在constants包下

package:com.alibaba.nacos.plugin.datasource.constants

  1. package com.alibaba.nacos.plugin.datasource.constants;
  2. /**
  3. * @Description TODO
  4. * @Author wx
  5. * @Date 2023/11/23
  6. */
  7. public class PrimaryKeyConstant {
  8. /**
  9. * replace lower Statement.RETURN_GENERATED_KEYS into id key.
  10. */
  11. public static final String[] LOWER_RETURN_PRIMARY_KEYS = new String[]{"id"};
  12. /**
  13. * upper replace Statement.RETURN_GENERATED_KEYS into id key.
  14. *
  15. */
  16. public static final String[] UPPER_RETURN_PRIMARY_KEYS = new String[]{"ID"};
  17. }
2.2.3 新增对dialect的管理

每种数据库都有不同的方言,因此为了统一对dialect管理,好后续做通配,因此需要设计一下dialect,主要改造步骤有以下几步:

2.2.3.1 新增DatabaseDialectManager类

这个manager主要是适配多数据源多方言的情况,不局限于一个进程就只能配置一种数据源和方言,可同时配置多数据源;

新增package: com.alibaba.nacos.plugin.datasource.manager

在该package下新增类: DatabaseDialectManager

  1. package com.alibaba.nacos.plugin.datasource.manager;
  2. import com.alibaba.nacos.common.spi.NacosServiceLoader;
  3. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  4. import com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import java.util.Collection;
  8. import java.util.Map;
  9. import java.util.concurrent.ConcurrentHashMap;
  10. /**
  11. * @Description TODO
  12. * @Author wx (mailto:wang-xin@primeton.com)
  13. * @Date 2023/11/23
  14. */
  15. public class DatabaseDialectManager {
  16. private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseDialectManager.class);
  17. private static final DatabaseDialectManager INSTANCE = new DatabaseDialectManager();
  18. private static final Map<String, DatabaseDialect> SUPPORT_DIALECT_MAP = new ConcurrentHashMap<String, DatabaseDialect>();
  19. private DatabaseDialectManager() {
  20. }
  21. static {
  22. //加载多种数据库方言为映射信息
  23. Collection<DatabaseDialect> dialectList = NacosServiceLoader.load(DatabaseDialect.class);
  24. for (DatabaseDialect dialect : dialectList) {
  25. SUPPORT_DIALECT_MAP.put(dialect.getType(), dialect);
  26. }
  27. if (SUPPORT_DIALECT_MAP.isEmpty()) {
  28. LOGGER.warn("[DatasourceDialectManager] Load DatabaseDialect fail, No DatabaseDialect implements");
  29. }
  30. }
  31. public DatabaseDialect getDialect(String databaseType) {
  32. DatabaseDialect databaseDialect = SUPPORT_DIALECT_MAP.get(databaseType);
  33. if (databaseDialect == null) {
  34. return new DefaultDatabaseDialect();
  35. }
  36. return databaseDialect;
  37. }
  38. /**
  39. * Get DatasourceDialectManager instance.
  40. *
  41. * @return DataSourceDialectProvider
  42. */
  43. public static DatabaseDialectManager getInstance() {
  44. return INSTANCE;
  45. }
  46. }
2.2.3.2 新增package:com.alibaba.nacos.plugin.datasource.dialect

以下代码都是在该package下面进行新增

1. 新增接口 DatabaseDialect

这个接口主要是定义了一些每个数据库不同的实现的一些接口,比如:分页、字段大小写等

  1. package com.alibaba.nacos.plugin.datasource.dialect;
  2. /**
  3. * @Description TODO
  4. * @Author wx520
  5. * @Date 2023/11/23
  6. */
  7. public interface DatabaseDialect {
  8. /**
  9. * get database type.
  10. * @return return database type name
  11. */
  12. public String getType();
  13. /**
  14. * get frist index page param.
  15. * @param page current pageNo
  16. * @param pageSize current pageSize
  17. * @return offset val or maxRange
  18. */
  19. public int getPagePrevNum(int page, int pageSize);
  20. /**
  21. * get second index page param.
  22. * @param page current pageNo
  23. * @param pageSize current pageSize
  24. * @return limit val or minRange
  25. */
  26. public int getPageLastNum(int page, int pageSize);
  27. /**
  28. * get page limit top data sql,contain placeholder.
  29. * @param sql orign sql
  30. * @return append limit sql
  31. */
  32. public String getLimitTopSqlWithMark(String sql);
  33. /**
  34. * get page limit page data sql,contain placeholder.
  35. * @param sql orign sql
  36. * @return append limit sql
  37. */
  38. public String getLimitPageSqlWithMark(String sql);
  39. /**
  40. * get page limit page data sql,using number.
  41. * @param sql orign sql
  42. * @param pageNo current pageNo
  43. * @param pageSize current pageSize
  44. * @return contain page number param sql
  45. */
  46. public String getLimitPageSql(String sql, int pageNo, int pageSize);
  47. /**
  48. * get page limit page data sql,using offset.
  49. * @param sql orign sql
  50. * @param startOffset current offset row
  51. * @param pageSize current pageSize
  52. * @return contain page number param sql
  53. */
  54. public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize);
  55. /**
  56. * get database return primary keys.
  57. * @return
  58. */
  59. public String[] getReturnPrimaryKeys();
  60. }
2. 新增抽象类 AbstractDatabaseDialect

该抽象类主要是新增一些方言的默认实现,比如limit的默认实现,大部分数据库对于limit的支持都是limit a ; limit a,b 这种,也有不分数据库是不支持limit a,b的,支持limt b offset a这种等等,所以提供一个大部分都支持的默认实现,少部分差异的再具体重写实现。

  1. package com.alibaba.nacos.plugin.datasource.dialect;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. /**
  4. * @Description TODO
  5. * @Author wx
  6. * @Date 2023/11/23
  7. */
  8. public abstract class AbstractDatabaseDialect implements DatabaseDialect {
  9. @Override
  10. public int getPagePrevNum(int page, int pageSize) {
  11. return (page - 1) * pageSize;
  12. }
  13. @Override
  14. public int getPageLastNum(int page, int pageSize) {
  15. return pageSize;
  16. }
  17. @Override
  18. public String getLimitTopSqlWithMark(String sql) {
  19. return sql + " LIMIT ? ";
  20. }
  21. @Override
  22. public String getLimitPageSqlWithMark(String sql) {
  23. return sql + " LIMIT ?,? ";
  24. }
  25. @Override
  26. public String getLimitPageSql(String sql, int pageNo, int pageSize) {
  27. return sql + " LIMIT " + getPagePrevNum(pageNo, pageSize) + " , " + pageSize;
  28. }
  29. @Override
  30. public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize){
  31. return sql + " LIMIT " + startOffset + " , " + pageSize;
  32. }
  33. @Override
  34. public String[] getReturnPrimaryKeys() {
  35. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  36. }
  37. }
3. 新增默认实现类 DefaultDatabaseDialect

默认实现类默认为mysql,因此无需做什么特殊改动

  1. package com.alibaba.nacos.plugin.datasource.dialect;
  2. import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
  3. /**
  4. * @Description TODO
  5. * @Author wx
  6. * @Date 2023/11/23
  7. */
  8. public class DefaultDatabaseDialect extends AbstractDatabaseDialect {
  9. @Override
  10. public String getType() {
  11. //默认mysql实现
  12. return DataSourceConstant.MYSQL;
  13. }
  14. }
2.2.4 抽象BaseMapper

首先新增package: com.alibaba.nacos.plugin.datasource.impl.base

然后在该package下面新增一些BaseMapper,具体如下:

新增BaseConfigInfoAggrMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  4. import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql;
  5. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  6. /**
  7. * @Description TODO
  8. * @Author wx
  9. * @Date 2023/11/23
  10. */
  11. public class BaseConfigInfoAggrMapper extends ConfigInfoAggrMapperByMySql {
  12. private DatabaseDialect databaseDialect;
  13. public BaseConfigInfoAggrMapper() {
  14. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  15. }
  16. @Override
  17. public String getTableName() {
  18. return TableConstant.CONFIG_INFO_AGGR;
  19. }
  20. @Override
  21. public String findConfigInfoAggrByPageFetchRows(int startRow, int pageSize) {
  22. return databaseDialect.getLimitPageSqlWithOffset(
  23. "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
  24. + "group_id= ? AND tenant_id= ? ORDER BY datum_id ", startRow, pageSize);
  25. }
  26. }
新增BaseConfigInfoBetaMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  4. import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql;
  5. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  6. /**
  7. * @Description TODO
  8. * @Author wx
  9. * @Date 2023/11/23
  10. */
  11. public class BaseConfigInfoBetaMapper extends ConfigInfoBetaMapperByMySql {
  12. private DatabaseDialect databaseDialect;
  13. public BaseConfigInfoBetaMapper() {
  14. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  15. }
  16. @Override
  17. public String getTableName() {
  18. return TableConstant.CONFIG_INFO_BETA;
  19. }
  20. public String getLimitPageSqlWithOffset(String sql, int startRow, int pageSize) {
  21. return databaseDialect.getLimitPageSqlWithOffset(sql, startRow, pageSize);
  22. }
  23. @Override
  24. public String findAllConfigInfoBetaForDumpAllFetchRows(int startRow, int pageSize) {
  25. String sqlInner = getLimitPageSqlWithOffset("SELECT id FROM config_info_beta ORDER BY id ", startRow,
  26. pageSize);
  27. String sql =
  28. " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
  29. + " FROM ( " + sqlInner + " )" + " g, config_info_beta t WHERE g.id = t.id ";
  30. return sql;
  31. }
  32. }
新增BaseConfigInfoMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.common.utils.StringUtils;
  3. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  4. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  5. import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql;
  6. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  7. import java.sql.Timestamp;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Map;
  11. /**
  12. * @Description TODO
  13. * @Author wx
  14. * @Date 2023/11/23
  15. */
  16. public class BaseConfigInfoMapper extends ConfigInfoMapperByMySql {
  17. private DatabaseDialect databaseDialect;
  18. public BaseConfigInfoMapper() {
  19. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  20. }
  21. public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) {
  22. return databaseDialect.getLimitPageSqlWithOffset(sql, startOffset, pageSize);
  23. }
  24. public String getLimitPageSqlWithMark(String sql) {
  25. return databaseDialect.getLimitPageSqlWithMark(sql);
  26. }
  27. @Override
  28. public String findConfigInfoByAppFetchRows(int startRow, int pageSize) {
  29. return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"
  30. + " WHERE tenant_id LIKE ? AND app_name= ?", startRow, pageSize);
  31. }
  32. @Override
  33. public String getTenantIdList(int startRow, int pageSize) {
  34. return getLimitPageSqlWithOffset(
  35. "SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY tenant_id ", startRow, pageSize);
  36. }
  37. @Override
  38. public String getGroupIdList(int startRow, int pageSize) {
  39. return getLimitPageSqlWithOffset(
  40. "SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id ", +startRow, pageSize);
  41. }
  42. @Override
  43. public String findAllConfigKey(int startRow, int pageSize) {
  44. String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id ",
  45. startRow, pageSize);
  46. return " SELECT data_id,group_id,app_name FROM ( " + innerSql + " g, config_info t WHERE g.id = t.id ";
  47. }
  48. @Override
  49. public String findAllConfigInfoBaseFetchRows(int startRow, int pageSize) {
  50. String innerSql = getLimitPageSqlWithMark(" SELECT id FROM config_info ORDER BY id ");
  51. return " SELECT t.id,data_id,group_id,content,md5" + " FROM ( " + innerSql + " ) "
  52. + " g, config_info t WHERE g.id = t.id ";
  53. }
  54. @Override
  55. public String findAllConfigInfoFragment(int startRow, int pageSize) {
  56. return getLimitPageSqlWithOffset(
  57. "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "
  58. + "FROM config_info WHERE id > ? ORDER BY id ASC ", startRow, pageSize);
  59. }
  60. @Override
  61. public String findChangeConfigFetchRows(Map<String, String> params, final Timestamp startTime,
  62. final Timestamp endTime, int startRow, int pageSize, long lastMaxId) {
  63. final String tenant = params.get(TENANT);
  64. final String dataId = params.get(DATA_ID);
  65. final String group = params.get(GROUP);
  66. final String appName = params.get(APP_NAME);
  67. final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
  68. List<Object> paramList = new ArrayList<>();
  69. final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM config_info WHERE ";
  70. String where = " 1=1 ";
  71. if (!StringUtils.isBlank(dataId)) {
  72. where += " AND data_id LIKE ? ";
  73. paramList.add(dataId);
  74. }
  75. if (!StringUtils.isBlank(group)) {
  76. where += " AND group_id LIKE ? ";
  77. paramList.add(group);
  78. }
  79. if (!StringUtils.isBlank(tenantTmp)) {
  80. where += " AND tenant_id = ? ";
  81. paramList.add(tenantTmp);
  82. }
  83. if (!StringUtils.isBlank(appName)) {
  84. where += " AND app_name = ? ";
  85. paramList.add(appName);
  86. }
  87. if (startTime != null) {
  88. where += " AND gmt_modified >=? ";
  89. paramList.add(startTime);
  90. }
  91. if (endTime != null) {
  92. where += " AND gmt_modified <=? ";
  93. paramList.add(endTime);
  94. }
  95. String originSql = sqlFetchRows + where + " AND id > " + lastMaxId + " ORDER BY id ASC";
  96. return getLimitPageSqlWithOffset(originSql, 0, pageSize);
  97. }
  98. @Override
  99. public String listGroupKeyMd5ByPageFetchRows(int startRow, int pageSize) {
  100. String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info ORDER BY id ", startRow, pageSize);
  101. String sql =
  102. " SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM " + "( "
  103. + innerSql + " ) g, config_info t WHERE g.id = t.id";
  104. return sql;
  105. }
  106. @Override
  107. public String findConfigInfoBaseLikeFetchRows(Map<String, String> params, int startRow, int pageSize) {
  108. final String dataId = params.get(DATA_ID);
  109. final String group = params.get(GROUP);
  110. final String content = params.get(CONTENT);
  111. final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
  112. String where = " 1=1 AND tenant_id='' ";
  113. if (!StringUtils.isBlank(dataId)) {
  114. where += " AND data_id LIKE ? ";
  115. }
  116. if (!StringUtils.isBlank(group)) {
  117. where += " AND group_id LIKE ";
  118. }
  119. if (!StringUtils.isBlank(content)) {
  120. where += " AND content LIKE ? ";
  121. }
  122. return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
  123. }
  124. @Override
  125. public String findConfigInfo4PageFetchRows(Map<String, String> params, int startRow, int pageSize) {
  126. final String appName = params.get(APP_NAME);
  127. final String dataId = params.get(DATA_ID);
  128. final String group = params.get(GROUP);
  129. final String content = params.get(CONTENT);
  130. List<Object> paramList = new ArrayList<>();
  131. final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info";
  132. StringBuilder where = new StringBuilder(" WHERE ");
  133. where.append(" tenant_id=? ");
  134. if (StringUtils.isNotBlank(dataId)) {
  135. where.append(" AND data_id=? ");
  136. paramList.add(dataId);
  137. }
  138. if (StringUtils.isNotBlank(group)) {
  139. where.append(" AND group_id=? ");
  140. paramList.add(group);
  141. }
  142. if (StringUtils.isNotBlank(appName)) {
  143. where.append(" AND app_name=? ");
  144. paramList.add(appName);
  145. }
  146. if (!StringUtils.isBlank(content)) {
  147. where.append(" AND content LIKE ? ");
  148. paramList.add(content);
  149. }
  150. return getLimitPageSqlWithOffset(sql + where, startRow, pageSize);
  151. }
  152. @Override
  153. public String findConfigInfoBaseByGroupFetchRows(int startRow, int pageSize) {
  154. String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? ";
  155. return getLimitPageSqlWithOffset(sql, startRow, pageSize);
  156. }
  157. @Override
  158. public String findConfigInfoLike4PageFetchRows(Map<String, String> params, int startRow, int pageSize) {
  159. String dataId = params.get(DATA_ID);
  160. String group = params.get(GROUP);
  161. final String appName = params.get(APP_NAME);
  162. final String content = params.get(CONTENT);
  163. final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";
  164. StringBuilder where = new StringBuilder(" WHERE ");
  165. where.append(" tenant_id LIKE ? ");
  166. List<Object> paramList = new ArrayList<>();
  167. if (!StringUtils.isBlank(dataId)) {
  168. where.append(" AND data_id LIKE ? ");
  169. paramList.add(dataId);
  170. }
  171. if (!StringUtils.isBlank(group)) {
  172. where.append(" AND group_id LIKE ? ");
  173. paramList.add(group);
  174. }
  175. if (!StringUtils.isBlank(appName)) {
  176. where.append(" AND app_name = ? ");
  177. paramList.add(appName);
  178. }
  179. if (!StringUtils.isBlank(content)) {
  180. where.append(" AND content LIKE ? ");
  181. paramList.add(content);
  182. }
  183. return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
  184. }
  185. @Override
  186. public String findAllConfigInfoFetchRows(int startRow, int pageSize) {
  187. String innerSql = getLimitPageSqlWithMark("SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id ");
  188. return " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 " + " FROM ( " + innerSql + " )"
  189. + " g, config_info t WHERE g.id = t.id ";
  190. }
  191. @Override
  192. public String getTableName() {
  193. return TableConstant.CONFIG_INFO;
  194. }
  195. }
新增BaseConfigInfoTagMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  4. import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql;
  5. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  6. /**
  7. * @Description TODO
  8. * @Author wx
  9. * @Date 2023/11/23
  10. */
  11. public class BaseConfigInfoTagMapper extends ConfigInfoTagMapperByMySql {
  12. private DatabaseDialect databaseDialect;
  13. public BaseConfigInfoTagMapper() {
  14. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  15. }
  16. @Override
  17. public String getTableName() {
  18. return TableConstant.CONFIG_INFO_TAG;
  19. }
  20. @Override
  21. public String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize) {
  22. String innerSql = databaseDialect
  23. .getLimitPageSqlWithOffset("SELECT id FROM config_info_tag ORDER BY id ", startRow, pageSize);
  24. return " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified " + " FROM ( "
  25. + innerSql + " ) " + "g, config_info_tag t WHERE g.id = t.id ";
  26. }
  27. }
新增BaseConfigTagsRelationMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.common.utils.StringUtils;
  3. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  4. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  5. import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql;
  6. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import java.util.Map;
  10. /**
  11. * @Description TODO
  12. * @Author wx
  13. * @Date 2023/11/23
  14. */
  15. public class BaseConfigTagsRelationMapper extends ConfigTagsRelationMapperByMySql {
  16. private DatabaseDialect databaseDialect;
  17. public BaseConfigTagsRelationMapper() {
  18. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  19. }
  20. public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) {
  21. return databaseDialect.getLimitPageSqlWithOffset(sql, startOffset, pageSize);
  22. }
  23. @Override
  24. public String getTableName() {
  25. return TableConstant.CONFIG_TAGS_RELATION;
  26. }
  27. @Override
  28. public String findConfigInfo4PageFetchRows(Map<String, String> params, int tagSize, int startRow, int pageSize) {
  29. final String appName = params.get("appName");
  30. final String dataId = params.get("dataId");
  31. final String group = params.get("group");
  32. final String content = params.get("content");
  33. List<Object> paramList = new ArrayList<>();
  34. StringBuilder where = new StringBuilder(" WHERE ");
  35. final String sql =
  36. "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
  37. + "config_tags_relation b ON a.id=b.id";
  38. where.append(" a.tenant_id=? ");
  39. if (StringUtils.isNotBlank(dataId)) {
  40. where.append(" AND a.data_id=? ");
  41. paramList.add(dataId);
  42. }
  43. if (StringUtils.isNotBlank(group)) {
  44. where.append(" AND a.group_id=? ");
  45. paramList.add(group);
  46. }
  47. if (StringUtils.isNotBlank(appName)) {
  48. where.append(" AND a.app_name=? ");
  49. paramList.add(appName);
  50. }
  51. if (!StringUtils.isBlank(content)) {
  52. where.append(" AND a.content LIKE ? ");
  53. paramList.add(content);
  54. }
  55. where.append(" AND b.tag_name IN (");
  56. for (int i = 0; i < tagSize; i++) {
  57. if (i != 0) {
  58. where.append(", ");
  59. }
  60. where.append('?');
  61. }
  62. where.append(") ");
  63. return getLimitPageSqlWithOffset(sql + where, startRow, pageSize);
  64. }
  65. @Override
  66. public String findConfigInfoLike4PageFetchRows(final Map<String, String> params,
  67. int tagSize,
  68. int startRow,
  69. int pageSize) {
  70. final String appName = params.get("appName");
  71. final String content = params.get("content");
  72. final String dataId = params.get("dataId");
  73. final String group = params.get("group");
  74. List<Object> paramList = new ArrayList<>();
  75. StringBuilder where = new StringBuilder(" WHERE ");
  76. final String sqlFetchRows = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content "
  77. + "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";
  78. where.append(" a.tenant_id LIKE ? ");
  79. if (!StringUtils.isBlank(dataId)) {
  80. where.append(" AND a.data_id LIKE ? ");
  81. paramList.add(dataId);
  82. }
  83. if (!StringUtils.isBlank(group)) {
  84. where.append(" AND a.group_id LIKE ? ");
  85. paramList.add(group);
  86. }
  87. if (!StringUtils.isBlank(appName)) {
  88. where.append(" AND a.app_name = ? ");
  89. paramList.add(appName);
  90. }
  91. if (!StringUtils.isBlank(content)) {
  92. where.append(" AND a.content LIKE ? ");
  93. paramList.add(content);
  94. }
  95. where.append(" AND b.tag_name IN (");
  96. for (int i = 0; i < tagSize; i++) {
  97. if (i != 0) {
  98. where.append(", ");
  99. }
  100. where.append('?');
  101. }
  102. where.append(") ");
  103. return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
  104. }
  105. }
新增BaseGroupCapacityMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  4. import com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql;
  5. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  6. /**
  7. * @Description TODO
  8. * @Author wx
  9. * @Date 2023/11/23
  10. */
  11. public class BaseGroupCapacityMapper extends GroupCapacityMapperByMysql {
  12. private DatabaseDialect databaseDialect;
  13. public BaseGroupCapacityMapper() {
  14. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  15. }
  16. @Override
  17. public String getTableName() {
  18. return TableConstant.GROUP_CAPACITY;
  19. }
  20. @Override
  21. public String selectGroupInfoBySize() {
  22. return databaseDialect.getLimitTopSqlWithMark("SELECT id, group_id FROM group_capacity WHERE id > ?");
  23. }
  24. }
新增BaseTenantCapacityMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  4. import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql;
  5. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  6. /**
  7. * @Description TODO
  8. * @Author wx
  9. * @Date 2023/11/23
  10. */
  11. public class BaseTenantCapacityMapper extends TenantCapacityMapperByMySql {
  12. private DatabaseDialect databaseDialect;
  13. public BaseTenantCapacityMapper() {
  14. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  15. }
  16. @Override
  17. public String getTableName() {
  18. return TableConstant.TENANT_CAPACITY;
  19. }
  20. @Override
  21. public String getCapacityList4CorrectUsage() {
  22. return databaseDialect.getLimitTopSqlWithMark("SELECT id, tenant_id FROM tenant_capacity WHERE id>?");
  23. }
  24. }
新增BaseTenantInfoMapper
  1. package com.alibaba.nacos.plugin.datasource.impl.base;
  2. import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
  4. import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql;
  5. import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
  6. /**
  7. * @Description TODO
  8. * @Author wx
  9. * @Date 2023/11/23
  10. */
  11. public class BaseTenantInfoMapper extends TenantInfoMapperByMySql {
  12. private DatabaseDialect databaseDialect;
  13. public BaseTenantInfoMapper() {
  14. databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
  15. }
  16. @Override
  17. public String getTableName() {
  18. return TableConstant.TENANT_INFO;
  19. }
  20. }
2.2.5 达梦dm适配
1. 新增达梦的dialect实现以及Mapper

新增package: com.alibaba.nacos.plugin.datasource.impl.dm.dialect

在该package下面新增类:DaMengDatabaseDialect

  1. package com.alibaba.nacos.plugin.datasource.impl.dm.dialect;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.AbstractDatabaseDialect;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class DaMengDatabaseDialect extends AbstractDatabaseDialect {
  11. @Override
  12. public String[] getReturnPrimaryKeys() {
  13. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  14. }
  15. @Override
  16. public String getType() {
  17. return DM;
  18. }
  19. }

然后就是各个Mapper的覆写,因为dm基本都支持mysql的语法,所以这一块改动不大,具体代码如下:在package:com.alibaba.nacos.plugin.datasource.impl.dm下面新增以下类

ConfigInfoAggrMapperByDM

  1. /*
  2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.alibaba.nacos.plugin.datasource.impl.dm;
  17. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  18. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoAggrMapper;
  19. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  20. /**
  21. * @Description TODO
  22. * @Author wx
  23. * @Date 2023/11/23
  24. */
  25. public class ConfigInfoAggrMapperByDM extends BaseConfigInfoAggrMapper {
  26. @Override
  27. public String getDataSource() {
  28. return DM;
  29. }
  30. @Override
  31. public String[] getPrimaryKeyGeneratedKeys() {
  32. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  33. }
  34. }
ConfigInfoBetaMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoBetaMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigInfoBetaMapperByDM extends BaseConfigInfoBetaMapper {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
ConfigInfoMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigInfoMapperByDM extends BaseConfigInfoMapper {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
ConfigInfoTagMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoTagMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigInfoTagMapperByDM extends BaseConfigInfoTagMapper {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
ConfigTagsRelationMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigTagsRelationMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigTagsRelationMapperByDM extends BaseConfigTagsRelationMapper {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
GroupCapacityMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseGroupCapacityMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class GroupCapacityMapperByDM extends BaseGroupCapacityMapper {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
HistoryConfigInfoMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class HistoryConfigInfoMapperByDM extends HistoryConfigInfoMapperByMySql {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
TenantCapacityMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantCapacityMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class TenantCapacityMapperByDM extends BaseTenantCapacityMapper {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
TenantInfoMapperByDM
  1. package com.alibaba.nacos.plugin.datasource.impl.dm;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantInfoMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class TenantInfoMapperByDM extends BaseTenantInfoMapper {
  11. @Override
  12. public String getDataSource() {
  13. return DM;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
2. 支持达梦数据库错误码

在resource目录下新增sql-error-codes.xml

这个配置文件主要是映射达梦数据库错误码

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd">
  3. <!--
  4. - Default SQL error codes for well-known databases.
  5. - Can be overridden by definitions in a "sql-error-codes.xml" file
  6. - in the root of the class path.
  7. -
  8. - If the Database Product Name contains characters that are invalid
  9. - to use in the id attribute (like a space) then we need to add a property
  10. - named "databaseProductName"/"databaseProductNames" that holds this value.
  11. - If this property is present, then it will be used instead of the id for
  12. - looking up the error codes based on the current database.
  13. -->
  14. <!--
  15. 此文件主要做dameng数据库错误码与spring异常类的映射关系
  16. 如果没有此文件 修改配置时唯一索冲突并不会抛出 DuplicateKeyException 的异常
  17. -->
  18. <beans>
  19. <!-- 支持达梦数据库错误码-->
  20. <bean id="DM" class="org.springframework.jdbc.support.SQLErrorCodes">
  21. <property name="databaseProductNames">
  22. <list>
  23. <!-- 数据源名称存在空格不能像Oracle一样直接作为beanId -->
  24. <value>DM DBMS</value>
  25. </list>
  26. </property>
  27. <property name="duplicateKeyCodes">
  28. <list>
  29. <value>-6602</value>
  30. <value>-6625</value>
  31. </list>
  32. </property>
  33. </bean>
  34. </beans>
3. 增加SPI加载

为了能够让spring加载到我们的配置,需要进行对应services的修改

修改文件:resources/META-INF.services下的

com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect

增加自定义达梦的dialect配置

  1. #
  2. # Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. #
  17. com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect
  18. com.alibaba.nacos.plugin.datasource.impl.dm.dialect.DaMengDatabaseDialect

修改resources/META-INF.services下的com.alibaba.nacos.plugin.datasource.mapper.Mapper文件

将上面自定义达梦相关的Mapper配置进去

  1. #
  2. # Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql
  17. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql
  18. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql
  19. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql
  20. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql
  21. com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql
  22. com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql
  23. com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql
  24. com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql
  25. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby
  26. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby
  27. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby
  28. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby
  29. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby
  30. com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby
  31. com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby
  32. com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby
  33. com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerby
  34. com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoAggrMapperByDM
  35. com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoBetaMapperByDM
  36. com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoMapperByDM
  37. com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoTagMapperByDM
  38. com.alibaba.nacos.plugin.datasource.impl.dm.ConfigTagsRelationMapperByDM
  39. com.alibaba.nacos.plugin.datasource.impl.dm.HistoryConfigInfoMapperByDM
  40. com.alibaba.nacos.plugin.datasource.impl.dm.GroupCapacityMapperByDM
  41. com.alibaba.nacos.plugin.datasource.impl.dm.TenantCapacityMapperByDM
  42. com.alibaba.nacos.plugin.datasource.impl.dm.TenantInfoMapperByDM
4. 达梦jdbc配置

修改datasource配置,配置如下:

  1. spring.sql.init.platform=dm
  2. ### Count of DB:
  3. db.num=1
  4. ### Connect URL of DB:
  5. db.url.0=jdbc:dm://localhost:5236
  6. db.user.0=SYSDBA
  7. db.password.0=123456
  8. db.driver-class-name.0=dm.jdbc.driver.DmDriver
5. dm脚本
  1. CREATE TABLE "NOCOS"."USERS"
  2. (
  3. "USERNAME" VARCHAR(50) NOT NULL,
  4. "PASSWORD" VARCHAR(500) NOT NULL,
  5. "ENABLED" TINYINT NOT NULL
  6. );
  7. CREATE TABLE "NOCOS"."TENANT_INFO"
  8. (
  9. "ID" BIGINT IDENTITY(1,1) NOT NULL,
  10. "KP" VARCHAR(128) NOT NULL,
  11. "TENANT_ID" VARCHAR(128) DEFAULT ''
  12. NULL,
  13. "TENANT_NAME" VARCHAR(128) DEFAULT ''
  14. NULL,
  15. "TENANT_DESC" VARCHAR(256) NULL,
  16. "CREATE_SOURCE" VARCHAR(32) NULL,
  17. "GMT_CREATE" BIGINT NOT NULL,
  18. "GMT_MODIFIED" BIGINT NOT NULL
  19. );
  20. CREATE TABLE "NOCOS"."TENANT_CAPACITY"
  21. (
  22. "ID" BIGINT IDENTITY(1,1) NOT NULL,
  23. "TENANT_ID" VARCHAR(128) DEFAULT ''
  24. NOT NULL,
  25. "QUOTA" BIGINT DEFAULT 0
  26. NOT NULL,
  27. "USAGE" BIGINT DEFAULT 0
  28. NOT NULL,
  29. "MAX_SIZE" BIGINT DEFAULT 0
  30. NOT NULL,
  31. "MAX_AGGR_COUNT" BIGINT DEFAULT 0
  32. NOT NULL,
  33. "MAX_AGGR_SIZE" BIGINT DEFAULT 0
  34. NOT NULL,
  35. "MAX_HISTORY_COUNT" BIGINT DEFAULT 0
  36. NOT NULL,
  37. "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  38. NOT NULL,
  39. "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  40. NOT NULL
  41. );
  42. CREATE TABLE "NOCOS"."ROLES"
  43. (
  44. "USERNAME" VARCHAR(50) NOT NULL,
  45. "ROLE" VARCHAR(50) NOT NULL
  46. );
  47. CREATE TABLE "NOCOS"."PERMISSIONS"
  48. (
  49. "ROLE" VARCHAR(50) NOT NULL,
  50. "RESOURCE" VARCHAR(255) NOT NULL,
  51. "ACTION" VARCHAR(8) NOT NULL
  52. );
  53. CREATE TABLE "NOCOS"."HIS_CONFIG_INFO"
  54. (
  55. "ID" DECIMAL(20, 0) NOT NULL,
  56. "NID" BIGINT IDENTITY(1,1) NOT NULL,
  57. "DATA_ID" VARCHAR(255) NOT NULL,
  58. "GROUP_ID" VARCHAR(128) NOT NULL,
  59. "APP_NAME" VARCHAR(128) NULL,
  60. "CONTENT" CLOB NOT NULL,
  61. "MD5" VARCHAR(32) NULL,
  62. "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  63. NOT NULL,
  64. "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  65. NOT NULL,
  66. "SRC_USER" TEXT NULL,
  67. "SRC_IP" VARCHAR(50) NULL,
  68. "OP_TYPE" CHAR(10) NULL,
  69. "TENANT_ID" VARCHAR(128) DEFAULT ''
  70. NULL,
  71. "ENCRYPTED_DATA_KEY" TEXT NOT NULL
  72. );
  73. CREATE TABLE "NOCOS"."GROUP_CAPACITY"
  74. (
  75. "ID" BIGINT IDENTITY(1,1) NOT NULL,
  76. "GROUP_ID" VARCHAR(128) DEFAULT ''
  77. NOT NULL,
  78. "QUOTA" BIGINT DEFAULT 0
  79. NOT NULL,
  80. "USAGE" BIGINT DEFAULT 0
  81. NOT NULL,
  82. "MAX_SIZE" BIGINT DEFAULT 0
  83. NOT NULL,
  84. "MAX_AGGR_COUNT" BIGINT DEFAULT 0
  85. NOT NULL,
  86. "MAX_AGGR_SIZE" BIGINT DEFAULT 0
  87. NOT NULL,
  88. "MAX_HISTORY_COUNT" BIGINT DEFAULT 0
  89. NOT NULL,
  90. "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  91. NOT NULL,
  92. "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  93. NOT NULL
  94. );
  95. CREATE TABLE "NOCOS"."CONFIG_TAGS_RELATION"
  96. (
  97. "ID" BIGINT NOT NULL,
  98. "TAG_NAME" VARCHAR(128) NOT NULL,
  99. "TAG_TYPE" VARCHAR(64) NULL,
  100. "DATA_ID" VARCHAR(255) NOT NULL,
  101. "GROUP_ID" VARCHAR(128) NOT NULL,
  102. "TENANT_ID" VARCHAR(128) DEFAULT ''
  103. NULL,
  104. "NID" BIGINT IDENTITY(1,1) NOT NULL
  105. );
  106. CREATE TABLE "NOCOS"."CONFIG_INFO_TAG"
  107. (
  108. "ID" BIGINT IDENTITY(1,1) NOT NULL,
  109. "DATA_ID" VARCHAR(255) NOT NULL,
  110. "GROUP_ID" VARCHAR(128) NOT NULL,
  111. "TENANT_ID" VARCHAR(128) DEFAULT ''
  112. NULL,
  113. "TAG_ID" VARCHAR(128) NOT NULL,
  114. "APP_NAME" VARCHAR(128) NULL,
  115. "CONTENT" CLOB NOT NULL,
  116. "MD5" VARCHAR(32) NULL,
  117. "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  118. NOT NULL,
  119. "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  120. NOT NULL,
  121. "SRC_USER" TEXT NULL,
  122. "SRC_IP" VARCHAR(50) NULL
  123. );
  124. CREATE TABLE "NOCOS"."CONFIG_INFO_BETA"
  125. (
  126. "ID" BIGINT IDENTITY(1,1) NOT NULL,
  127. "DATA_ID" VARCHAR(255) NOT NULL,
  128. "GROUP_ID" VARCHAR(128) NOT NULL,
  129. "APP_NAME" VARCHAR(128) NULL,
  130. "CONTENT" CLOB NOT NULL,
  131. "BETA_IPS" VARCHAR(1024) NULL,
  132. "MD5" VARCHAR(32) NULL,
  133. "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  134. NOT NULL,
  135. "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  136. NOT NULL,
  137. "SRC_USER" TEXT NULL,
  138. "SRC_IP" VARCHAR(50) NULL,
  139. "TENANT_ID" VARCHAR(128) DEFAULT ''
  140. NULL,
  141. "ENCRYPTED_DATA_KEY" TEXT NOT NULL
  142. );
  143. CREATE TABLE "NOCOS"."CONFIG_INFO_AGGR"
  144. (
  145. "ID" BIGINT IDENTITY(1,1) NOT NULL,
  146. "DATA_ID" VARCHAR(255) NOT NULL,
  147. "GROUP_ID" VARCHAR(128) NOT NULL,
  148. "DATUM_ID" VARCHAR(255) NOT NULL,
  149. "CONTENT" CLOB NOT NULL,
  150. "GMT_MODIFIED" TIMESTAMP(0) NOT NULL,
  151. "APP_NAME" VARCHAR(128) NULL,
  152. "TENANT_ID" VARCHAR(128) DEFAULT ''
  153. NULL
  154. );
  155. CREATE TABLE "NOCOS"."CONFIG_INFO"
  156. (
  157. "ID" BIGINT IDENTITY(1,1) NOT NULL,
  158. "DATA_ID" VARCHAR(255) NOT NULL,
  159. "GROUP_ID" VARCHAR(128) NULL,
  160. "CONTENT" CLOB NOT NULL,
  161. "MD5" VARCHAR(32) NULL,
  162. "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  163. NOT NULL,
  164. "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
  165. NOT NULL,
  166. "SRC_USER" TEXT NULL,
  167. "SRC_IP" VARCHAR(50) NULL,
  168. "APP_NAME" VARCHAR(128) NULL,
  169. "TENANT_ID" VARCHAR(128) DEFAULT ''
  170. NULL,
  171. "C_DESC" VARCHAR(256) NULL,
  172. "C_USE" VARCHAR(64) NULL,
  173. "EFFECT" VARCHAR(64) NULL,
  174. "TYPE" VARCHAR(64) NULL,
  175. "C_SCHEMA" TEXT NULL,
  176. "ENCRYPTED_DATA_KEY" TEXT NOT NULL
  177. );
  178. ALTER TABLE "NOCOS"."USERS"
  179. ADD CONSTRAINT PRIMARY KEY ("USERNAME");
  180. ALTER TABLE "NOCOS"."TENANT_INFO"
  181. ADD CONSTRAINT PRIMARY KEY ("ID");
  182. ALTER TABLE "NOCOS"."TENANT_INFO"
  183. ADD CONSTRAINT "UK_TENANT_INFO_KPTENANTID" UNIQUE ("KP", "TENANT_ID");
  184. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  185. ADD CONSTRAINT PRIMARY KEY ("ID");
  186. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  187. ADD CONSTRAINT "UK_TENANT_ID" UNIQUE ("TENANT_ID");
  188. ALTER TABLE "NOCOS"."ROLES"
  189. ADD CONSTRAINT "IDX_USER_ROLE" UNIQUE ("USERNAME", "ROLE");
  190. ALTER TABLE "NOCOS"."PERMISSIONS"
  191. ADD CONSTRAINT "UK_ROLE_PERMISSION" UNIQUE ("ROLE", "RESOURCE", "ACTION");
  192. ALTER TABLE "NOCOS"."HIS_CONFIG_INFO"
  193. ADD CONSTRAINT PRIMARY KEY ("NID");
  194. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  195. ADD CONSTRAINT PRIMARY KEY ("ID");
  196. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  197. ADD CONSTRAINT "UK_GROUP_ID" UNIQUE ("GROUP_ID");
  198. ALTER TABLE "NOCOS"."CONFIG_TAGS_RELATION"
  199. ADD CONSTRAINT PRIMARY KEY ("NID");
  200. ALTER TABLE "NOCOS"."CONFIG_TAGS_RELATION"
  201. ADD CONSTRAINT "UK_CONFIGTAGRELATION_CONFIGIDTAG" UNIQUE ("ID", "TAG_NAME", "TAG_TYPE");
  202. ALTER TABLE "NOCOS"."CONFIG_INFO_TAG"
  203. ADD CONSTRAINT PRIMARY KEY ("ID");
  204. ALTER TABLE "NOCOS"."CONFIG_INFO_TAG"
  205. ADD CONSTRAINT "UK_CONFIGINFOTAG_DATAGROUPTENANTTAG" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID", "TAG_ID");
  206. ALTER TABLE "NOCOS"."CONFIG_INFO_BETA"
  207. ADD CONSTRAINT PRIMARY KEY ("ID");
  208. ALTER TABLE "NOCOS"."CONFIG_INFO_BETA"
  209. ADD CONSTRAINT "UK_CONFIGINFOBETA_DATAGROUPTENANT" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID");
  210. ALTER TABLE "NOCOS"."CONFIG_INFO_AGGR"
  211. ADD CONSTRAINT PRIMARY KEY ("ID");
  212. ALTER TABLE "NOCOS"."CONFIG_INFO_AGGR"
  213. ADD CONSTRAINT "UK_CONFIGINFOAGGR_DATAGROUPTENANTDATUM" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID", "DATUM_ID");
  214. ALTER TABLE "NOCOS"."CONFIG_INFO"
  215. ADD CONSTRAINT PRIMARY KEY ("ID");
  216. ALTER TABLE "NOCOS"."CONFIG_INFO"
  217. ADD CONSTRAINT "UK_CONFIGINFO_DATAGROUPTENANT" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID");
  218. CREATE INDEX "IDX_TENANT_ID"
  219. ON "NOCOS"."TENANT_INFO" ("TENANT_ID");
  220. COMMENT
  221. ON TABLE "NOCOS"."TENANT_INFO" IS 'tenant_info';
  222. COMMENT
  223. ON COLUMN "NOCOS"."TENANT_INFO"."ID" IS 'id';
  224. COMMENT
  225. ON COLUMN "NOCOS"."TENANT_INFO"."KP" IS 'kp';
  226. COMMENT
  227. ON COLUMN "NOCOS"."TENANT_INFO"."TENANT_ID" IS 'tenant_id';
  228. COMMENT
  229. ON COLUMN "NOCOS"."TENANT_INFO"."TENANT_NAME" IS 'tenant_name';
  230. COMMENT
  231. ON COLUMN "NOCOS"."TENANT_INFO"."TENANT_DESC" IS 'tenant_desc';
  232. COMMENT
  233. ON COLUMN "NOCOS"."TENANT_INFO"."CREATE_SOURCE" IS 'create_source';
  234. COMMENT
  235. ON COLUMN "NOCOS"."TENANT_INFO"."GMT_CREATE" IS '创建时间';
  236. COMMENT
  237. ON COLUMN "NOCOS"."TENANT_INFO"."GMT_MODIFIED" IS '修改时间';
  238. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  239. ADD CHECK ("QUOTA" >= 0) ENABLE;
  240. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  241. ADD CHECK ("MAX_HISTORY_COUNT" >= 0) ENABLE;
  242. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  243. ADD CHECK ("MAX_AGGR_SIZE" >= 0) ENABLE;
  244. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  245. ADD CHECK ("MAX_AGGR_COUNT" >= 0) ENABLE;
  246. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  247. ADD CHECK ("MAX_SIZE" >= 0) ENABLE;
  248. ALTER TABLE "NOCOS"."TENANT_CAPACITY"
  249. ADD CHECK ("USAGE" >= 0) ENABLE;
  250. COMMENT
  251. ON TABLE "NOCOS"."TENANT_CAPACITY" IS '租户容量信息表';
  252. COMMENT
  253. ON COLUMN "NOCOS"."TENANT_CAPACITY"."ID" IS '主键ID';
  254. COMMENT
  255. ON COLUMN "NOCOS"."TENANT_CAPACITY"."TENANT_ID" IS 'Tenant ID';
  256. COMMENT
  257. ON COLUMN "NOCOS"."TENANT_CAPACITY"."QUOTA" IS '配额,0表示使用默认值';
  258. COMMENT
  259. ON COLUMN "NOCOS"."TENANT_CAPACITY"."USAGE" IS '使用量';
  260. COMMENT
  261. ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_SIZE" IS '单个配置大小上限,单位为字节,0表示使用默认值';
  262. COMMENT
  263. ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_AGGR_COUNT" IS '聚合子配置最大个数';
  264. COMMENT
  265. ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_AGGR_SIZE" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
  266. COMMENT
  267. ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_HISTORY_COUNT" IS '最大变更历史数量';
  268. COMMENT
  269. ON COLUMN "NOCOS"."TENANT_CAPACITY"."GMT_CREATE" IS '创建时间';
  270. COMMENT
  271. ON COLUMN "NOCOS"."TENANT_CAPACITY"."GMT_MODIFIED" IS '修改时间';
  272. ALTER TABLE "NOCOS"."HIS_CONFIG_INFO"
  273. ADD CHECK ("ID" >= 0) ENABLE;
  274. CREATE INDEX "IDX_GMT_MODIFIED"
  275. ON "NOCOS"."HIS_CONFIG_INFO" ("GMT_MODIFIED");
  276. CREATE INDEX "IDX_GMT_CREATE"
  277. ON "NOCOS"."HIS_CONFIG_INFO" ("GMT_CREATE");
  278. CREATE INDEX "IDX_DID"
  279. ON "NOCOS"."HIS_CONFIG_INFO" ("DATA_ID");
  280. COMMENT
  281. ON TABLE "NOCOS"."HIS_CONFIG_INFO" IS '多租户改造';
  282. COMMENT
  283. ON COLUMN "NOCOS"."HIS_CONFIG_INFO"."APP_NAME" IS 'app_name';
  284. COMMENT
  285. ON COLUMN "NOCOS"."HIS_CONFIG_INFO"."TENANT_ID" IS '租户字段';
  286. COMMENT
  287. ON COLUMN "NOCOS"."HIS_CONFIG_INFO"."ENCRYPTED_DATA_KEY" IS '密钥';
  288. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  289. ADD CHECK ("QUOTA" >= 0) ENABLE;
  290. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  291. ADD CHECK ("MAX_HISTORY_COUNT" >= 0) ENABLE;
  292. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  293. ADD CHECK ("MAX_AGGR_SIZE" >= 0) ENABLE;
  294. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  295. ADD CHECK ("MAX_AGGR_COUNT" >= 0) ENABLE;
  296. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  297. ADD CHECK ("MAX_SIZE" >= 0) ENABLE;
  298. ALTER TABLE "NOCOS"."GROUP_CAPACITY"
  299. ADD CHECK ("USAGE" >= 0) ENABLE;
  300. COMMENT
  301. ON TABLE "NOCOS"."GROUP_CAPACITY" IS '集群、各Group容量信息表';
  302. COMMENT
  303. ON COLUMN "NOCOS"."GROUP_CAPACITY"."ID" IS '主键ID';
  304. COMMENT
  305. ON COLUMN "NOCOS"."GROUP_CAPACITY"."GROUP_ID" IS 'Group ID,空字符表示整个集群';
  306. COMMENT
  307. ON COLUMN "NOCOS"."GROUP_CAPACITY"."QUOTA" IS '配额,0表示使用默认值';
  308. COMMENT
  309. ON COLUMN "NOCOS"."GROUP_CAPACITY"."USAGE" IS '使用量';
  310. COMMENT
  311. ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_SIZE" IS '单个配置大小上限,单位为字节,0表示使用默认值';
  312. COMMENT
  313. ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_AGGR_COUNT" IS '聚合子配置最大个数,,0表示使用默认值';
  314. COMMENT
  315. ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_AGGR_SIZE" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
  316. COMMENT
  317. ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_HISTORY_COUNT" IS '最大变更历史数量';
  318. COMMENT
  319. ON COLUMN "NOCOS"."GROUP_CAPACITY"."GMT_CREATE" IS '创建时间';
  320. COMMENT
  321. ON COLUMN "NOCOS"."GROUP_CAPACITY"."GMT_MODIFIED" IS '修改时间';
  322. COMMENT
  323. ON TABLE "NOCOS"."CONFIG_TAGS_RELATION" IS 'config_tag_relation';
  324. COMMENT
  325. ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."ID" IS 'id';
  326. COMMENT
  327. ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."TAG_NAME" IS 'tag_name';
  328. COMMENT
  329. ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."TAG_TYPE" IS 'tag_type';
  330. COMMENT
  331. ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."DATA_ID" IS 'data_id';
  332. COMMENT
  333. ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."GROUP_ID" IS 'group_id';
  334. COMMENT
  335. ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."TENANT_ID" IS 'tenant_id';
  336. COMMENT
  337. ON TABLE "NOCOS"."CONFIG_INFO_TAG" IS 'config_info_tag';
  338. COMMENT
  339. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."ID" IS 'id';
  340. COMMENT
  341. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."DATA_ID" IS 'data_id';
  342. COMMENT
  343. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."GROUP_ID" IS 'group_id';
  344. COMMENT
  345. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."TENANT_ID" IS 'tenant_id';
  346. COMMENT
  347. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."TAG_ID" IS 'tag_id';
  348. COMMENT
  349. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."APP_NAME" IS 'app_name';
  350. COMMENT
  351. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."CONTENT" IS 'content';
  352. COMMENT
  353. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."MD5" IS 'md5';
  354. COMMENT
  355. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."GMT_CREATE" IS '创建时间';
  356. COMMENT
  357. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."GMT_MODIFIED" IS '修改时间';
  358. COMMENT
  359. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."SRC_USER" IS 'source user';
  360. COMMENT
  361. ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."SRC_IP" IS 'source ip';
  362. COMMENT
  363. ON TABLE "NOCOS"."CONFIG_INFO_BETA" IS 'config_info_beta';
  364. COMMENT
  365. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."ID" IS 'id';
  366. COMMENT
  367. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."DATA_ID" IS 'data_id';
  368. COMMENT
  369. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."GROUP_ID" IS 'group_id';
  370. COMMENT
  371. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."APP_NAME" IS 'app_name';
  372. COMMENT
  373. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."CONTENT" IS 'content';
  374. COMMENT
  375. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."BETA_IPS" IS 'betaIps';
  376. COMMENT
  377. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."MD5" IS 'md5';
  378. COMMENT
  379. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."GMT_CREATE" IS '创建时间';
  380. COMMENT
  381. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."GMT_MODIFIED" IS '修改时间';
  382. COMMENT
  383. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."SRC_USER" IS 'source user';
  384. COMMENT
  385. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."SRC_IP" IS 'source ip';
  386. COMMENT
  387. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."TENANT_ID" IS '租户字段';
  388. COMMENT
  389. ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."ENCRYPTED_DATA_KEY" IS '密钥';
  390. COMMENT
  391. ON TABLE "NOCOS"."CONFIG_INFO_AGGR" IS '增加租户字段';
  392. COMMENT
  393. ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."ID" IS 'id';
  394. COMMENT
  395. ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."DATA_ID" IS 'data_id';
  396. COMMENT
  397. ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."GROUP_ID" IS 'group_id';
  398. COMMENT
  399. ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."DATUM_ID" IS 'datum_id';
  400. COMMENT
  401. ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."CONTENT" IS '内容';
  402. COMMENT
  403. ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."GMT_MODIFIED" IS '修改时间';
  404. COMMENT
  405. ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."TENANT_ID" IS '租户字段';
  406. COMMENT
  407. ON TABLE "NOCOS"."CONFIG_INFO" IS 'config_info';
  408. COMMENT
  409. ON COLUMN "NOCOS"."CONFIG_INFO"."ID" IS 'id';
  410. COMMENT
  411. ON COLUMN "NOCOS"."CONFIG_INFO"."DATA_ID" IS 'data_id';
  412. COMMENT
  413. ON COLUMN "NOCOS"."CONFIG_INFO"."CONTENT" IS 'content';
  414. COMMENT
  415. ON COLUMN "NOCOS"."CONFIG_INFO"."MD5" IS 'md5';
  416. COMMENT
  417. ON COLUMN "NOCOS"."CONFIG_INFO"."GMT_CREATE" IS '创建时间';
  418. COMMENT
  419. ON COLUMN "NOCOS"."CONFIG_INFO"."GMT_MODIFIED" IS '修改时间';
  420. COMMENT
  421. ON COLUMN "NOCOS"."CONFIG_INFO"."SRC_USER" IS 'source user';
  422. COMMENT
  423. ON COLUMN "NOCOS"."CONFIG_INFO"."SRC_IP" IS 'source ip';
  424. COMMENT
  425. ON COLUMN "NOCOS"."CONFIG_INFO"."TENANT_ID" IS '租户字段';
  426. COMMENT
  427. ON COLUMN "NOCOS"."CONFIG_INFO"."ENCRYPTED_DATA_KEY" IS '密钥';
  428. INSERT INTO "NOCOS"."USERS"("USERNAME", "PASSWORD", "ENABLED")
  429. VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);
  430. INSERT INTO "NOCOS"."ROLES"("USERNAME", "ROLE")
  431. VALUES ('nacos', 'ROLE_ADMIN');
6. 打包、指定加载依赖运行

最后在nacos源码最外层pom所在文件夹打开cmd运行打包命令:

mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Drat.skip=true -Dcheckstyle.skip=true clean install -U

命令结束会在distribution模块所在的target目录下生成zip包和tar.gz包,

解压对应的安装包,找到bin目录下的启动脚本,查看-Dloader.path命令后面指定的目录,在该任意目录下放进达梦的jdbc驱动即可,最后,修改conf下面的配置文件中的datasource配置,然后驱动命令运行即可

2.2.6 kingbase8适配

本次选举的kingbase版本是kingbaseV008R006C008B0014,选的是兼容mysql模式,其他版本以及兼容oracle或者pg模式的kingbase仅供参考,如果说能运行脚本,一般就没多大问题

1. 新增kingbase的dialect实现以及Mapper

新增package: com.alibaba.nacos.plugin.datasource.impl.kingbase8.dialect

在该package下面新增类:Kingbase8DatabaseDialect

主要是对limit做了特殊处理

  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8.dialect;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.dialect.AbstractDatabaseDialect;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2024/1/2
  9. */
  10. public class Kingbase8DatabaseDialect extends AbstractDatabaseDialect {
  11. @Override
  12. public String getLimitPageSqlWithMark(String sql) {
  13. return sql + " LIMIT ? OFFSET ? ";
  14. }
  15. @Override
  16. public String getLimitPageSql(String sql, int pageNo, int pageSize) {
  17. return sql + " LIMIT " + pageSize + " OFFSET " + getPagePrevNum(pageNo, pageSize);
  18. }
  19. @Override
  20. public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize){
  21. return sql + " LIMIT " + pageSize + " OFFSET " + startOffset;
  22. }
  23. @Override
  24. public String[] getReturnPrimaryKeys() {
  25. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  26. }
  27. @Override
  28. public String getType() {
  29. return KINGBASE8;
  30. }
  31. }

然后就是各个Mapper的覆写,因为上面的方言以及做了处理,所以这一块改动不大,具体代码如下:在package:com.alibaba.nacos.plugin.datasource.impl.kingbase8下面新增以下类

ConfigInfoAggrMapperByKingbase8
  1. /*
  2. * Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  17. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  18. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoAggrMapper;
  19. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  20. /**
  21. * @Description TODO
  22. * @Author wx
  23. * @Date 2023/11/23
  24. */
  25. public class ConfigInfoAggrMapperByKingbase8 extends BaseConfigInfoAggrMapper {
  26. @Override
  27. public String getDataSource() {
  28. return KINGBASE8;
  29. }
  30. @Override
  31. public String[] getPrimaryKeyGeneratedKeys() {
  32. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  33. }
  34. }
ConfigInfoBetaMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoBetaMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigInfoBetaMapperByKingbase8 extends BaseConfigInfoBetaMapper {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
ConfigInfoMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigInfoMapperByKingbase8 extends BaseConfigInfoMapper {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
ConfigInfoTagMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoTagMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigInfoTagMapperByKingbase8 extends BaseConfigInfoTagMapper {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
ConfigTagsRelationMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigTagsRelationMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class ConfigTagsRelationMapperByKingbase8 extends BaseConfigTagsRelationMapper {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
GroupCapacityMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseGroupCapacityMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class GroupCapacityMapperByKingbase8 extends BaseGroupCapacityMapper {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
HistoryConfigInfoMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class HistoryConfigInfoMapperByKingbase8 extends HistoryConfigInfoMapperByMySql {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
TenantCapacityMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantCapacityMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class TenantCapacityMapperByKingbase8 extends BaseTenantCapacityMapper {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
TenantInfoMapperByKingbase8
  1. package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
  2. import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
  3. import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantInfoMapper;
  4. import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
  5. /**
  6. * @Description TODO
  7. * @Author wx
  8. * @Date 2023/11/23
  9. */
  10. public class TenantInfoMapperByKingbase8 extends BaseTenantInfoMapper {
  11. @Override
  12. public String getDataSource() {
  13. return KINGBASE8;
  14. }
  15. @Override
  16. public String[] getPrimaryKeyGeneratedKeys() {
  17. return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
  18. }
  19. }
2. 增加SPI加载

为了能够让spring加载到我们的配置,需要进行对应services的修改

修改文件:resources/META-INF.services下的

com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect

增加自定义kingbase8的dialect配置

  1. #
  2. # Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. #
  17. com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect
  18. com.alibaba.nacos.plugin.datasource.impl.kingbase8.dialect.Kingbase8DatabaseDialect

修改resources/META-INF.services下的com.alibaba.nacos.plugin.datasource.mapper.Mapper文件

将上面自定义kingbase8相关的Mapper配置进去

  1. #
  2. # Copyright 1999-2022 Alibaba Group Holding Ltd.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql
  17. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql
  18. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql
  19. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql
  20. com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql
  21. com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql
  22. com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql
  23. com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql
  24. com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql
  25. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby
  26. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby
  27. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby
  28. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby
  29. com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby
  30. com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby
  31. com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby
  32. com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby
  33. com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerby
  34. com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoAggrMapperByKingbase8
  35. com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoBetaMapperByKingbase8
  36. com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoMapperByKingbase8
  37. com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoTagMapperByKingbase8
  38. com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigTagsRelationMapperByKingbase8
  39. com.alibaba.nacos.plugin.datasource.impl.kingbase8.GroupCapacityMapperByKingbase8
  40. com.alibaba.nacos.plugin.datasource.impl.kingbase8.HistoryConfigInfoMapperByKingbase8
  41. com.alibaba.nacos.plugin.datasource.impl.kingbase8.TenantCapacityMapperByKingbase8
  42. com.alibaba.nacos.plugin.datasource.impl.kingbase8.TenantInfoMapperByKingbase8
3. kingbase8 jdbc配置
  1. spring.sql.init.platform=kingbase8
  2. ### Count of DB:
  3. db.num=1
  4. ### Connect URL of DB:
  5. db.url.0=jdbc:kingbase8://localhost:54321/xxxx
  6. db.user.0=xxxx
  7. db.password.0=123456
  8. db.driver-class-name.0=com.kingbase8.Driver
4. kingbase8脚本
  1. CREATE TABLE "config_info" (
  2. "id" BIGSERIAL NOT NULL,
  3. "data_id" character varying(255 char) NOT NULL,
  4. "group_id" character varying(255 char) NULL,
  5. "content" text NOT NULL,
  6. "md5" character varying(32 char) NULL,
  7. "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  8. "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  9. "src_user" text NULL,
  10. "src_ip" character varying(50 char) NULL,
  11. "app_name" character varying(128 char) NULL,
  12. "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
  13. "c_desc" character varying(256 char) NULL,
  14. "c_use" character varying(64 char) NULL,
  15. "effect" character varying(64 char) NULL,
  16. "type" character varying(64 char) NULL,
  17. "c_schema" text NULL,
  18. "encrypted_data_key" text NULL,
  19. CONSTRAINT "PRIMARY_73F26186" PRIMARY KEY (id),
  20. CONSTRAINT "uk_configinfo_datagrouptenant_C827FEB8" UNIQUE (data_id, group_id, tenant_id)
  21. );
  22. CREATE TABLE "config_info_aggr" (
  23. "id" BIGSERIAL NOT NULL,
  24. "data_id" character varying(255 char) NOT NULL,
  25. "group_id" character varying(255 char) NOT NULL,
  26. "datum_id" character varying(255 char) NOT NULL,
  27. "content" text NOT NULL,
  28. "gmt_modified" timestamp(0) without time zone NOT NULL,
  29. "app_name" character varying(128 char) NULL,
  30. "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
  31. CONSTRAINT "PRIMARY_F787E5C0" PRIMARY KEY (id),
  32. CONSTRAINT "uk_configinfoaggr_datagrouptenantdatum_D10078D8" UNIQUE (data_id, group_id, tenant_id, datum_id)
  33. );
  34. CREATE TABLE "config_info_beta" (
  35. "id" BIGSERIAL NOT NULL,
  36. "data_id" character varying(255 char) NOT NULL,
  37. "group_id" character varying(128 char) NOT NULL,
  38. "app_name" character varying(128 char) NULL,
  39. "content" text NOT NULL,
  40. "beta_ips" character varying(1024 char) NULL,
  41. "md5" character varying(32 char) NULL,
  42. "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  43. "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  44. "src_user" text NULL,
  45. "src_ip" character varying(50 char) NULL,
  46. "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
  47. "encrypted_data_key" text NULL,
  48. CONSTRAINT "PRIMARY_E3F5B61F" PRIMARY KEY (id),
  49. CONSTRAINT "uk_configinfobeta_datagrouptenant_E4D7C681" UNIQUE (data_id, group_id, tenant_id)
  50. );
  51. CREATE TABLE "config_info_tag" (
  52. "id" BIGSERIAL NOT NULL,
  53. "data_id" character varying(255 char) NOT NULL,
  54. "group_id" character varying(128 char) NOT NULL,
  55. "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
  56. "tag_id" character varying(128 char) NOT NULL,
  57. "app_name" character varying(128 char) NULL,
  58. "content" text NOT NULL,
  59. "md5" character varying(32 char) NULL,
  60. "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  61. "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  62. "src_user" text NULL,
  63. "src_ip" character varying(50 char) NULL,
  64. CONSTRAINT "PRIMARY_26447CE1" PRIMARY KEY (id),
  65. CONSTRAINT "uk_configinfotag_datagrouptenanttag_5CBEB0AC" UNIQUE (data_id, group_id, tenant_id, tag_id)
  66. );
  67. CREATE TABLE "config_tags_relation" (
  68. "id" bigint NOT NULL,
  69. "tag_name" character varying(128 char) NOT NULL,
  70. "tag_type" character varying(64 char) NULL,
  71. "data_id" character varying(255 char) NOT NULL,
  72. "group_id" character varying(128 char) NOT NULL,
  73. "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
  74. "nid" BIGSERIAL NOT NULL,
  75. CONSTRAINT "PRIMARY_82226084" PRIMARY KEY (nid),
  76. CONSTRAINT "uk_configtagrelation_configidtag_25395725" UNIQUE (id, tag_name, tag_type)
  77. );
  78. CREATE INDEX idx_tenant_id_4FB846F8 ON config_tags_relation USING btree (tenant_id);
  79. CREATE TABLE "group_capacity" (
  80. "id" BIGSERIAL NOT NULL,
  81. "group_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
  82. "quota" bigint NOT NULL DEFAULT 0,
  83. "usage" bigint NOT NULL DEFAULT 0,
  84. "max_size" bigint NOT NULL DEFAULT 0,
  85. "max_aggr_count" bigint NOT NULL DEFAULT 0,
  86. "max_aggr_size" bigint NOT NULL DEFAULT 0,
  87. "max_history_count" bigint NOT NULL DEFAULT 0,
  88. "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  89. "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  90. CONSTRAINT "PRIMARY_D72B7E75" PRIMARY KEY (id),
  91. CONSTRAINT "uk_group_id_377325F2" UNIQUE (group_id)
  92. );
  93. CREATE TABLE "his_config_info" (
  94. "id" numeric NOT NULL,
  95. "nid" BIGSERIAL NOT NULL,
  96. "data_id" character varying(255 char) NOT NULL,
  97. "group_id" character varying(128 char) NOT NULL,
  98. "app_name" character varying(128 char) NULL,
  99. "content" text NOT NULL,
  100. "md5" character varying(32 char) NULL,
  101. "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  102. "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  103. "src_user" text NULL,
  104. "src_ip" character varying(50 char) NULL,
  105. "op_type" character(10 char) NULL,
  106. "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
  107. "encrypted_data_key" text NULL,
  108. CONSTRAINT "PRIMARY_93A4DC6B" PRIMARY KEY (nid)
  109. );
  110. CREATE INDEX idx_did_8DE97C10 ON his_config_info USING btree (data_id);
  111. CREATE INDEX idx_gmt_create_F3B3E5A1 ON his_config_info USING btree (gmt_create);
  112. CREATE INDEX idx_gmt_modified_42DBB1BB ON his_config_info USING btree (gmt_modified);
  113. CREATE TABLE "permissions" (
  114. "role" character varying(50 char) NOT NULL,
  115. "resource" character varying(255 char) NOT NULL,
  116. "action" character varying(8 char) NOT NULL,
  117. CONSTRAINT "uk_role_permission_9C323780" UNIQUE (role, resource, action)
  118. );
  119. CREATE TABLE "roles" (
  120. "username" character varying(50 char) NOT NULL,
  121. "role" character varying(50 char) NOT NULL,
  122. CONSTRAINT "idx_user_role_314C5701" UNIQUE (username, role)
  123. );
  124. CREATE TABLE "tenant_capacity" (
  125. "id" BIGSERIAL NOT NULL,
  126. "tenant_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
  127. "quota" bigint NOT NULL DEFAULT 0,
  128. "usage" bigint NOT NULL DEFAULT 0,
  129. "max_size" bigint NOT NULL DEFAULT 0,
  130. "max_aggr_count" bigint NOT NULL DEFAULT 0,
  131. "max_aggr_size" bigint NOT NULL DEFAULT 0,
  132. "max_history_count" bigint NOT NULL DEFAULT 0,
  133. "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  134. "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
  135. CONSTRAINT "PRIMARY_F4CCC2AA" PRIMARY KEY (id),
  136. CONSTRAINT "uk_tenant_id_22935E1" UNIQUE (tenant_id)
  137. );
  138. CREATE TABLE "tenant_info" (
  139. "id" BIGSERIAL NOT NULL,
  140. "kp" character varying(128 char) NOT NULL,
  141. "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
  142. "tenant_name" character varying(128 char) NULL DEFAULT NULL::varchar,
  143. "tenant_desc" character varying(256 char) NULL,
  144. "create_source" character varying(32 char) NULL,
  145. "gmt_create" bigint NOT NULL,
  146. "gmt_modified" bigint NOT NULL,
  147. CONSTRAINT "PRIMARY_8B91ED1E" PRIMARY KEY (id),
  148. CONSTRAINT "uk_tenant_info_kptenantid_195888C1" UNIQUE (kp, tenant_id)
  149. );
  150. CREATE INDEX idx_tenant_id_ABB71DBA ON tenant_info USING btree (tenant_id);
  151. CREATE TABLE "users" (
  152. "username" character varying(50 char) NOT NULL,
  153. "password" character varying(500 char) NOT NULL,
  154. "enabled" tinyint NOT NULL,
  155. CONSTRAINT "PRIMARY_1A6B23BE" PRIMARY KEY (username)
  156. );
  157. INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);
  158. INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
5. 打包、指定加载依赖运行

最后在nacos源码最外层pom所在文件夹打开cmd运行打包命令:

mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Drat.skip=true -Dcheckstyle.skip=true clean install -U

命令结束会在distribution模块所在的target目录下生成zip包和tar.gz包,

解压对应的安装包,找到bin目录下的启动脚本,查看-Dloader.path命令后面指定的目录,在该任意目录下放进kingbase8的jdbc驱动即可,最后,修改conf下面的配置文件中的datasource配置,然后驱动命令运行即可

2.2.7 其他数据库的适配

介于时间和精力问题,本人没有对其他数据库进行适配,但是架子已经搭好了,如有需要进行其他数据库的适配,主要分以下几个步骤


1.脚本的适配


    针对nacos的脚本进行对应数据库的适配修改
    脚本主要改造的地方有几点
        1.自增
            针对不同数据库进行自增适配,或是用数据库支持的默认序列,或是用自定义创建序列进行实现
        2.字段类型的适配
            不同数据库对于string类型、int类型、date类型有对应的jdbc类型,只需要修改对应类型即可
        3.建表语句的主键和索引语句
            不同数据库对于指定主键和创建索引可能会有差异
    脚本这块关注这几点就可以了


2.创建对应的Dialect以及mapper


    创建自己数据库的Dialect,按照上面dm和kingbase一样,实现AbstractDatabaseDialect
    然后对里面的方法如果有需要重写的就进行重写
    主要是limit的支持,如果支持AbstractDatabaseDialect里面的写法就不用重写,不支持就需要重写自己的处理逻辑
    对应的Mapper里面的方法如果有需要特殊处理的就进行重写,没有就按照dm和kingbase的写法进行默认实现即可


3.配置SPI


    按照dm和kingbase的配置步骤进行spi配置即可


4.修改datasource配置


    进行对应数据库的datasouce配置即可


5.jdbc驱动问题


    我的建议是最好是打完包之后按照nacos的-Dloader.path命令后面指定的目录放驱动就行
    无需改源码的pom依赖


6.打包运行


    打包,放驱动,该配置,运行即可

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号