赞
踩
目录
2.1 ExternalDataSourceProperties.java源码修改
2.2.2 增加PrimaryKeyConstant.java类
2.2.3.1 新增DatabaseDialectManager类
2.2.3.2 新增package:com.alibaba.nacos.plugin.datasource.dialect
2. 新增抽象类 AbstractDatabaseDialect
3. 新增默认实现类 DefaultDatabaseDialect
新增BaseConfigTagsRelationMapper
1. 新增kingbase的dialect实现以及Mapper
主要是为了信创,需要各种开源组件以及自身开发的产品对国产环境进行验证,其中最重要的一环就是国产数据库的适配,在借鉴了各位大佬的文章以及查阅了无数国产数据库官方文档之后,最后整理出了一版兼容以上数据库的案例,本人已经测试过了,完美运行。整理不易,望诸君高台贵手,点赞支持。
nacos:2.2.3
nacos源码下载什么的在这里就不做赘述了,直接github下载的,数据库版本也没多大限制,只要能跑脚本的一般都没啥问题
修改这里主要是为了能自定义在配置文件里面配置driverClassName、testQuery等等自定义配置,反正都是源码修改,不在乎修改多少,这里一改,其他地方就能直接配置使用了,主打的就是省心,可直接复制下面代码覆盖源码,源码:com.alibaba.nacos.config.server.service.datasource.ExternalDataSourceProperties。
- /*
- * 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.config.server.service.datasource;
-
- import com.alibaba.nacos.common.utils.Preconditions;
- import com.alibaba.nacos.common.utils.StringUtils;
- import com.zaxxer.hikari.HikariDataSource;
- import org.apache.commons.collections.CollectionUtils;
- import org.springframework.boot.context.properties.bind.Bindable;
- import org.springframework.boot.context.properties.bind.Binder;
- import org.springframework.core.env.Environment;
-
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Objects;
-
- import static com.alibaba.nacos.common.utils.CollectionUtils.getOrDefault;
-
- /**
- * Properties of external DataSource.
- *
- * @author Nacos
- */
- public class ExternalDataSourceProperties {
-
- private static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
-
- private static final String TEST_QUERY = "SELECT 1";
-
- private Integer num;
-
- private List<String> url = new ArrayList<>();
-
- private List<String> user = new ArrayList<>();
-
- private List<String> password = new ArrayList<>();
-
- private List<String> driverClassName = new ArrayList<>();
-
- private List<String> testQuery = new ArrayList<>();
-
- public void setNum(Integer num) {
- this.num = num;
- }
-
- public void setUrl(List<String> url) {
- this.url = url;
- }
-
- public void setUser(List<String> user) {
- this.user = user;
- }
-
- public void setPassword(List<String> password) {
- this.password = password;
- }
-
- public List<String> getDriverClassName() {
- return driverClassName;
- }
-
- public void setDriverClassName(List<String> driverClassName) {
- this.driverClassName = driverClassName;
- }
-
- public void setTestQuery(List<String> testQuery) {
- this.testQuery = testQuery;
- }
-
- /**
- * Build serveral HikariDataSource.
- *
- * @param environment {@link Environment}
- * @param callback Callback function when constructing data source
- * @return List of {@link HikariDataSource}
- */
- List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {
- List<HikariDataSource> dataSources = new ArrayList<>();
- Binder.get(environment).bind("db", Bindable.ofInstance(this));
- Preconditions.checkArgument(Objects.nonNull(num), "db.num is null");
- Preconditions.checkArgument(CollectionUtils.isNotEmpty(user), "db.user or db.user.[index] is null");
- Preconditions.checkArgument(CollectionUtils.isNotEmpty(password), "db.password or db.password.[index] is null");
- Preconditions.checkArgument(CollectionUtils.isNotEmpty(driverClassName), "db.driverClassName or db.driverClassName.[index] is null");
- for (int index = 0; index < num; index++) {
- int currentSize = index + 1;
- Preconditions.checkArgument(url.size() >= currentSize, "db.url.%s is null", index);
- DataSourcePoolProperties poolProperties = DataSourcePoolProperties.build(environment);
- poolProperties.setDriverClassName(getOrDefault(driverClassName, index, JDBC_DRIVER_NAME).trim());
- poolProperties.setJdbcUrl(url.get(index).trim());
- poolProperties.setUsername(getOrDefault(user, index, user.get(0)).trim());
- poolProperties.setPassword(getOrDefault(password, index, password.get(0)).trim());
- HikariDataSource ds = poolProperties.getDataSource();
- if (StringUtils.isEmpty(ds.getConnectionTestQuery())) {
- ds.setConnectionTestQuery(getOrDefault(testQuery, index, TEST_QUERY).trim());
- }
- dataSources.add(ds);
- callback.accept(ds);
- }
- Preconditions.checkArgument(CollectionUtils.isNotEmpty(dataSources), "no datasource available");
- return dataSources;
- }
-
- interface Callback<D> {
-
- /**
- * Perform custom logic.
- *
- * @param datasource dataSource.
- */
- void accept(D datasource);
- }
- }
2.2.3版本的nacos已经适配了最新spring spi规范了,所以总体来讲开发一个nacos的插件是很容易的,并且源码里面已经给出了模板了,所以做一个nacos-datasource的plugin就直接在plugin模块下面对datasource模块进行改造即可,具体改造如下:
注意:以下代码改造都是在plugin模块-datasource模块下进行的改造,因此代码都是在datasource下进行的
在该常量类中增加需要支持的数据库类型,后续有其他要支持数据库类型都统一定义在该类中即可,类:com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant
- /*
- * 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.constants;
-
- /**
- * The data source name.
- *
- * @author hyx
- **/
-
- public class DataSourceConstant {
- public static final String MYSQL = "mysql";
-
- public static final String DM = "dm";
-
- public static final String DERBY = "derby";
-
- public static final String POSTGRESQL = "postgresql";
-
- public static final String KINGBASE8 = "kingbase8";
- }
这个常量类主要是为了适配数据库的大小写问题,放在constants包下
package:com.alibaba.nacos.plugin.datasource.constants
- package com.alibaba.nacos.plugin.datasource.constants;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class PrimaryKeyConstant {
-
- /**
- * replace lower Statement.RETURN_GENERATED_KEYS into id key.
- */
- public static final String[] LOWER_RETURN_PRIMARY_KEYS = new String[]{"id"};
-
- /**
- * upper replace Statement.RETURN_GENERATED_KEYS into id key.
- *
- */
- public static final String[] UPPER_RETURN_PRIMARY_KEYS = new String[]{"ID"};
- }
每种数据库都有不同的方言,因此为了统一对dialect管理,好后续做通配,因此需要设计一下dialect,主要改造步骤有以下几步:
这个manager主要是适配多数据源多方言的情况,不局限于一个进程就只能配置一种数据源和方言,可同时配置多数据源;
新增package: com.alibaba.nacos.plugin.datasource.manager
在该package下新增类: DatabaseDialectManager
- package com.alibaba.nacos.plugin.datasource.manager;
-
- import com.alibaba.nacos.common.spi.NacosServiceLoader;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
-
- import java.util.Collection;
- import java.util.Map;
- import java.util.concurrent.ConcurrentHashMap;
-
- /**
- * @Description TODO
- * @Author wx (mailto:wang-xin@primeton.com)
- * @Date 2023/11/23
- */
- public class DatabaseDialectManager {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseDialectManager.class);
-
- private static final DatabaseDialectManager INSTANCE = new DatabaseDialectManager();
-
- private static final Map<String, DatabaseDialect> SUPPORT_DIALECT_MAP = new ConcurrentHashMap<String, DatabaseDialect>();
-
- private DatabaseDialectManager() {
- }
-
- static {
- //加载多种数据库方言为映射信息
- Collection<DatabaseDialect> dialectList = NacosServiceLoader.load(DatabaseDialect.class);
-
- for (DatabaseDialect dialect : dialectList) {
- SUPPORT_DIALECT_MAP.put(dialect.getType(), dialect);
- }
- if (SUPPORT_DIALECT_MAP.isEmpty()) {
- LOGGER.warn("[DatasourceDialectManager] Load DatabaseDialect fail, No DatabaseDialect implements");
- }
- }
-
- public DatabaseDialect getDialect(String databaseType) {
- DatabaseDialect databaseDialect = SUPPORT_DIALECT_MAP.get(databaseType);
- if (databaseDialect == null) {
- return new DefaultDatabaseDialect();
- }
- return databaseDialect;
- }
-
- /**
- * Get DatasourceDialectManager instance.
- *
- * @return DataSourceDialectProvider
- */
- public static DatabaseDialectManager getInstance() {
- return INSTANCE;
- }
- }
以下代码都是在该package下面进行新增
这个接口主要是定义了一些每个数据库不同的实现的一些接口,比如:分页、字段大小写等
- package com.alibaba.nacos.plugin.datasource.dialect;
-
- /**
- * @Description TODO
- * @Author wx520
- * @Date 2023/11/23
- */
- public interface DatabaseDialect {
-
- /**
- * get database type.
- * @return return database type name
- */
- public String getType();
-
- /**
- * get frist index page param.
- * @param page current pageNo
- * @param pageSize current pageSize
- * @return offset val or maxRange
- */
- public int getPagePrevNum(int page, int pageSize);
-
- /**
- * get second index page param.
- * @param page current pageNo
- * @param pageSize current pageSize
- * @return limit val or minRange
- */
- public int getPageLastNum(int page, int pageSize);
-
- /**
- * get page limit top data sql,contain placeholder.
- * @param sql orign sql
- * @return append limit sql
- */
- public String getLimitTopSqlWithMark(String sql);
-
- /**
- * get page limit page data sql,contain placeholder.
- * @param sql orign sql
- * @return append limit sql
- */
- public String getLimitPageSqlWithMark(String sql);
-
- /**
- * get page limit page data sql,using number.
- * @param sql orign sql
- * @param pageNo current pageNo
- * @param pageSize current pageSize
- * @return contain page number param sql
- */
- public String getLimitPageSql(String sql, int pageNo, int pageSize);
-
- /**
- * get page limit page data sql,using offset.
- * @param sql orign sql
- * @param startOffset current offset row
- * @param pageSize current pageSize
- * @return contain page number param sql
- */
- public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize);
-
- /**
- * get database return primary keys.
- * @return
- */
- public String[] getReturnPrimaryKeys();
- }
该抽象类主要是新增一些方言的默认实现,比如limit的默认实现,大部分数据库对于limit的支持都是limit a ; limit a,b 这种,也有不分数据库是不支持limit a,b的,支持limt b offset a这种等等,所以提供一个大部分都支持的默认实现,少部分差异的再具体重写实现。
- package com.alibaba.nacos.plugin.datasource.dialect;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public abstract class AbstractDatabaseDialect implements DatabaseDialect {
-
- @Override
- public int getPagePrevNum(int page, int pageSize) {
- return (page - 1) * pageSize;
- }
-
- @Override
- public int getPageLastNum(int page, int pageSize) {
- return pageSize;
- }
-
- @Override
- public String getLimitTopSqlWithMark(String sql) {
- return sql + " LIMIT ? ";
- }
-
- @Override
- public String getLimitPageSqlWithMark(String sql) {
- return sql + " LIMIT ?,? ";
- }
-
- @Override
- public String getLimitPageSql(String sql, int pageNo, int pageSize) {
- return sql + " LIMIT " + getPagePrevNum(pageNo, pageSize) + " , " + pageSize;
- }
-
- @Override
- public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize){
- return sql + " LIMIT " + startOffset + " , " + pageSize;
- }
-
- @Override
- public String[] getReturnPrimaryKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
默认实现类默认为mysql,因此无需做什么特殊改动
- package com.alibaba.nacos.plugin.datasource.dialect;
-
- import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class DefaultDatabaseDialect extends AbstractDatabaseDialect {
- @Override
- public String getType() {
- //默认mysql实现
- return DataSourceConstant.MYSQL;
- }
- }
首先新增package: com.alibaba.nacos.plugin.datasource.impl.base
然后在该package下面新增一些BaseMapper,具体如下:
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseConfigInfoAggrMapper extends ConfigInfoAggrMapperByMySql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseConfigInfoAggrMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- @Override
- public String getTableName() {
- return TableConstant.CONFIG_INFO_AGGR;
- }
-
- @Override
- public String findConfigInfoAggrByPageFetchRows(int startRow, int pageSize) {
- return databaseDialect.getLimitPageSqlWithOffset(
- "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
- + "group_id= ? AND tenant_id= ? ORDER BY datum_id ", startRow, pageSize);
- }
- }
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseConfigInfoBetaMapper extends ConfigInfoBetaMapperByMySql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseConfigInfoBetaMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- @Override
- public String getTableName() {
- return TableConstant.CONFIG_INFO_BETA;
- }
-
- public String getLimitPageSqlWithOffset(String sql, int startRow, int pageSize) {
- return databaseDialect.getLimitPageSqlWithOffset(sql, startRow, pageSize);
- }
-
- @Override
- public String findAllConfigInfoBetaForDumpAllFetchRows(int startRow, int pageSize) {
- String sqlInner = getLimitPageSqlWithOffset("SELECT id FROM config_info_beta ORDER BY id ", startRow,
- pageSize);
- String sql =
- " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
- + " FROM ( " + sqlInner + " )" + " g, config_info_beta t WHERE g.id = t.id ";
- return sql;
- }
- }
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.common.utils.StringUtils;
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseConfigInfoMapper extends ConfigInfoMapperByMySql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseConfigInfoMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) {
- return databaseDialect.getLimitPageSqlWithOffset(sql, startOffset, pageSize);
- }
-
- public String getLimitPageSqlWithMark(String sql) {
- return databaseDialect.getLimitPageSqlWithMark(sql);
- }
-
- @Override
- public String findConfigInfoByAppFetchRows(int startRow, int pageSize) {
- return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"
- + " WHERE tenant_id LIKE ? AND app_name= ?", startRow, pageSize);
- }
-
- @Override
- public String getTenantIdList(int startRow, int pageSize) {
- return getLimitPageSqlWithOffset(
- "SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY tenant_id ", startRow, pageSize);
- }
-
- @Override
- public String getGroupIdList(int startRow, int pageSize) {
- return getLimitPageSqlWithOffset(
- "SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id ", +startRow, pageSize);
- }
-
- @Override
- public String findAllConfigKey(int startRow, int pageSize) {
- String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id ",
- startRow, pageSize);
- return " SELECT data_id,group_id,app_name FROM ( " + innerSql + " g, config_info t WHERE g.id = t.id ";
- }
-
- @Override
- public String findAllConfigInfoBaseFetchRows(int startRow, int pageSize) {
- String innerSql = getLimitPageSqlWithMark(" SELECT id FROM config_info ORDER BY id ");
- return " SELECT t.id,data_id,group_id,content,md5" + " FROM ( " + innerSql + " ) "
- + " g, config_info t WHERE g.id = t.id ";
- }
-
- @Override
- public String findAllConfigInfoFragment(int startRow, int pageSize) {
- return getLimitPageSqlWithOffset(
- "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "
- + "FROM config_info WHERE id > ? ORDER BY id ASC ", startRow, pageSize);
- }
-
- @Override
- public String findChangeConfigFetchRows(Map<String, String> params, final Timestamp startTime,
- final Timestamp endTime, int startRow, int pageSize, long lastMaxId) {
- final String tenant = params.get(TENANT);
- final String dataId = params.get(DATA_ID);
- final String group = params.get(GROUP);
- final String appName = params.get(APP_NAME);
- final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
- List<Object> paramList = new ArrayList<>();
-
- final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM config_info WHERE ";
- String where = " 1=1 ";
- if (!StringUtils.isBlank(dataId)) {
- where += " AND data_id LIKE ? ";
- paramList.add(dataId);
- }
- if (!StringUtils.isBlank(group)) {
- where += " AND group_id LIKE ? ";
- paramList.add(group);
- }
- if (!StringUtils.isBlank(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);
- }
- String originSql = sqlFetchRows + where + " AND id > " + lastMaxId + " ORDER BY id ASC";
- return getLimitPageSqlWithOffset(originSql, 0, pageSize);
- }
-
- @Override
- public String listGroupKeyMd5ByPageFetchRows(int startRow, int pageSize) {
- String innerSql = getLimitPageSqlWithOffset(" SELECT id FROM config_info ORDER BY id ", startRow, pageSize);
- String sql =
- " SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM " + "( "
- + innerSql + " ) g, config_info t WHERE g.id = t.id";
- return sql;
- }
-
- @Override
- public String findConfigInfoBaseLikeFetchRows(Map<String, String> params, int startRow, int pageSize) {
- final String dataId = params.get(DATA_ID);
- final String group = params.get(GROUP);
- final String content = params.get(CONTENT);
- final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
- String where = " 1=1 AND tenant_id='' ";
- if (!StringUtils.isBlank(dataId)) {
- where += " AND data_id LIKE ? ";
- }
- if (!StringUtils.isBlank(group)) {
- where += " AND group_id LIKE ";
- }
- if (!StringUtils.isBlank(content)) {
- where += " AND content LIKE ? ";
- }
- return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
- }
-
- @Override
- public String findConfigInfo4PageFetchRows(Map<String, String> params, int startRow, int pageSize) {
- final String appName = params.get(APP_NAME);
- final String dataId = params.get(DATA_ID);
- final String group = params.get(GROUP);
- final String content = params.get(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=? ");
- 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 getLimitPageSqlWithOffset(sql + where, startRow, pageSize);
- }
-
- @Override
- public String findConfigInfoBaseByGroupFetchRows(int startRow, int pageSize) {
- String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? ";
- return getLimitPageSqlWithOffset(sql, startRow, pageSize);
- }
-
- @Override
- public String findConfigInfoLike4PageFetchRows(Map<String, String> params, int startRow, int pageSize) {
- String dataId = params.get(DATA_ID);
- String group = params.get(GROUP);
- final String appName = params.get(APP_NAME);
- final String content = params.get(CONTENT);
- final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";
- StringBuilder where = new StringBuilder(" WHERE ");
- where.append(" tenant_id LIKE ? ");
- List<Object> paramList = new ArrayList<>();
- if (!StringUtils.isBlank(dataId)) {
- where.append(" AND data_id LIKE ? ");
- paramList.add(dataId);
- }
- if (!StringUtils.isBlank(group)) {
- where.append(" AND group_id LIKE ? ");
- paramList.add(group);
- }
- if (!StringUtils.isBlank(appName)) {
- where.append(" AND app_name = ? ");
- paramList.add(appName);
- }
- if (!StringUtils.isBlank(content)) {
- where.append(" AND content LIKE ? ");
- paramList.add(content);
- }
- return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
- }
-
- @Override
- public String findAllConfigInfoFetchRows(int startRow, int pageSize) {
- String innerSql = getLimitPageSqlWithMark("SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id ");
- return " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 " + " FROM ( " + innerSql + " )"
- + " g, config_info t WHERE g.id = t.id ";
- }
-
- @Override
- public String getTableName() {
- return TableConstant.CONFIG_INFO;
- }
- }
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseConfigInfoTagMapper extends ConfigInfoTagMapperByMySql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseConfigInfoTagMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- @Override
- public String getTableName() {
- return TableConstant.CONFIG_INFO_TAG;
- }
-
- @Override
- public String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize) {
- String innerSql = databaseDialect
- .getLimitPageSqlWithOffset("SELECT id FROM config_info_tag ORDER BY id ", startRow, pageSize);
- return " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified " + " FROM ( "
- + innerSql + " ) " + "g, config_info_tag t WHERE g.id = t.id ";
- }
- }
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.common.utils.StringUtils;
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseConfigTagsRelationMapper extends ConfigTagsRelationMapperByMySql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseConfigTagsRelationMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize) {
- return databaseDialect.getLimitPageSqlWithOffset(sql, startOffset, pageSize);
- }
-
- @Override
- public String getTableName() {
- return TableConstant.CONFIG_TAGS_RELATION;
- }
-
- @Override
- public String findConfigInfo4PageFetchRows(Map<String, String> params, int tagSize, int startRow, int pageSize) {
- final String appName = params.get("appName");
- final String dataId = params.get("dataId");
- final String group = params.get("group");
- final String content = params.get("content");
- 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=? ");
- 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 < tagSize; i++) {
- if (i != 0) {
- where.append(", ");
- }
- where.append('?');
- }
- where.append(") ");
- return getLimitPageSqlWithOffset(sql + where, startRow, pageSize);
- }
-
- @Override
- public String findConfigInfoLike4PageFetchRows(final Map<String, String> params,
- int tagSize,
- int startRow,
- int pageSize) {
- final String appName = params.get("appName");
- final String content = params.get("content");
- final String dataId = params.get("dataId");
- final String group = params.get("group");
- List<Object> paramList = new ArrayList<>();
- StringBuilder where = new StringBuilder(" WHERE ");
- final String sqlFetchRows = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content "
- + "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";
-
- where.append(" a.tenant_id LIKE ? ");
- if (!StringUtils.isBlank(dataId)) {
- where.append(" AND a.data_id LIKE ? ");
- paramList.add(dataId);
- }
- if (!StringUtils.isBlank(group)) {
- where.append(" AND a.group_id LIKE ? ");
- paramList.add(group);
- }
- if (!StringUtils.isBlank(appName)) {
- where.append(" AND a.app_name = ? ");
- paramList.add(appName);
- }
- if (!StringUtils.isBlank(content)) {
- where.append(" AND a.content LIKE ? ");
- paramList.add(content);
- }
- where.append(" AND b.tag_name IN (");
- for (int i = 0; i < tagSize; i++) {
- if (i != 0) {
- where.append(", ");
- }
- where.append('?');
- }
- where.append(") ");
- return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
- }
- }
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseGroupCapacityMapper extends GroupCapacityMapperByMysql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseGroupCapacityMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- @Override
- public String getTableName() {
- return TableConstant.GROUP_CAPACITY;
- }
-
- @Override
- public String selectGroupInfoBySize() {
- return databaseDialect.getLimitTopSqlWithMark("SELECT id, group_id FROM group_capacity WHERE id > ?");
- }
- }
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseTenantCapacityMapper extends TenantCapacityMapperByMySql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseTenantCapacityMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- @Override
- public String getTableName() {
- return TableConstant.TENANT_CAPACITY;
- }
-
- @Override
- public String getCapacityList4CorrectUsage() {
- return databaseDialect.getLimitTopSqlWithMark("SELECT id, tenant_id FROM tenant_capacity WHERE id>?");
- }
- }
- package com.alibaba.nacos.plugin.datasource.impl.base;
-
- import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql;
- import com.alibaba.nacos.plugin.datasource.manager.DatabaseDialectManager;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class BaseTenantInfoMapper extends TenantInfoMapperByMySql {
-
- private DatabaseDialect databaseDialect;
-
- public BaseTenantInfoMapper() {
- databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
- }
-
- @Override
- public String getTableName() {
- return TableConstant.TENANT_INFO;
- }
- }
新增package: com.alibaba.nacos.plugin.datasource.impl.dm.dialect
在该package下面新增类:DaMengDatabaseDialect
- package com.alibaba.nacos.plugin.datasource.impl.dm.dialect;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.AbstractDatabaseDialect;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class DaMengDatabaseDialect extends AbstractDatabaseDialect {
-
- @Override
- public String[] getReturnPrimaryKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
-
- @Override
- public String getType() {
- return DM;
- }
- }
然后就是各个Mapper的覆写,因为dm基本都支持mysql的语法,所以这一块改动不大,具体代码如下:在package:com.alibaba.nacos.plugin.datasource.impl.dm下面新增以下类
ConfigInfoAggrMapperByDM
- /*
- * 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.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoAggrMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoAggrMapperByDM extends BaseConfigInfoAggrMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigInfoBetaMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoBetaMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoBetaMapperByDM extends BaseConfigInfoBetaMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigInfoMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoMapperByDM extends BaseConfigInfoMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigInfoTagMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoTagMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoTagMapperByDM extends BaseConfigInfoTagMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigTagsRelationMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigTagsRelationMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigTagsRelationMapperByDM extends BaseConfigTagsRelationMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
GroupCapacityMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseGroupCapacityMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class GroupCapacityMapperByDM extends BaseGroupCapacityMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
HistoryConfigInfoMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class HistoryConfigInfoMapperByDM extends HistoryConfigInfoMapperByMySql {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
TenantCapacityMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantCapacityMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class TenantCapacityMapperByDM extends BaseTenantCapacityMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
TenantInfoMapperByDM
- package com.alibaba.nacos.plugin.datasource.impl.dm;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantInfoMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.DM;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class TenantInfoMapperByDM extends BaseTenantInfoMapper {
-
- @Override
- public String getDataSource() {
- return DM;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.UPPER_RETURN_PRIMARY_KEYS;
- }
- }
在resource目录下新增sql-error-codes.xml
这个配置文件主要是映射达梦数据库错误码
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
- <!--
- - Default SQL error codes for well-known databases.
- - Can be overridden by definitions in a "sql-error-codes.xml" file
- - in the root of the class path.
- -
- - If the Database Product Name contains characters that are invalid
- - to use in the id attribute (like a space) then we need to add a property
- - named "databaseProductName"/"databaseProductNames" that holds this value.
- - If this property is present, then it will be used instead of the id for
- - looking up the error codes based on the current database.
- -->
-
- <!--
- 此文件主要做dameng数据库错误码与spring异常类的映射关系
- 如果没有此文件 修改配置时唯一索冲突并不会抛出 DuplicateKeyException 的异常
- -->
- <beans>
- <!-- 支持达梦数据库错误码-->
- <bean id="DM" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="databaseProductNames">
- <list>
- <!-- 数据源名称存在空格不能像Oracle一样直接作为beanId -->
- <value>DM DBMS</value>
- </list>
- </property>
- <property name="duplicateKeyCodes">
- <list>
- <value>-6602</value>
- <value>-6625</value>
- </list>
- </property>
- </bean>
-
- </beans>
-
为了能够让spring加载到我们的配置,需要进行对应services的修改
修改文件:resources/META-INF.services下的
com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect
增加自定义达梦的dialect配置
# # 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. # # com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect com.alibaba.nacos.plugin.datasource.impl.dm.dialect.DaMengDatabaseDialect
修改resources/META-INF.services下的com.alibaba.nacos.plugin.datasource.mapper.Mapper文件
将上面自定义达梦相关的Mapper配置进去
# # 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. # com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerby com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoAggrMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoBetaMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.ConfigInfoTagMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.ConfigTagsRelationMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.HistoryConfigInfoMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.GroupCapacityMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.TenantCapacityMapperByDM com.alibaba.nacos.plugin.datasource.impl.dm.TenantInfoMapperByDM
修改datasource配置,配置如下:
- spring.sql.init.platform=dm
-
- ### Count of DB:
- db.num=1
-
- ### Connect URL of DB:
- db.url.0=jdbc:dm://localhost:5236
- db.user.0=SYSDBA
- db.password.0=123456
- db.driver-class-name.0=dm.jdbc.driver.DmDriver
- CREATE TABLE "NOCOS"."USERS"
- (
- "USERNAME" VARCHAR(50) NOT NULL,
- "PASSWORD" VARCHAR(500) NOT NULL,
- "ENABLED" TINYINT NOT NULL
- );
- CREATE TABLE "NOCOS"."TENANT_INFO"
- (
- "ID" BIGINT IDENTITY(1,1) NOT NULL,
- "KP" VARCHAR(128) NOT NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NULL,
- "TENANT_NAME" VARCHAR(128) DEFAULT ''
- NULL,
- "TENANT_DESC" VARCHAR(256) NULL,
- "CREATE_SOURCE" VARCHAR(32) NULL,
- "GMT_CREATE" BIGINT NOT NULL,
- "GMT_MODIFIED" BIGINT NOT NULL
- );
- CREATE TABLE "NOCOS"."TENANT_CAPACITY"
- (
- "ID" BIGINT IDENTITY(1,1) NOT NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NOT NULL,
- "QUOTA" BIGINT DEFAULT 0
- NOT NULL,
- "USAGE" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_SIZE" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_AGGR_COUNT" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_AGGR_SIZE" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_HISTORY_COUNT" BIGINT DEFAULT 0
- NOT NULL,
- "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL
- );
- CREATE TABLE "NOCOS"."ROLES"
- (
- "USERNAME" VARCHAR(50) NOT NULL,
- "ROLE" VARCHAR(50) NOT NULL
- );
- CREATE TABLE "NOCOS"."PERMISSIONS"
- (
- "ROLE" VARCHAR(50) NOT NULL,
- "RESOURCE" VARCHAR(255) NOT NULL,
- "ACTION" VARCHAR(8) NOT NULL
- );
- CREATE TABLE "NOCOS"."HIS_CONFIG_INFO"
- (
- "ID" DECIMAL(20, 0) NOT NULL,
- "NID" BIGINT IDENTITY(1,1) NOT NULL,
- "DATA_ID" VARCHAR(255) NOT NULL,
- "GROUP_ID" VARCHAR(128) NOT NULL,
- "APP_NAME" VARCHAR(128) NULL,
- "CONTENT" CLOB NOT NULL,
- "MD5" VARCHAR(32) NULL,
- "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "SRC_USER" TEXT NULL,
- "SRC_IP" VARCHAR(50) NULL,
- "OP_TYPE" CHAR(10) NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NULL,
- "ENCRYPTED_DATA_KEY" TEXT NOT NULL
- );
- CREATE TABLE "NOCOS"."GROUP_CAPACITY"
- (
- "ID" BIGINT IDENTITY(1,1) NOT NULL,
- "GROUP_ID" VARCHAR(128) DEFAULT ''
- NOT NULL,
- "QUOTA" BIGINT DEFAULT 0
- NOT NULL,
- "USAGE" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_SIZE" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_AGGR_COUNT" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_AGGR_SIZE" BIGINT DEFAULT 0
- NOT NULL,
- "MAX_HISTORY_COUNT" BIGINT DEFAULT 0
- NOT NULL,
- "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL
- );
- CREATE TABLE "NOCOS"."CONFIG_TAGS_RELATION"
- (
- "ID" BIGINT NOT NULL,
- "TAG_NAME" VARCHAR(128) NOT NULL,
- "TAG_TYPE" VARCHAR(64) NULL,
- "DATA_ID" VARCHAR(255) NOT NULL,
- "GROUP_ID" VARCHAR(128) NOT NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NULL,
- "NID" BIGINT IDENTITY(1,1) NOT NULL
- );
- CREATE TABLE "NOCOS"."CONFIG_INFO_TAG"
- (
- "ID" BIGINT IDENTITY(1,1) NOT NULL,
- "DATA_ID" VARCHAR(255) NOT NULL,
- "GROUP_ID" VARCHAR(128) NOT NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NULL,
- "TAG_ID" VARCHAR(128) NOT NULL,
- "APP_NAME" VARCHAR(128) NULL,
- "CONTENT" CLOB NOT NULL,
- "MD5" VARCHAR(32) NULL,
- "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "SRC_USER" TEXT NULL,
- "SRC_IP" VARCHAR(50) NULL
- );
- CREATE TABLE "NOCOS"."CONFIG_INFO_BETA"
- (
- "ID" BIGINT IDENTITY(1,1) NOT NULL,
- "DATA_ID" VARCHAR(255) NOT NULL,
- "GROUP_ID" VARCHAR(128) NOT NULL,
- "APP_NAME" VARCHAR(128) NULL,
- "CONTENT" CLOB NOT NULL,
- "BETA_IPS" VARCHAR(1024) NULL,
- "MD5" VARCHAR(32) NULL,
- "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "SRC_USER" TEXT NULL,
- "SRC_IP" VARCHAR(50) NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NULL,
- "ENCRYPTED_DATA_KEY" TEXT NOT NULL
- );
- CREATE TABLE "NOCOS"."CONFIG_INFO_AGGR"
- (
- "ID" BIGINT IDENTITY(1,1) NOT NULL,
- "DATA_ID" VARCHAR(255) NOT NULL,
- "GROUP_ID" VARCHAR(128) NOT NULL,
- "DATUM_ID" VARCHAR(255) NOT NULL,
- "CONTENT" CLOB NOT NULL,
- "GMT_MODIFIED" TIMESTAMP(0) NOT NULL,
- "APP_NAME" VARCHAR(128) NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NULL
- );
- CREATE TABLE "NOCOS"."CONFIG_INFO"
- (
- "ID" BIGINT IDENTITY(1,1) NOT NULL,
- "DATA_ID" VARCHAR(255) NOT NULL,
- "GROUP_ID" VARCHAR(128) NULL,
- "CONTENT" CLOB NOT NULL,
- "MD5" VARCHAR(32) NULL,
- "GMT_CREATE" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "GMT_MODIFIED" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP()
- NOT NULL,
- "SRC_USER" TEXT NULL,
- "SRC_IP" VARCHAR(50) NULL,
- "APP_NAME" VARCHAR(128) NULL,
- "TENANT_ID" VARCHAR(128) DEFAULT ''
- NULL,
- "C_DESC" VARCHAR(256) NULL,
- "C_USE" VARCHAR(64) NULL,
- "EFFECT" VARCHAR(64) NULL,
- "TYPE" VARCHAR(64) NULL,
- "C_SCHEMA" TEXT NULL,
- "ENCRYPTED_DATA_KEY" TEXT NOT NULL
- );
- ALTER TABLE "NOCOS"."USERS"
- ADD CONSTRAINT PRIMARY KEY ("USERNAME");
-
- ALTER TABLE "NOCOS"."TENANT_INFO"
- ADD CONSTRAINT PRIMARY KEY ("ID");
-
- ALTER TABLE "NOCOS"."TENANT_INFO"
- ADD CONSTRAINT "UK_TENANT_INFO_KPTENANTID" UNIQUE ("KP", "TENANT_ID");
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CONSTRAINT PRIMARY KEY ("ID");
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CONSTRAINT "UK_TENANT_ID" UNIQUE ("TENANT_ID");
-
- ALTER TABLE "NOCOS"."ROLES"
- ADD CONSTRAINT "IDX_USER_ROLE" UNIQUE ("USERNAME", "ROLE");
-
- ALTER TABLE "NOCOS"."PERMISSIONS"
- ADD CONSTRAINT "UK_ROLE_PERMISSION" UNIQUE ("ROLE", "RESOURCE", "ACTION");
-
- ALTER TABLE "NOCOS"."HIS_CONFIG_INFO"
- ADD CONSTRAINT PRIMARY KEY ("NID");
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CONSTRAINT PRIMARY KEY ("ID");
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CONSTRAINT "UK_GROUP_ID" UNIQUE ("GROUP_ID");
-
- ALTER TABLE "NOCOS"."CONFIG_TAGS_RELATION"
- ADD CONSTRAINT PRIMARY KEY ("NID");
-
- ALTER TABLE "NOCOS"."CONFIG_TAGS_RELATION"
- ADD CONSTRAINT "UK_CONFIGTAGRELATION_CONFIGIDTAG" UNIQUE ("ID", "TAG_NAME", "TAG_TYPE");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO_TAG"
- ADD CONSTRAINT PRIMARY KEY ("ID");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO_TAG"
- ADD CONSTRAINT "UK_CONFIGINFOTAG_DATAGROUPTENANTTAG" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID", "TAG_ID");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO_BETA"
- ADD CONSTRAINT PRIMARY KEY ("ID");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO_BETA"
- ADD CONSTRAINT "UK_CONFIGINFOBETA_DATAGROUPTENANT" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO_AGGR"
- ADD CONSTRAINT PRIMARY KEY ("ID");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO_AGGR"
- ADD CONSTRAINT "UK_CONFIGINFOAGGR_DATAGROUPTENANTDATUM" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID", "DATUM_ID");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO"
- ADD CONSTRAINT PRIMARY KEY ("ID");
-
- ALTER TABLE "NOCOS"."CONFIG_INFO"
- ADD CONSTRAINT "UK_CONFIGINFO_DATAGROUPTENANT" UNIQUE ("DATA_ID", "GROUP_ID", "TENANT_ID");
-
- CREATE INDEX "IDX_TENANT_ID"
- ON "NOCOS"."TENANT_INFO" ("TENANT_ID");
-
- COMMENT
- ON TABLE "NOCOS"."TENANT_INFO" IS 'tenant_info';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."ID" IS 'id';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."KP" IS 'kp';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."TENANT_ID" IS 'tenant_id';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."TENANT_NAME" IS 'tenant_name';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."TENANT_DESC" IS 'tenant_desc';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."CREATE_SOURCE" IS 'create_source';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."GMT_CREATE" IS '创建时间';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_INFO"."GMT_MODIFIED" IS '修改时间';
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CHECK ("QUOTA" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CHECK ("MAX_HISTORY_COUNT" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CHECK ("MAX_AGGR_SIZE" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CHECK ("MAX_AGGR_COUNT" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CHECK ("MAX_SIZE" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."TENANT_CAPACITY"
- ADD CHECK ("USAGE" >= 0) ENABLE;
-
- COMMENT
- ON TABLE "NOCOS"."TENANT_CAPACITY" IS '租户容量信息表';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."ID" IS '主键ID';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."TENANT_ID" IS 'Tenant ID';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."QUOTA" IS '配额,0表示使用默认值';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."USAGE" IS '使用量';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_SIZE" IS '单个配置大小上限,单位为字节,0表示使用默认值';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_AGGR_COUNT" IS '聚合子配置最大个数';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_AGGR_SIZE" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."MAX_HISTORY_COUNT" IS '最大变更历史数量';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."GMT_CREATE" IS '创建时间';
-
- COMMENT
- ON COLUMN "NOCOS"."TENANT_CAPACITY"."GMT_MODIFIED" IS '修改时间';
-
- ALTER TABLE "NOCOS"."HIS_CONFIG_INFO"
- ADD CHECK ("ID" >= 0) ENABLE;
-
- CREATE INDEX "IDX_GMT_MODIFIED"
- ON "NOCOS"."HIS_CONFIG_INFO" ("GMT_MODIFIED");
-
- CREATE INDEX "IDX_GMT_CREATE"
- ON "NOCOS"."HIS_CONFIG_INFO" ("GMT_CREATE");
-
- CREATE INDEX "IDX_DID"
- ON "NOCOS"."HIS_CONFIG_INFO" ("DATA_ID");
-
- COMMENT
- ON TABLE "NOCOS"."HIS_CONFIG_INFO" IS '多租户改造';
-
- COMMENT
- ON COLUMN "NOCOS"."HIS_CONFIG_INFO"."APP_NAME" IS 'app_name';
-
- COMMENT
- ON COLUMN "NOCOS"."HIS_CONFIG_INFO"."TENANT_ID" IS '租户字段';
-
- COMMENT
- ON COLUMN "NOCOS"."HIS_CONFIG_INFO"."ENCRYPTED_DATA_KEY" IS '密钥';
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CHECK ("QUOTA" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CHECK ("MAX_HISTORY_COUNT" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CHECK ("MAX_AGGR_SIZE" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CHECK ("MAX_AGGR_COUNT" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CHECK ("MAX_SIZE" >= 0) ENABLE;
-
- ALTER TABLE "NOCOS"."GROUP_CAPACITY"
- ADD CHECK ("USAGE" >= 0) ENABLE;
-
- COMMENT
- ON TABLE "NOCOS"."GROUP_CAPACITY" IS '集群、各Group容量信息表';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."ID" IS '主键ID';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."GROUP_ID" IS 'Group ID,空字符表示整个集群';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."QUOTA" IS '配额,0表示使用默认值';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."USAGE" IS '使用量';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_SIZE" IS '单个配置大小上限,单位为字节,0表示使用默认值';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_AGGR_COUNT" IS '聚合子配置最大个数,,0表示使用默认值';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_AGGR_SIZE" IS '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."MAX_HISTORY_COUNT" IS '最大变更历史数量';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."GMT_CREATE" IS '创建时间';
-
- COMMENT
- ON COLUMN "NOCOS"."GROUP_CAPACITY"."GMT_MODIFIED" IS '修改时间';
-
- COMMENT
- ON TABLE "NOCOS"."CONFIG_TAGS_RELATION" IS 'config_tag_relation';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."ID" IS 'id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."TAG_NAME" IS 'tag_name';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."TAG_TYPE" IS 'tag_type';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."DATA_ID" IS 'data_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."GROUP_ID" IS 'group_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_TAGS_RELATION"."TENANT_ID" IS 'tenant_id';
-
- COMMENT
- ON TABLE "NOCOS"."CONFIG_INFO_TAG" IS 'config_info_tag';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."ID" IS 'id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."DATA_ID" IS 'data_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."GROUP_ID" IS 'group_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."TENANT_ID" IS 'tenant_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."TAG_ID" IS 'tag_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."APP_NAME" IS 'app_name';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."CONTENT" IS 'content';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."MD5" IS 'md5';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."GMT_CREATE" IS '创建时间';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."GMT_MODIFIED" IS '修改时间';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."SRC_USER" IS 'source user';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_TAG"."SRC_IP" IS 'source ip';
-
- COMMENT
- ON TABLE "NOCOS"."CONFIG_INFO_BETA" IS 'config_info_beta';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."ID" IS 'id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."DATA_ID" IS 'data_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."GROUP_ID" IS 'group_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."APP_NAME" IS 'app_name';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."CONTENT" IS 'content';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."BETA_IPS" IS 'betaIps';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."MD5" IS 'md5';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."GMT_CREATE" IS '创建时间';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."GMT_MODIFIED" IS '修改时间';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."SRC_USER" IS 'source user';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."SRC_IP" IS 'source ip';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."TENANT_ID" IS '租户字段';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_BETA"."ENCRYPTED_DATA_KEY" IS '密钥';
-
- COMMENT
- ON TABLE "NOCOS"."CONFIG_INFO_AGGR" IS '增加租户字段';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."ID" IS 'id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."DATA_ID" IS 'data_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."GROUP_ID" IS 'group_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."DATUM_ID" IS 'datum_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."CONTENT" IS '内容';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."GMT_MODIFIED" IS '修改时间';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO_AGGR"."TENANT_ID" IS '租户字段';
-
- COMMENT
- ON TABLE "NOCOS"."CONFIG_INFO" IS 'config_info';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."ID" IS 'id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."DATA_ID" IS 'data_id';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."CONTENT" IS 'content';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."MD5" IS 'md5';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."GMT_CREATE" IS '创建时间';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."GMT_MODIFIED" IS '修改时间';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."SRC_USER" IS 'source user';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."SRC_IP" IS 'source ip';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."TENANT_ID" IS '租户字段';
-
- COMMENT
- ON COLUMN "NOCOS"."CONFIG_INFO"."ENCRYPTED_DATA_KEY" IS '密钥';
-
-
-
- INSERT INTO "NOCOS"."USERS"("USERNAME", "PASSWORD", "ENABLED")
- VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);
-
- INSERT INTO "NOCOS"."ROLES"("USERNAME", "ROLE")
- VALUES ('nacos', 'ROLE_ADMIN');
-
最后在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配置,然后驱动命令运行即可
本次选举的kingbase版本是kingbaseV008R006C008B0014,选的是兼容mysql模式,其他版本以及兼容oracle或者pg模式的kingbase仅供参考,如果说能运行脚本,一般就没多大问题
新增package: com.alibaba.nacos.plugin.datasource.impl.kingbase8.dialect
在该package下面新增类:Kingbase8DatabaseDialect
主要是对limit做了特殊处理
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8.dialect;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.dialect.AbstractDatabaseDialect;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2024/1/2
- */
- public class Kingbase8DatabaseDialect extends AbstractDatabaseDialect {
-
- @Override
- public String getLimitPageSqlWithMark(String sql) {
- return sql + " LIMIT ? OFFSET ? ";
- }
-
- @Override
- public String getLimitPageSql(String sql, int pageNo, int pageSize) {
- return sql + " LIMIT " + pageSize + " OFFSET " + getPagePrevNum(pageNo, pageSize);
- }
-
- @Override
- public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSize){
- return sql + " LIMIT " + pageSize + " OFFSET " + startOffset;
- }
-
- @Override
- public String[] getReturnPrimaryKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
-
- @Override
- public String getType() {
- return KINGBASE8;
- }
- }
然后就是各个Mapper的覆写,因为上面的方言以及做了处理,所以这一块改动不大,具体代码如下:在package:com.alibaba.nacos.plugin.datasource.impl.kingbase8下面新增以下类
ConfigInfoAggrMapperByKingbase8
- /*
- * 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.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoAggrMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoAggrMapperByKingbase8 extends BaseConfigInfoAggrMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigInfoBetaMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoBetaMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoBetaMapperByKingbase8 extends BaseConfigInfoBetaMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigInfoMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoMapperByKingbase8 extends BaseConfigInfoMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigInfoTagMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigInfoTagMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigInfoTagMapperByKingbase8 extends BaseConfigInfoTagMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
ConfigTagsRelationMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseConfigTagsRelationMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class ConfigTagsRelationMapperByKingbase8 extends BaseConfigTagsRelationMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
GroupCapacityMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseGroupCapacityMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class GroupCapacityMapperByKingbase8 extends BaseGroupCapacityMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
HistoryConfigInfoMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class HistoryConfigInfoMapperByKingbase8 extends HistoryConfigInfoMapperByMySql {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
TenantCapacityMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantCapacityMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class TenantCapacityMapperByKingbase8 extends BaseTenantCapacityMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
TenantInfoMapperByKingbase8
- package com.alibaba.nacos.plugin.datasource.impl.kingbase8;
-
- import com.alibaba.nacos.plugin.datasource.constants.PrimaryKeyConstant;
- import com.alibaba.nacos.plugin.datasource.impl.base.BaseTenantInfoMapper;
-
- import static com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant.KINGBASE8;
-
- /**
- * @Description TODO
- * @Author wx
- * @Date 2023/11/23
- */
- public class TenantInfoMapperByKingbase8 extends BaseTenantInfoMapper {
-
- @Override
- public String getDataSource() {
- return KINGBASE8;
- }
-
- @Override
- public String[] getPrimaryKeyGeneratedKeys() {
- return PrimaryKeyConstant.LOWER_RETURN_PRIMARY_KEYS;
- }
- }
为了能够让spring加载到我们的配置,需要进行对应services的修改
修改文件:resources/META-INF.services下的
com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect
增加自定义kingbase8的dialect配置
# # 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. # # com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect com.alibaba.nacos.plugin.datasource.impl.kingbase8.dialect.Kingbase8DatabaseDialect
修改resources/META-INF.services下的com.alibaba.nacos.plugin.datasource.mapper.Mapper文件
将上面自定义kingbase8相关的Mapper配置进去
# # 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. # com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigTagsRelationMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.HistoryConfigInfoMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagsRelationMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.HistoryConfigInfoMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.TenantInfoMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.TenantCapacityMapperByDerby com.alibaba.nacos.plugin.datasource.impl.derby.GroupCapacityMapperByDerby com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoAggrMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoBetaMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigInfoTagMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.ConfigTagsRelationMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.GroupCapacityMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.HistoryConfigInfoMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.TenantCapacityMapperByKingbase8 com.alibaba.nacos.plugin.datasource.impl.kingbase8.TenantInfoMapperByKingbase8
- spring.sql.init.platform=kingbase8
-
- ### Count of DB:
- db.num=1
-
- ### Connect URL of DB:
- db.url.0=jdbc:kingbase8://localhost:54321/xxxx
- db.user.0=xxxx
- db.password.0=123456
- db.driver-class-name.0=com.kingbase8.Driver
- CREATE TABLE "config_info" (
- "id" BIGSERIAL NOT NULL,
- "data_id" character varying(255 char) NOT NULL,
- "group_id" character varying(255 char) NULL,
- "content" text NOT NULL,
- "md5" character varying(32 char) NULL,
- "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "src_user" text NULL,
- "src_ip" character varying(50 char) NULL,
- "app_name" character varying(128 char) NULL,
- "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
- "c_desc" character varying(256 char) NULL,
- "c_use" character varying(64 char) NULL,
- "effect" character varying(64 char) NULL,
- "type" character varying(64 char) NULL,
- "c_schema" text NULL,
- "encrypted_data_key" text NULL,
- CONSTRAINT "PRIMARY_73F26186" PRIMARY KEY (id),
- CONSTRAINT "uk_configinfo_datagrouptenant_C827FEB8" UNIQUE (data_id, group_id, tenant_id)
- );
-
- CREATE TABLE "config_info_aggr" (
- "id" BIGSERIAL NOT NULL,
- "data_id" character varying(255 char) NOT NULL,
- "group_id" character varying(255 char) NOT NULL,
- "datum_id" character varying(255 char) NOT NULL,
- "content" text NOT NULL,
- "gmt_modified" timestamp(0) without time zone NOT NULL,
- "app_name" character varying(128 char) NULL,
- "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
- CONSTRAINT "PRIMARY_F787E5C0" PRIMARY KEY (id),
- CONSTRAINT "uk_configinfoaggr_datagrouptenantdatum_D10078D8" UNIQUE (data_id, group_id, tenant_id, datum_id)
- );
-
-
- CREATE TABLE "config_info_beta" (
- "id" BIGSERIAL NOT NULL,
- "data_id" character varying(255 char) NOT NULL,
- "group_id" character varying(128 char) NOT NULL,
- "app_name" character varying(128 char) NULL,
- "content" text NOT NULL,
- "beta_ips" character varying(1024 char) NULL,
- "md5" character varying(32 char) NULL,
- "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "src_user" text NULL,
- "src_ip" character varying(50 char) NULL,
- "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
- "encrypted_data_key" text NULL,
- CONSTRAINT "PRIMARY_E3F5B61F" PRIMARY KEY (id),
- CONSTRAINT "uk_configinfobeta_datagrouptenant_E4D7C681" UNIQUE (data_id, group_id, tenant_id)
- );
-
- CREATE TABLE "config_info_tag" (
- "id" BIGSERIAL NOT NULL,
- "data_id" character varying(255 char) NOT NULL,
- "group_id" character varying(128 char) NOT NULL,
- "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
- "tag_id" character varying(128 char) NOT NULL,
- "app_name" character varying(128 char) NULL,
- "content" text NOT NULL,
- "md5" character varying(32 char) NULL,
- "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "src_user" text NULL,
- "src_ip" character varying(50 char) NULL,
- CONSTRAINT "PRIMARY_26447CE1" PRIMARY KEY (id),
- CONSTRAINT "uk_configinfotag_datagrouptenanttag_5CBEB0AC" UNIQUE (data_id, group_id, tenant_id, tag_id)
- );
-
- CREATE TABLE "config_tags_relation" (
- "id" bigint NOT NULL,
- "tag_name" character varying(128 char) NOT NULL,
- "tag_type" character varying(64 char) NULL,
- "data_id" character varying(255 char) NOT NULL,
- "group_id" character varying(128 char) NOT NULL,
- "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
- "nid" BIGSERIAL NOT NULL,
- CONSTRAINT "PRIMARY_82226084" PRIMARY KEY (nid),
- CONSTRAINT "uk_configtagrelation_configidtag_25395725" UNIQUE (id, tag_name, tag_type)
- );
- CREATE INDEX idx_tenant_id_4FB846F8 ON config_tags_relation USING btree (tenant_id);
-
- CREATE TABLE "group_capacity" (
- "id" BIGSERIAL NOT NULL,
- "group_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
- "quota" bigint NOT NULL DEFAULT 0,
- "usage" bigint NOT NULL DEFAULT 0,
- "max_size" bigint NOT NULL DEFAULT 0,
- "max_aggr_count" bigint NOT NULL DEFAULT 0,
- "max_aggr_size" bigint NOT NULL DEFAULT 0,
- "max_history_count" bigint NOT NULL DEFAULT 0,
- "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- CONSTRAINT "PRIMARY_D72B7E75" PRIMARY KEY (id),
- CONSTRAINT "uk_group_id_377325F2" UNIQUE (group_id)
- );
-
- CREATE TABLE "his_config_info" (
- "id" numeric NOT NULL,
- "nid" BIGSERIAL NOT NULL,
- "data_id" character varying(255 char) NOT NULL,
- "group_id" character varying(128 char) NOT NULL,
- "app_name" character varying(128 char) NULL,
- "content" text NOT NULL,
- "md5" character varying(32 char) NULL,
- "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "src_user" text NULL,
- "src_ip" character varying(50 char) NULL,
- "op_type" character(10 char) NULL,
- "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
- "encrypted_data_key" text NULL,
- CONSTRAINT "PRIMARY_93A4DC6B" PRIMARY KEY (nid)
- );
- CREATE INDEX idx_did_8DE97C10 ON his_config_info USING btree (data_id);
- CREATE INDEX idx_gmt_create_F3B3E5A1 ON his_config_info USING btree (gmt_create);
- CREATE INDEX idx_gmt_modified_42DBB1BB ON his_config_info USING btree (gmt_modified);
-
- CREATE TABLE "permissions" (
- "role" character varying(50 char) NOT NULL,
- "resource" character varying(255 char) NOT NULL,
- "action" character varying(8 char) NOT NULL,
- CONSTRAINT "uk_role_permission_9C323780" UNIQUE (role, resource, action)
- );
-
- CREATE TABLE "roles" (
- "username" character varying(50 char) NOT NULL,
- "role" character varying(50 char) NOT NULL,
- CONSTRAINT "idx_user_role_314C5701" UNIQUE (username, role)
- );
-
- CREATE TABLE "tenant_capacity" (
- "id" BIGSERIAL NOT NULL,
- "tenant_id" character varying(128 char) NOT NULL DEFAULT NULL::varchar,
- "quota" bigint NOT NULL DEFAULT 0,
- "usage" bigint NOT NULL DEFAULT 0,
- "max_size" bigint NOT NULL DEFAULT 0,
- "max_aggr_count" bigint NOT NULL DEFAULT 0,
- "max_aggr_size" bigint NOT NULL DEFAULT 0,
- "max_history_count" bigint NOT NULL DEFAULT 0,
- "gmt_create" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- "gmt_modified" timestamp(0) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
- CONSTRAINT "PRIMARY_F4CCC2AA" PRIMARY KEY (id),
- CONSTRAINT "uk_tenant_id_22935E1" UNIQUE (tenant_id)
- );
-
- CREATE TABLE "tenant_info" (
- "id" BIGSERIAL NOT NULL,
- "kp" character varying(128 char) NOT NULL,
- "tenant_id" character varying(128 char) NULL DEFAULT NULL::varchar,
- "tenant_name" character varying(128 char) NULL DEFAULT NULL::varchar,
- "tenant_desc" character varying(256 char) NULL,
- "create_source" character varying(32 char) NULL,
- "gmt_create" bigint NOT NULL,
- "gmt_modified" bigint NOT NULL,
- CONSTRAINT "PRIMARY_8B91ED1E" PRIMARY KEY (id),
- CONSTRAINT "uk_tenant_info_kptenantid_195888C1" UNIQUE (kp, tenant_id)
- );
- CREATE INDEX idx_tenant_id_ABB71DBA ON tenant_info USING btree (tenant_id);
-
- CREATE TABLE "users" (
- "username" character varying(50 char) NOT NULL,
- "password" character varying(500 char) NOT NULL,
- "enabled" tinyint NOT NULL,
- CONSTRAINT "PRIMARY_1A6B23BE" PRIMARY KEY (username)
- );
-
- INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', 1);
-
- INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');
-
最后在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配置,然后驱动命令运行即可
介于时间和精力问题,本人没有对其他数据库进行适配,但是架子已经搭好了,如有需要进行其他数据库的适配,主要分以下几个步骤
针对nacos的脚本进行对应数据库的适配修改
脚本主要改造的地方有几点
1.自增
针对不同数据库进行自增适配,或是用数据库支持的默认序列,或是用自定义创建序列进行实现
2.字段类型的适配
不同数据库对于string类型、int类型、date类型有对应的jdbc类型,只需要修改对应类型即可
3.建表语句的主键和索引语句
不同数据库对于指定主键和创建索引可能会有差异
脚本这块关注这几点就可以了
创建自己数据库的Dialect,按照上面dm和kingbase一样,实现AbstractDatabaseDialect
然后对里面的方法如果有需要重写的就进行重写
主要是limit的支持,如果支持AbstractDatabaseDialect里面的写法就不用重写,不支持就需要重写自己的处理逻辑
对应的Mapper里面的方法如果有需要特殊处理的就进行重写,没有就按照dm和kingbase的写法进行默认实现即可
按照dm和kingbase的配置步骤进行spi配置即可
进行对应数据库的datasouce配置即可
我的建议是最好是打完包之后按照nacos的-Dloader.path命令后面指定的目录放驱动就行
无需改源码的pom依赖
打包,放驱动,该配置,运行即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。