nacos版本2.2.0
人大金仓版本8.6.0
一、相关文件
Nacos官方文档-数据源插件
https://nacos.io/zh-cn/docs/v2/plugin/datasource-plugin.html
Nacos2.2.0源码
https://github.com/alibaba/nacos/archive/refs/tags/2.2.0.zip
人大金仓驱动
https://download.csdn.net/download/qq_36802726/88165221
二、Nacos源码修改
1.配置人大金仓依赖
下载源码与驱动。
源码打开后,如果项目依赖下载太慢可以换成阿里的:可以打开
maven
的setting.xml文件,把内容换成以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
引入人大金仓驱动,先用maven 安装kingbase8.8.6.0.jar:
//打开命令行,使用以下命令安装本地jar
mvn install:install-file -Dfile=D:\library\kingbase8.8.6.0.jar -DgroupId=com.kingbase -DartifactId=kingbase8 -Dversion=8.6.0 -Dpackaging=jar
引入依赖,打开项目父pom文件 nacos-all
<!--人大金仓 -->
<dependency>
<groupId>com.kingbase</groupId>
<artifactId>kingbase8</artifactId>
<version>8.6.0</version>
</dependency>
2、源码修改
2.1.找到DataSourceConstant.java,增加kingbase数据常量
public class DataSourceConstant {
public static final String MYSQL = "mysql";
public static final String DERBY = "derby";
public static final String KINGBASE = "kingbase";
}
2.2、新建人大金仓数据源插件
2.2.1、ConfigInfoAggrMapperByKingbase
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import java.util.List;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class ConfigInfoAggrMapperByKingbase extends KingbaseAbstractMapper implements ConfigInfoAggrMapper {
@Override
public String batchRemoveAggr(List<String> datumList) {
final StringBuilder datumString = new StringBuilder();
for (String datum : datumList) {
datumString.append('\'').append(datum).append("',");
}
datumString.deleteCharAt(datumString.length() - 1);
return "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND (tenant_id = ? OR tenant_id IS NULL) AND datum_id IN ("
+ datumString + ")";
}
@Override
public String aggrConfigInfoCount(int size, boolean isIn) {
StringBuilder sql = new StringBuilder(
"SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND (tenant_id = ? OR tenant_id IS NULL) AND datum_id");
if (isIn) {
sql.append(" IN (");
} else {
sql.append(" NOT IN (");
}
for (int i = 0; i < size; i++) {
if (i > 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(')');
return sql.toString();
}
@Override
public String findConfigInfoAggrIsOrdered() {
return "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 = ? OR tenant_id IS NULL) ORDER BY datum_id";
}
@Override
public String findConfigInfoAggrByPageFetchRows(int startRow, int pageSize) {
String sql = "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
+ "group_id= ? AND (tenant_id= ? OR tenant_id IS NULL) ORDER BY datum_id";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findAllAggrGroupByDistinct() {
return "SELECT DISTINCT data_id, group_id, tenant_id FROM config_info_aggr";
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_AGGR;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.2、ConfigInfoBetaMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class ConfigInfoBetaMapperByKingbase extends KingbaseAbstractMapper implements ConfigInfoBetaMapper {
@Override
public String updateConfigInfo4BetaCas() {
return "UPDATE config_info_beta SET content = ?,md5 = ?,beta_ips = ?,src_ip = ?,src_user = ?,gmt_modified = ?,app_name = ? "
+ "WHERE data_id = ? AND group_id = ? AND (tenant_id = ? OR tenant_id IS NULL) AND (md5 = ? or md5 is null or md5 = '')";
}
@Override
public String findAllConfigInfoBetaForDumpAllFetchRows(int startRow, int pageSize) {
return " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
+ " FROM ( SELECT rownum ROW_ID,id FROM config_info_beta WHERE ROW_ID<= " + (startRow + pageSize)
+ " ORDER BY id )" + " g, config_info_beta t WHERE g.id = t.id AND g.ROW_ID >" + startRow;
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_BETA;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.3、ConfigInfoMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class ConfigInfoMapperByKingbase extends KingbaseAbstractMapper implements ConfigInfoMapper {
private static final String DATA_ID = "dataId";
private static final String GROUP = "group";
private static final String APP_NAME = "appName";
private static final String CONTENT = "content";
private static final String TENANT = "tenant";
@Override
public String findConfigMaxId() {
return "SELECT MAX(id) FROM config_info";
}
@Override
public String findAllDataIdAndGroup() {
return "SELECT DISTINCT data_id, group_id FROM config_info";
}
@Override
public String findConfigInfoByAppCountRows() {
return "SELECT count(*) FROM config_info WHERE (tenant_id LIKE ? OR tenant_id IS NULL) AND app_name= ?";
}
@Override
public String findConfigInfoByAppFetchRows(int startRow, int pageSize) {
String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"
+ " WHERE (tenant_id LIKE ? OR tenant_id IS NULL) AND app_name= ?";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String configInfoLikeTenantCount() {
return "SELECT count(*) FROM config_info WHERE (tenant_id LIKE ? OR tenant_id IS NULL)";
}
@Override
public String getTenantIdList(int startRow, int pageSize) {
String sql = "SELECT tenant_id FROM config_info WHERE tenant_id IS NOT NULL GROUP BY tenant_id ";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String getGroupIdList(int startRow, int pageSize) {
String sql = "SELECT group_id FROM config_info WHERE tenant_id IS NULL GROUP BY group_id ";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findAllConfigKey(int startRow, int pageSize) {
String sql = " SELECT id,data_id,group_id,app_name FROM config_info WHERE (tenant_id LIKE ? OR tenant_id IS NULL) ORDER BY id ";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findAllConfigInfoBaseFetchRows(int startRow, int pageSize) {
String sql = "SELECT id,data_id,group_id,content,md5 FROM config_info ORDER BY id ";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findAllConfigInfoFragment(int startRow, int pageSize) {
String sql = "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 ";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findChangeConfig() {
return "SELECT data_id, group_id, tenant_id, app_name, content, gmt_modified,encrypted_data_key "
+ "FROM config_info WHERE gmt_modified >= ? AND gmt_modified <= ?";
}
@Override
public String findChangeConfigCountRows(Map<String, String> params, final Timestamp startTime,
final Timestamp endTime) {
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;
final String sqlCountRows = "SELECT count(*) FROM config_info WHERE ";
String where = " 1=1 ";
if (!StringUtils.isBlank(dataId)) {
where += " AND data_id LIKE ? ";
}
if (!StringUtils.isBlank(group)) {
where += " AND group_id LIKE ? ";
}
if (!StringUtils.isBlank(tenantTmp)) {
where += " AND (tenant_id = ? OR tenant_id IS NULL) ";
}
if (!StringUtils.isBlank(appName)) {
where += " AND app_name = ? ";
}
if (startTime != null) {
where += " AND gmt_modified >=? ";
}
if (endTime != null) {
where += " AND gmt_modified <=? ";
}
return sqlCountRows + where;
}
@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;
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 ? ";
}
if (!StringUtils.isBlank(group)) {
where += " AND group_id LIKE ? ";
}
if (!StringUtils.isBlank(tenantTmp)) {
where += " AND (tenant_id = ? OR tenant_id IS NULL) ";
}
if (!StringUtils.isBlank(appName)) {
where += " AND app_name = ? ";
}
if (startTime != null) {
where += " AND gmt_modified >=? ";
}
if (endTime != null) {
where += " AND gmt_modified <=? ";
}
String sql = sqlFetchRows + where + " AND id > " + lastMaxId + " ORDER BY id ASC";
return buildPaginationSql(sql, 0, pageSize);
}
@Override
public String listGroupKeyMd5ByPageFetchRows(int startRow, int pageSize) {
String sql = "SELECT id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key config_info ORDER BY id ";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findAllConfigInfo4Export(List<Long> ids, Map<String, String> params) {
String tenant = params.get("tenant");
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,src_ip,"
+ "c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
List<Object> paramList = new ArrayList<>();
if (!CollectionUtils.isEmpty(ids)) {
where.append(" id IN (");
for (int i = 0; i < ids.size(); i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
paramList.add(ids.get(i));
}
where.append(") ");
} else {
where.append(" (tenant_id= ? OR tenant_id IS NULL)");
paramList.add(tenantTmp);
if (!StringUtils.isBlank(params.get(DATA_ID))) {
where.append(" AND data_id LIKE ? ");
}
if (StringUtils.isNotBlank(params.get(GROUP))) {
where.append(" AND group_id= ? ");
}
if (StringUtils.isNotBlank(params.get(APP_NAME))) {
where.append(" AND app_name= ? ");
}
}
return sql + where;
}
@Override
public String findConfigInfoBaseLikeCountRows(Map<String, String> params) {
final String sqlCountRows = "SELECT count(*) FROM config_info WHERE ";
String where = " 1=1 AND (tenant_id='' OR tenant_id IS NULL) ";
if (!StringUtils.isBlank(params.get(DATA_ID))) {
where += " AND data_id LIKE ? ";
}
if (!StringUtils.isBlank(params.get(GROUP))) {
where += " AND group_id LIKE ";
}
if (!StringUtils.isBlank(params.get(CONTENT))) {
where += " AND content LIKE ? ";
}
return sqlCountRows + where;
}
@Override
public String findConfigInfoBaseLikeFetchRows(Map<String, String> params, int startRow, int pageSize) {
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
String where = " 1=1 AND (tenant_id='' OR tenant_id IS NULL) ";
if (!StringUtils.isBlank(params.get(DATA_ID))) {
where += " AND data_id LIKE ? ";
}
if (!StringUtils.isBlank(params.get(GROUP))) {
where += " AND group_id LIKE ";
}
if (!StringUtils.isBlank(params.get(CONTENT))) {
where += " AND content LIKE ? ";
}
String sql = sqlFetchRows + where;
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findConfigInfo4PageCountRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
final String sqlCount = "SELECT count(*) FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" ( tenant_id= ? or tenant_id is NULL )");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
}
return sqlCount + where;
}
@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 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= ? or tenant_id is NULL ) ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
}
return buildPaginationSql(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= ? or tenant_id is NULL )";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findConfigInfoLike4PageCountRows(Map<String, String> params) {
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 sqlCountRows = "SELECT count(*) FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" (tenant_id LIKE ? OR tenant_id IS NULL) ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
}
return sqlCountRows + where;
}
@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 ? OR tenant_id IS NULL) ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
}
return buildPaginationSql(sqlFetchRows + where, startRow, pageSize);
}
@Override
public String findAllConfigInfoFetchRows(int startRow, int pageSize) {
String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,md5 "
+ " FROM config_info WHERE (tenant_id LIKE ? OR tenant_id IS NULL) ORDER BY id ";
return buildPaginationSql(sql, startRow, pageSize);
}
@Override
public String findConfigInfosByIds(int idSize) {
StringBuilder sql = new StringBuilder(
"SELECT ID,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE ");
sql.append("id IN (");
for (int i = 0; i < idSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
return sql.toString();
}
@Override
public String removeConfigInfoByIdsAtomic(int size) {
StringBuilder sql = new StringBuilder("DELETE FROM config_info WHERE ");
sql.append("id IN (");
for (int i = 0; i < size; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
return sql.toString();
}
@Override
public String updateConfigInfoAtomicCas() {
return "UPDATE config_info SET "
+ "content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?, app_name=?,c_desc=?,c_use=?,effect=?,type=?,c_schema=? "
+ "WHERE data_id=? AND group_id=? AND (tenant_id=? OR tenant_id IS NULL) AND (md5=? OR md5 IS NULL OR md5='')";
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.4、ConfigInfoTagMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class ConfigInfoTagMapperByKingbase extends KingbaseAbstractMapper implements ConfigInfoTagMapper {
@Override
public String updateConfigInfo4TagCas() {
return "UPDATE config_info_tag SET content = ?, md5 = ?, src_ip = ?,src_user = ?,gmt_modified = ?,app_name = ? "
+ "WHERE data_id = ? AND group_id = ? AND (tenant_id = ? OR tenant_id IS NULL) AND tag_id = ? AND (md5 = "
+ "? OR md5 IS NULL OR md5 = '') ";
}
@Override
public String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize) {
return " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "
+ " FROM ( SELECT id FROM config_info_tag WHERE ROWNUM > " + startRow + " AND ROWNUM <="
+ (startRow + pageSize) + "ORDER BY id " + " ) " + "g, config_info_tag t WHERE g.id = t.id ";
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_TAG;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.5、ConfigInfoTagsRelationMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import java.util.Map;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class ConfigTagsRelationMapperByKingbase extends KingbaseAbstractMapper implements ConfigTagsRelationMapper {
@Override
public String findConfigInfo4PageCountRows(final Map<String, String> params, final int tagSize) {
final String appName = params.get("appName");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlCount = "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id";
where.append(" (a.tenant_id=? OR a.tenant_id IS NULL)");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlCount + where;
}
@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");
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=? OR tenant_id IS NULL)");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sql + where + " AND ROWNUM > " + sql + " AND ROWNUM <= " + (startRow + pageSize);
}
@Override
public String findConfigInfoLike4PageCountRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String content = params.get("content");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlCountRows = "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";
where.append(" a.(tenant_id LIKE ? OR tenant_id IS NULL) ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND a.data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND a.group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND a.app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlCountRows + where;
}
@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");
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 ? OR tenant_id IS NULL) ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND a.data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND a.group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND a.app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlFetchRows + where + " AND ROWNUM > " + startRow + " AND ROWNUM <= " + (startRow + pageSize);
}
@Override
public String getTableName() {
return TableConstant.CONFIG_TAGS_RELATION;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.6、GroupCapacityMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class GroupCapacityMapperByKingbase extends KingbaseAbstractMapper implements GroupCapacityMapper {
@Override
public String insertIntoSelect() {
return "INSERT INTO group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size,gmt_create,"
+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info";
}
@Override
public String insertIntoSelectByWhere() {
return "INSERT INTO group_capacity (group_id, quota,`usage`, `max_size`, max_aggr_count, max_aggr_size, gmt_create,"
+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE group_id=? AND tenant_id = ''";
}
@Override
public String incrementUsageByWhereQuotaEqualZero() {
return "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? AND `usage` < ? AND quota = 0";
}
@Override
public String incrementUsageByWhereQuotaNotEqualZero() {
return "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? AND `usage` < quota AND quota != 0";
}
@Override
public String incrementUsageByWhere() {
return "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ?";
}
@Override
public String decrementUsageByWhere() {
return "UPDATE group_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE group_id = ? AND `usage` > 0";
}
@Override
public String updateUsage() {
return "UPDATE group_capacity SET `usage` = (SELECT count(*) FROM config_info), gmt_modified = ? WHERE group_id = ?";
}
@Override
public String updateUsageByWhere() {
return "UPDATE group_capacity SET `usage` = (SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id = ''),"
+ " gmt_modified = ? WHERE group_id= ?";
}
@Override
public String selectGroupInfoBySize() {
return "SELECT id, group_id FROM group_capacity WHERE id > ? ROWNUM > ?";
}
@Override
public String getTableName() {
return TableConstant.GROUP_CAPACITY;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.7、HistoryConfigInfoMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class HistoryConfigInfoMapperByKingbase extends KingbaseAbstractMapper implements HistoryConfigInfoMapper {
@Override
public String removeConfigHistory() {
return "DELETE FROM his_config_info WHERE gmt_modified < ? AND ROWNUM > ?";
}
@Override
public String findConfigHistoryCountByTime() {
return "SELECT count(*) FROM his_config_info WHERE gmt_modified < ?";
}
@Override
public String findDeletedConfig() {
return "SELECT DISTINCT data_id, group_id, tenant_id FROM his_config_info WHERE op_type = 'D' AND gmt_modified >= ? AND gmt_modified <= ?";
}
@Override
public String findConfigHistoryFetchRows() {
return "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
+ "WHERE data_id = ? AND group_id = ? AND (tenant_id = ? OR tenant_id IS NULL) ORDER BY nid DESC";
}
@Override
public String detailPreviousConfigHistory() {
return "SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,gmt_modified "
+ "FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?) ";
}
@Override
public String getTableName() {
return TableConstant.HIS_CONFIG_INFO;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.8、TenantCapacityMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class TenantCapacityMapperByKingbase extends KingbaseAbstractMapper implements TenantCapacityMapper {
@Override
public String incrementUsageWithDefaultQuotaLimit() {
return "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE "
+ "((tenant_id = ? OR tenant_id IS NULL) OR tenant_id IS NULL) AND `usage` <"
+ " ? AND quota = 0";
}
@Override
public String incrementUsageWithQuotaLimit() {
return "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE "
+ "(tenant_id = ? OR tenant_id IS NULL) AND `usage` < "
+ "quota AND quota != 0";
}
@Override
public String incrementUsage() {
return "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE (tenant_id = ? OR tenant_id IS NULL)";
}
@Override
public String decrementUsage() {
return "UPDATE tenant_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE (tenant_id = ? OR tenant_id IS NULL) AND `usage` > 0";
}
@Override
public String correctUsage() {
return "UPDATE tenant_capacity SET `usage` = (SELECT count(*) FROM config_info WHERE (tenant_id = ? OR tenant_id IS NULL)), "
+ "gmt_modified = ? WHERE (tenant_id = ? OR tenant_id IS NULL)";
}
@Override
public String getCapacityList4CorrectUsage() {
return "SELECT id, tenant_id FROM tenant_capacity WHERE id> AND ROWNUM > ?";
}
@Override
public String insertTenantCapacity() {
return "INSERT INTO tenant_capacity (tenant_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "
+ "gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE tenant_id=? OR tenant_id IS NULL;";
}
@Override
public String getTableName() {
return TableConstant.TENANT_CAPACITY;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.9、TenantInfoMapperByKingbase.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public class TenantInfoMapperByKingbase extends KingbaseAbstractMapper implements TenantInfoMapper {
@Override
public String getTableName() {
return TableConstant.TENANT_INFO;
}
@Override
public String getDataSource() {
return DataSourceConstant.KINGBASE;
}
}
2.2.10、KingbaseAbstractMapper.java
package com.alibaba.nacos.plugin.datasource.impl.kingbase;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import java.util.List;
/**
* The mysql implementation of ConfigInfoAggrMapper.
*
* @author zc
**/
public abstract class KingbaseAbstractMapper extends AbstractMapper {
@Override
public String select(List<String> columns, List<String> where) {
StringBuilder sql = new StringBuilder("SELECT ");
for (int i = 0; i < columns.size(); i++) {
sql.append(columns.get(i));
if (i == columns.size() - 1) {
sql.append(" ");
} else {
sql.append(",");
}
}
sql.append("FROM ");
sql.append(getTableName());
sql.append(" ");
if (where.size() == 0) {
return sql.toString();
}
sql.append("WHERE ");
for (int i = 0; i < where.size(); i++) {
String column = where.get(i);
// 租户列特殊处理 避免前端传空字符串是Oracle查询不到数据
if ("tenant_id".equalsIgnoreCase(column)) {
sql.append("(");
sql.append(column).append(" = ").append("?");
sql.append(" OR ");
sql.append(column).append(" IS NULL ");
sql.append(")");
} else {
sql.append(column).append(" = ").append("?");
}
if (i != where.size() - 1) {
sql.append(" AND ");
}
}
return sql.toString();
}
@Override
public String update(List<String> columns, List<String> where) {
StringBuilder sql = new StringBuilder();
String method = "UPDATE ";
sql.append(method);
sql.append(getTableName()).append(" ").append("SET ");
for (int i = 0; i < columns.size(); i++) {
sql.append(columns.get(i)).append(" = ").append("?");
if (i != columns.size() - 1) {
sql.append(",");
}
}
if (where.size() == 0) {
return sql.toString();
}
sql.append(" WHERE ");
for (int i = 0; i < where.size(); i++) {
String column = where.get(i);
if ("tenant_id".equalsIgnoreCase(column)) {
sql.append("(");
sql.append(column).append(" = ").append("?");
sql.append(" OR ");
sql.append(column).append(" IS NULL ");
sql.append(")");
} else {
sql.append(column).append(" = ").append("?");
}
if (i != where.size() - 1) {
sql.append(" AND ");
}
}
return sql.toString();
}
@Override
public String delete(List<String> params) {
StringBuilder sql = new StringBuilder();
String method = "DELETE ";
sql.append(method).append("FROM ").append(getTableName()).append(" ").append("WHERE ");
for (int i = 0; i < params.size(); i++) {
String column = params.get(i);
if ("tenant_id".equalsIgnoreCase(column)) {
sql.append("(");
sql.append(column).append(" = ").append("?");
sql.append(" OR ");
sql.append(column).append(" IS NULL ");
sql.append(")");
} else {
sql.append(column).append(" = ").append("?");
}
if (i != params.size() - 1) {
sql.append("AND ");
}
}
return sql.toString();
}
@Override
public String count(List<String> where) {
StringBuilder sql = new StringBuilder();
String method = "SELECT ";
sql.append(method);
sql.append("COUNT(*) FROM ");
sql.append(getTableName());
sql.append(" ");
if (null == where || where.size() == 0) {
return sql.toString();
}
sql.append("WHERE ");
for (int i = 0; i < where.size(); i++) {
String column = where.get(i);
if ("tenant_id".equalsIgnoreCase(column)) {
sql.append("(");
sql.append(column).append(" = ").append("?");
sql.append(" OR ");
sql.append(column).append(" IS NULL ");
sql.append(")");
} else {
sql.append(column).append(" = ").append("?");
}
if (i != where.size() - 1) {
sql.append(" AND ");
}
}
return sql.toString();
}
public String buildPaginationSql(String originalSql, int startRow, int pageSize) {
return "SELECT * FROM ( SELECT TMP2.* FROM (SELECT TMP.*, ROWNUM ROW_ID FROM ( " + originalSql
+ " ) TMP) TMP2 WHERE ROWNUM <=" + (startRow + pageSize) + ") WHERE ROW_ID > " + startRow;
}
/**
* Get the name of table.
* @return The name of table.
*/
@Override
public abstract String getTableName();
/**
* Get the datasource name.
* @return The name of datasource.
*/
@Override
public abstract String getDataSource();
}
2.3、plugin/datasource/src/main/resources/META-INF/services 下增加以下数据
#
# 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.kingbase.ConfigInfoAggrMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoBetaMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoTagMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.ConfigInfoTagsRelationMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.GroupCapacityMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.HistoryConfigInfoMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.TenantCapacityMapperByKingbase
com.alibaba.nacos.plugin.datasource.impl.kingbase.TenantInfoMapperByKingbase
2.4、修改配置文件连接数据库
### kingbase:
spring.sql.init.platform=kingbase
db.num=1
db.url.0=jdbc:kingbase8://192.168.0.1:54321/nacos?currentSchema=nacos&allowEncodingChanges=true&clientEncoding=UTF8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
db.user.0=nacos
db.password.0=nacos
db.pool.config.driverClassName=com.kingbase8.Driver
需要注意url的第一个nacos代表数据库名,参数currentSchema后面是数据库的模式名。
2.5、手动增加数据源
不然后面启动项目会报错
Invocation of init method failed; nested exception is ErrCode:500, ErrMsg:Nacos Server did not start because dumpservice bean construction failure :
No DataSource set
在ExternalDataSourceServiceImpl
找到方法public void init() 追加
if(Objects.isNull(jt.getDataSource())){
jt.setDataSource(dataSourceList.get(0));
}
完整方法
@Override
public void init() {
queryTimeout = ConvertUtils.toInt(System.getProperty("QUERYTIMEOUT"), 3);
jt = new JdbcTemplate();
// Set the maximum number of records to prevent memory expansion
jt.setMaxRows(50000);
jt.setQueryTimeout(queryTimeout);
testMasterJT = new JdbcTemplate();
testMasterJT.setQueryTimeout(queryTimeout);
testMasterWritableJT = new JdbcTemplate();
// Prevent the login interface from being too long because the main library is not available
testMasterWritableJT.setQueryTimeout(1);
// Database health check
testJtList = new ArrayList<>();
isHealthList = new ArrayList<>();
tm = new DataSourceTransactionManager();
tjt = new TransactionTemplate(tm);
// Transaction timeout needs to be distinguished from ordinary operations.
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
dataSourceType = DatasourcePlatformUtil.getDatasourcePlatform(defaultDataSourceType);
if (PropertyUtil.isUseExternalDB()) {
try {
reload();
} catch (IOException e) {
FATAL_LOG.error("[ExternalDataSourceService] datasource reload error", e);
throw new RuntimeException(DB_LOAD_ERROR_MSG, e);
}
if (this.dataSourceList.size() > DB_MASTER_SELECT_THRESHOLD) {
ConfigExecutor.scheduleConfigTask(new SelectMasterTask(), 10, 10, TimeUnit.SECONDS);
}
ConfigExecutor.scheduleConfigTask(new CheckDbHealthTask(), 10, 10, TimeUnit.SECONDS);
}
if(Objects.isNull(jt.getDataSource())){
jt.setDataSource(dataSourceList.get(0));
}
}
2.6、配置调试
maven执行 mvn install
如果控制台显示
java: 程序包com.alibaba.nacos.consistency.entity不存在java: 程序包com.alibaba.nacos.consistency.entity不存在
可以执行
然后刷新一下maven在执行 mvn install
成功后进行运行配置
-Dnacos.standalone=true 代表单例运行
这说明项目启动成功
3、人大金仓数据库
CREATE TABLE "config_info" (
"id" bigint AUTO_INCREMENT,
"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)
);
-- "pig_config"."config_info_aggr" definition
-- Drop table
-- DROP TABLE "config_info_aggr";
CREATE TABLE "config_info_aggr" (
"id" bigint AUTO_INCREMENT,
"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)
);
-- "pig_config"."config_info_beta" definition
-- Drop table
-- DROP TABLE "config_info_beta";
CREATE TABLE "config_info_beta" (
"id" bigint AUTO_INCREMENT,
"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)
);
-- "pig_config"."config_info_tag" definition
-- Drop table
-- DROP TABLE "config_info_tag";
CREATE TABLE "config_info_tag" (
"id" bigint AUTO_INCREMENT,
"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)
);
-- "pig_config"."config_tags_relation" definition
-- Drop table
-- DROP TABLE "config_tags_relation";
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" bigint AUTO_INCREMENT,
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);
-- "pig_config"."group_capacity" definition
-- Drop table
-- DROP TABLE "group_capacity";
CREATE TABLE "group_capacity" (
"id" bigint AUTO_INCREMENT,
"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)
);
-- "pig_config"."his_config_info" definition
-- Drop table
-- DROP TABLE "his_config_info";
CREATE TABLE "his_config_info" (
"id" numeric NOT NULL,
"nid" bigint AUTO_INCREMENT,
"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);
-- "pig_config"."permissions" definition
-- Drop table
-- DROP TABLE "permissions";
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)
);
-- "pig_config"."roles" definition
-- Drop table
-- DROP TABLE "roles";
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)
);
-- "pig_config"."tenant_capacity" definition
-- Drop table
-- DROP TABLE "tenant_capacity";
CREATE TABLE "tenant_capacity" (
"id" bigint AUTO_INCREMENT,
"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)
);
-- "pig_config"."tenant_info" definition
-- Drop table
-- DROP TABLE "tenant_info";
CREATE TABLE "tenant_info" (
"id" bigint AUTO_INCREMENT,
"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);
-- "pig_config"."users" definition
-- Drop table
-- DROP TABLE "users";
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 "roles" ("username","role") VALUES
('nacos','ROLE_ADMIN');
INSERT INTO "users" ("username","password","enabled") VALUES
('nacos','$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu',1);
设置参数 ora_input_emptystr_isnull = off,参数意义为输入空字符串时的处理措施。 on 表示将输入的空字符串作为null 值处理。 off 表示不处理。
建表后就设置,因为当数据保存到数据库时,会根据参数ora_input_emptystr_isnull 保存为不同格式,后续的参数修改不影响已存储的数据。
在数据库安装目录下找到kingbase.conf
保存,重启数据库服务即可
//重启数据库指令
//在安装目录/Server/bin/下执行
./sys_ctl restart - D /你的data路径
如:./sys_ctl restart -D /home/kingbase/KingbaseES/V8/data
三、 构建打包
mvn -Prelease-nacos -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true clean install
或者
mvn -Prelease-nacos clean package install -Dmaven.test.skip=true
成功后在distribution的target下生成两个包
nacos-server-2.2.0.tar.gz 是linux环境的
nacos-server-2.2.0.zip 是windows环境的
1.修改后的源码
https://download.csdn.net/download/qq_36802726/88180716
2.生成的程序包
https://download.csdn.net/download/qq_36802726/88180751
使用时只需要把application.properties里面的数据库信息修改一下就可以直接运行