Skip to content

Commit

Permalink
[ISSUE alibaba#8312]Merge sql.
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Gamer-01 committed Oct 24, 2022
1 parent 94f59a9 commit 5fc3ca2
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 727 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ server.error.include-message=ALWAYS

#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
# spring.datasource.platform=mysql
spring.datasource.platform=mysql

### Count of DB:
# db.num=1
db.num=1

### Connect URL of DB:
# db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
# db.user.0=nacos
# db.password.0=nacos
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=huangyixuan

#*************** Naming Module Related Configurations ***************#
### Data dispatch task execution period in milliseconds:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;

import java.util.List;
Expand All @@ -28,27 +29,7 @@
* @author hyx
**/

public class ConfigInfoAggrMapperByDerby implements ConfigInfoAggrMapper {

@Override
public String select() {
return "SELECT content FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ?";
}

@Override
public String insert() {
return "INSERT INTO config_info_aggr(data_id, group_id, tenant_id, datum_id, app_name, content, gmt_modified) VALUES(?,?,?,?,?,?,?)";
}

@Override
public String update() {
return "UPDATE config_info_aggr SET content = ? , gmt_modified = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ?";
}

@Override
public String removeAggrConfigInfo() {
return "DELETE FROM config_info_aggr WHERE data_id=? AND group_id=? AND tenant_id=?";
}
public class ConfigInfoAggrMapperByDerby extends AbstractMapper implements ConfigInfoAggrMapper {

@Override
public String batchRemoveAggr(List<String> datumList) {
Expand All @@ -61,17 +42,6 @@ public String batchRemoveAggr(List<String> datumList) {
+ datumString.toString() + ")";
}

@Override
public String removeSingleAggrConfigInfo() {
return "DELETE FROM config_info_aggr WHERE data_id=? AND group_id=? AND tenant_id=? AND datum_id=?";
}

@Override
public String replaceAggr() {
return "INSERT INTO config_info_aggr(data_id, group_id, tenant_id, datum_id, app_name, "
+ "content, gmt_modified) VALUES(?,?,?,?,?,?,?) ";
}

@Override
public String aggrConfigInfoCount(List<String> datumIds, boolean isIn) {
StringBuilder sql = new StringBuilder(
Expand All @@ -97,23 +67,12 @@ public String aggrConfigInfoCount() {
return " SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String findSingleConfigInfoAggr() {
return "SELECT id,data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id=? "
+ "AND group_id=? AND tenant_id=? AND datum_id=?";
}

@Override
public String findConfigInfoAggr() {
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=? ORDER BY datum_id";
}

@Override
public String findConfigInfoAggrByPageCountRows() {
return "SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String findConfigInfoAggrByPageFetchRows(int startRow, int pageSize) {
return "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id=? AND "
Expand All @@ -125,11 +84,6 @@ public String findAllAggrGroup() {
return "SELECT DISTINCT data_id, group_id, tenant_id FROM config_info_aggr";
}

@Override
public String findDatumIdByContent() {
return "SELECT datum_id FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND content = ? ";
}

@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_AGGR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper;

/**
Expand All @@ -26,37 +27,14 @@
* @author hyx
**/

public class ConfigInfoBetaMapperByDerby implements ConfigInfoBetaMapper {

@Override
public String addConfigInfo4Beta() {
return "INSERT INTO config_info_beta(data_id,group_id,tenant_id,app_name,content,md5,beta_ips,src_ip,"
+ "src_user,gmt_create,gmt_modified,encrypted_data_key) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
}

@Override
public String updateConfigInfo4Beta() {
return "UPDATE config_info_beta SET content=?,md5=?,beta_ips=?,src_ip=?,src_user=?,gmt_modified=?,app_name=?,encrypted_data_key=? "
+ "WHERE data_id=? AND group_id=? AND tenant_id=?";
}
public class ConfigInfoBetaMapperByDerby extends AbstractMapper 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=? AND (md5=? OR md5 IS NULL OR md5='')";
}

@Override
public String removeConfigInfo4Beta() {
return "DELETE FROM config_info_beta WHERE data_id=? AND group_id=? AND tenant_id=?";
}

@Override
public String findConfigInfo4Beta() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content,beta_ips,encrypted_data_key FROM config_info_beta "
+ "WHERE data_id=? AND group_id=? AND tenant_id=?";
}

@Override
public String count() {
return "SELECT COUNT(*) FROM config_info_beta";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;

import java.sql.Timestamp;
Expand All @@ -32,7 +33,7 @@
* @author hyx
**/

public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
public class ConfigInfoMapperByDerby extends AbstractMapper implements ConfigInfoMapper {

private static final String DATA_ID = "data_id";

Expand All @@ -44,11 +45,6 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {

private static final String TENANT = "tenant";

@Override
public String updateMd5() {
return "UPDATE config_info SET md5 = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND gmt_modified = ?";
}

@Override
public String findConfigMaxId() {
return "SELECT max(id) FROM config_info";
Expand All @@ -59,22 +55,6 @@ public String findAllDataIdAndGroup() {
return "SELECT DISTINCT data_id, group_id FROM config_info";
}

@Override
public String findConfigInfoApp() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id = ? "
+ "AND group_id = ? AND tenant_id = ? AND app_name = ?";
}

@Override
public String findConfigInfoBase() {
return "SELECT id,data_id,group_id,content FROM config_info WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String findConfigInfoById() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE id = ?";
}

@Override
public String findConfigInfoByDataIdFetchRows(int startRow, int pageSize) {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id = ? AND "
Expand Down Expand Up @@ -224,53 +204,12 @@ public String findChangeConfigFetchRows(
return sqlFetchRows + where + " OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY";
}

@Override
public String addConfigInfoAtomic() {
return "INSERT INTO config_info(id, data_id, group_id, tenant_id, app_name, content, md5, src_ip, src_user, gmt_create,"
+ "gmt_modified, c_desc, c_use, effect, type, c_schema,encrypted_data_key) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
}

@Override
public String removeConfigInfoAtomic() {
return "DELETE FROM config_info WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String updateConfigInfoAtomic() {
return "UPDATE config_info SET content = ?, md5 = ?, src_ip = ?,src_user = ?,gmt_modified = ?,app_name = ?,"
+ "c_desc = ?,c_use = ?,effect = ?,type = ?,c_schema = ?,encrypted_data_key = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String findConfigAdvanceInfo() {
return "SELECT gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,type,c_schema FROM config_info "
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String findConfigAllInfo() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_create,"
+ "gmt_modified,src_user,src_ip,c_desc,c_use,effect,type,c_schema,encrypted_data_key FROM config_info "
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String listGroupKeyMd5ByPageFetchRows() {
return " SELECT t.id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified "
+ "FROM ( SELECT id FROM config_info ORDER BY id OFFSET ? ROWS FETCH NEXT ? ROWS ONLY ) g, config_info t WHERE g.id = t.id";
}

@Override
public String queryConfigInfo() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content,type,gmt_modified,md5 "
+ "FROM config_info WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

@Override
public String queryConfigInfoByNamespace() {
return "SELECT data_id,group_id,tenant_id,app_name,type FROM config_info WHERE tenant_id = ?";
}

@Override
public String findAllConfigInfo4Export(List<Long> ids, Map<String, String> params) {
String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,"
Expand Down Expand Up @@ -627,11 +566,6 @@ public String findConfigInfosByIds(int idSize) {
return sql.toString();
}

@Override
public String findConfigInfoByDataId2Group2Tenant() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE id=?";
}

@Override
public String removeConfigInfoByIdsAtomic(int size) {
StringBuilder sql = new StringBuilder("DELETE FROM config_info WHERE ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;

/**
Expand All @@ -26,32 +27,14 @@
* @author hyx
**/

public class ConfigInfoTagMapperByDerby implements ConfigInfoTagMapper {

@Override
public String addConfigInfo4Tag() {
return "INSERT INTO config_info_tag(data_id,group_id,tenant_id,tag_id,app_name,content,md5,src_ip,src_user,"
+ "gmt_create,gmt_modified) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
}

@Override
public String updateConfigInfo4Tag() {
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=? AND tag_id=?";
}
public class ConfigInfoTagMapperByDerby extends AbstractMapper 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=? AND tag_id=? AND (md5=? OR md5 IS NULL OR md5='')";
}

@Override
public String findConfigInfo4Tag() {
return "SELECT id,data_id,group_id,tenant_id,tag_id,app_name,content FROM config_info_tag WHERE "
+ "data_id=? AND group_id=? AND tenant_id=? AND tag_id=?";
}

@Override
public String configInfoTagCount() {
return " SELECT count(*) FROM config_info_tag ";
Expand All @@ -69,11 +52,6 @@ public String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize
+ " g, config_info_tag t WHERE g.id = t.id ";
}

@Override
public String removeConfigInfoTag() {
return "DELETE FROM config_info_tag WHERE data_id=? AND group_id=? AND tenant_id=? AND tag_id=?";
}

@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_TAG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;

import java.util.Map;
Expand All @@ -29,7 +30,7 @@
* @author hyx
**/

public class ConfigInfoTagsRelationMapperByDerby implements ConfigTagsRelationMapper {
public class ConfigInfoTagsRelationMapperByDerby extends AbstractMapper implements ConfigTagsRelationMapper {

@Override
public String findConfigInfoAdvanceInfo(Map<String, String> params, int tagSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;

/**
Expand All @@ -26,7 +27,7 @@
* @author hyx
**/

public class HistoryConfigInfoMapperByDerby implements HistoryConfigInfoMapper {
public class HistoryConfigInfoMapperByDerby extends AbstractMapper implements HistoryConfigInfoMapper {

@Override
public String removeConfigHistory() {
Expand All @@ -45,12 +46,6 @@ public String findDeletedConfig() {
+ "gmt_modified >=? AND gmt_modified <= ?";
}

@Override
public String insertConfigHistoryAtomic() {
return "INSERT INTO his_config_info (id,data_id,group_id,tenant_id,app_name,content,md5,"
+ "src_ip,src_user,gmt_modified,op_type,encrypted_data_key) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
}

@Override
public String findConfigHistoryCountRows() {
return "SELECT count(*) FROM his_config_info WHERE gmt_modified < ?";
Expand All @@ -63,12 +58,6 @@ public String findConfigHistoryFetchRows(int startRow, int pageSize) {
+ "ORDER BY nid DESC" + " OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY";
}

@Override
public String detailConfigHistory() {
return "SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,gmt_modified,encrypted_data_key "
+ "FROM his_config_info WHERE nid = ?";
}

@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 "
Expand Down
Loading

0 comments on commit 5fc3ca2

Please sign in to comment.