Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #8312]Merge sql. #9385

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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 @@ -57,31 +38,20 @@ public String batchRemoveAggr(List<String> 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=? AND datum_id IN ("
return "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id IN ("
+ 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) {
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 = ? AND datum_id");
if (isIn) {
sql.append(" IN (");
} else {
sql.append(" NOT IN (");
}
for (int i = 0, size = datumIds.size(); i < size; i++) {
for (int i = 0; i < size; i++) {
if (i > 0) {
sql.append(", ");
}
Expand All @@ -97,21 +67,10 @@ 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 = ?";
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
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,35 +27,12 @@
* @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=?";
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
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 = "dataId";

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(Map<String, String> params, final Timest
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,12 +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,md5,type,encrypted_data_key FROM config_info "
+ "WHERE data_id=? AND group_id=? AND tenant_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,30 +27,12 @@
* @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=?";
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
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 data_id = ? AND group_id = ? AND tenant_id = ?";
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