From 5fc3ca2bc9575eccb4f276933419e8eb8bd3e3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=BF=E5=90=8D=E8=92=9F=E8=92=BB?= <843497509@qq.com> Date: Mon, 24 Oct 2022 19:57:05 +0800 Subject: [PATCH] [ISSUE #8312]Merge sql. --- .../EmbeddedStoragePersistServiceImpl.java | 90 +++++++----- .../ExternalStoragePersistServiceImpl.java | 91 +++++++----- .../src/main/resources/application.properties | 10 +- .../derby/ConfigInfoAggrMapperByDerby.java | 50 +------ .../derby/ConfigInfoBetaMapperByDerby.java | 26 +--- .../impl/derby/ConfigInfoMapperByDerby.java | 70 +--------- .../derby/ConfigInfoTagMapperByDerby.java | 26 +--- .../ConfigInfoTagsRelationMapperByDerby.java | 3 +- .../derby/HistoryConfigInfoMapperByDerby.java | 15 +- .../mysql/ConfigInfoAggrMapperByMySql.java | 50 +------ .../mysql/ConfigInfoBetaMapperByMySql.java | 25 +--- .../impl/mysql/ConfigInfoMapperByMySql.java | 72 +--------- .../mysql/ConfigInfoTagMapperByMySql.java | 26 +--- .../ConfigTagsRelationMapperByMySql.java | 3 +- .../mysql/HistoryConfigInfoMapperByMySql.java | 15 +- .../datasource/mapper/AbstractMapper.java | 132 ++++++++++++++++++ .../mapper/ConfigInfoAggrMapper.java | 84 ----------- .../mapper/ConfigInfoBetaMapper.java | 39 ------ .../datasource/mapper/ConfigInfoMapper.java | 116 --------------- .../mapper/ConfigInfoTagMapper.java | 38 ----- .../mapper/HistoryConfigInfoMapper.java | 20 --- .../plugin/datasource/mapper/Mapper.java | 32 +++++ 22 files changed, 306 insertions(+), 727 deletions(-) create mode 100644 plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/AbstractMapper.java diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java index 584dc4c69ce..8295357a5e2 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java @@ -133,7 +133,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService { private MapperManager mapperManager; - private String dataSource; + private final String dataSource; private static final String DATASOURCE_PLATFORM_PROPERTY = "spring.datasource.platform"; @@ -257,7 +257,8 @@ public void addConfigInfo4Beta(ConfigInfo configInfo, String betaIps, String src try { String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE); ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_BETA).get(); - final String sql = configInfoBetaMapper.addConfigInfo4Beta(); + final String sql = configInfoBetaMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "app_name", "content", "md5", "beta_ips", "src_ip", + "src_user,gmt_create", "gmt_modified", "encrypted_data_key")); final Object[] args = new Object[] {configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp, configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, time, encryptedDataKey}; @@ -283,7 +284,8 @@ public void addConfigInfo4Tag(ConfigInfo configInfo, String tag, String srcIp, S String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE); ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - final String sql = configInfoTagMapper.addConfigInfo4Tag(); + final String sql = configInfoTagMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "tag_id", "app_name", + "content", "md5", "src_ip", "src_user", "gmt_create", "gmt_modified")); final Object[] args = new Object[] {configInfo.getDataId(), configInfo.getGroup(), tenantTmp, tagTmp, appNameTmp, configInfo.getContent(), md5, srcIp, srcUser, time, time}; @@ -384,7 +386,8 @@ public void updateConfigInfo4Beta(ConfigInfo configInfo, String betaIps, String try { String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE); ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_BETA).get(); - final String sql = configInfoBetaMapper.updateConfigInfo4Beta(); + final String sql = configInfoBetaMapper.update(Arrays.asList("content", "md5", "beta_ips", "src_ip", "src_user", "gmt_modified", "app_name", "encrypted_data_key"), + Arrays.asList("data_id", "group_id", "tenant_id")); final Object[] args = new Object[] {configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, appNameTmp, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp}; @@ -436,7 +439,8 @@ public void updateConfigInfo4Tag(ConfigInfo configInfo, String tag, String srcIp String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE); ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - final String sql = configInfoTagMapper.updateConfigInfo4Tag(); + final String sql = configInfoTagMapper.update(Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name"), + Arrays.asList("data_id", "group_id", "tenant_id", "tag_id")); final Object[] args = new Object[] {configInfo.getContent(), md5, srcIp, srcUser, time, appNameTmp, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, tagTmp}; @@ -522,8 +526,7 @@ public void updateMd5(String dataId, String group, String tenant, String md5, Ti String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - - final String sql = configInfoMapper.updateMd5(); + final String sql = configInfoMapper.update(Arrays.asList("md5"), Arrays.asList("data_id", "group_id", "tenant_id", "gmt_modified")); final Object[] args = new Object[] {md5, dataId, group, tenantTmp, lastTime}; EmbeddedStorageContextUtils.addSqlContext(sql, args); @@ -648,7 +651,7 @@ public void removeConfigInfo4Beta(final String dataId, final String group, final if (configInfo != null) { try { ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_BETA).get(); - final String sql = configInfoBetaMapper.removeConfigInfo4Beta(); + final String sql = configInfoBetaMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id")); final Object[] args = new Object[] {dataId, group, tenantTmp}; EmbeddedStorageContextUtils.onDeleteConfigBetaInfo(tenantTmp, group, dataId, @@ -675,9 +678,9 @@ public boolean addAggrConfigInfo(final String dataId, final String group, String final Timestamp now = new Timestamp(System.currentTimeMillis()); ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - final String select = configInfoAggrMapper.select(); - final String insert = configInfoAggrMapper.insert(); - final String update = configInfoAggrMapper.update(); + final String select = configInfoAggrMapper.select(Collections.singletonList("content"), Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); + final String insert = configInfoAggrMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified")); + final String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified"), Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); String dbContent = databaseOperate.queryOne(select, new Object[] {dataId, group, tenantTmp, datumId}, String.class); @@ -707,7 +710,7 @@ public void removeSingleAggrConfigInfo(final String dataId, final String group, final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - final String sql = configInfoAggrMapper.removeSingleAggrConfigInfo(); + final String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); final Object[] args = new Object[] {dataId, group, tenantTmp, datumId}; EmbeddedStorageContextUtils.addSqlContext(sql, args); @@ -726,7 +729,7 @@ public void removeAggrConfigInfo(final String dataId, final String group, final final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - final String sql = configInfoAggrMapper.removeAggrConfigInfo(); + final String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id")); final Object[] args = new Object[] {dataId, group, tenantTmp}; EmbeddedStorageContextUtils.addSqlContext(sql, args); @@ -822,7 +825,7 @@ public boolean replaceAggr(final String dataId, final String group, final String String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - final String sql = configInfoAggrMapper.replaceAggr(); + final String sql = configInfoAggrMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified")); for (Entry datumEntry : datumMap.entrySet()) { final Object[] args = new Object[] {dataId, group, tenantTmp, datumEntry.getKey(), appNameTmp, datumEntry.getValue(), new Timestamp(System.currentTimeMillis())}; @@ -852,7 +855,8 @@ public List findAllDataIdAndGroup() { public ConfigInfoBetaWrapper findConfigInfo4Beta(final String dataId, final String group, final String tenant) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant. CONFIG_INFO_BETA).get(); - final String sql = configInfoBetaMapper.findConfigInfo4Beta(); + final String sql = configInfoBetaMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "beta_ips", "encrypted_data_key"), + Arrays.asList("data_id", "group_id", "tenant_id")); return databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp}, CONFIG_INFO_BETA_WRAPPER_ROW_MAPPER); @@ -865,7 +869,8 @@ public ConfigInfoTagWrapper findConfigInfo4Tag(final String dataId, final String String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim(); ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - final String sql = configInfoTagMapper.findConfigInfo4Tag(); + final String sql = configInfoTagMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "tag_id", "app_name", "content"), + Arrays.asList("data_id", "group_id", "tenant_id", "tag_id")); return databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp, tagTmp}, CONFIG_INFO_TAG_WRAPPER_ROW_MAPPER); @@ -876,7 +881,8 @@ public ConfigInfo findConfigInfoApp(final String dataId, final String group, fin final String appName) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.findConfigInfoApp(); + final String sql = configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content"), + Arrays.asList("data_id", "group_id", "tenant_id", "app_name")); return databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp, appName}, CONFIG_INFO_ROW_MAPPER); @@ -915,7 +921,8 @@ public ConfigInfo findConfigInfoAdvanceInfo(final String dataId, final String gr @Override public ConfigInfoBase findConfigInfoBase(final String dataId, final String group) { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.findConfigInfoBase(); + final String sql = configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "content"), + Arrays.asList("data_id", "group_id", "tenant_id")); return databaseOperate.queryOne(sql, new Object[] {dataId, group, StringUtils.EMPTY}, CONFIG_INFO_BASE_ROW_MAPPER); @@ -924,7 +931,8 @@ public ConfigInfoBase findConfigInfoBase(final String dataId, final String group @Override public ConfigInfo findConfigInfo(long id) { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.findConfigInfoById(); + final String sql = configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content"), + Collections.singletonList("id")); return databaseOperate.queryOne(sql, new Object[] {id}, CONFIG_INFO_ROW_MAPPER); } @@ -932,7 +940,8 @@ public ConfigInfo findConfigInfo(long id) { public ConfigInfoWrapper findConfigInfo(final String dataId, final String group, final String tenant) { final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.findConfigInfoByDataId2Group2Tenant(); + final String sql = configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content"), + Collections.singletonList("id")); final Object[] args = new Object[] {dataId, group, tenantTmp}; return databaseOperate.queryOne(sql, args, CONFIG_INFO_WRAPPER_ROW_MAPPER); @@ -1660,7 +1669,8 @@ public Page findConfigInfoBaseLike(final int pageNo, final int p public ConfigInfoAggr findSingleConfigInfoAggr(String dataId, String group, String tenant, String datumId) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - String sql = configInfoAggrMapper.findSingleConfigInfoAggr(); + String sql = configInfoAggrMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "datum_id", "app_name", "content"), + Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); return databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp, datumId}, CONFIG_INFO_AGGR_ROW_MAPPER); @@ -1683,7 +1693,7 @@ public Page findConfigInfoAggrByPage(String dataId, String group String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); final int startRow = (pageNo - 1) * pageSize; - String sqlCountRows = configInfoAggrMapper.findConfigInfoAggrByPageCountRows(); + String sqlCountRows = configInfoAggrMapper.select(Arrays.asList("count(*)"), Arrays.asList("data_id", "group_id", "tenant_id")); String sqlFetchRows = configInfoAggrMapper.findConfigInfoAggrByPageFetchRows(startRow, pageSize); PaginationHelper helper = createPaginationHelper(); @@ -1799,7 +1809,8 @@ public List findAllAggrGroup() { @Override public List findDatumIdByContent(String dataId, String groupId, String content) { ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - String sql = configInfoAggrMapper.findDatumIdByContent(); + String sql = configInfoAggrMapper.select( + Collections.singletonList("datum_id"), Arrays.asList("data_id", "group_id", "content")); return databaseOperate.queryMany(sql, new Object[] {dataId, groupId, content}, String.class); } @@ -1878,7 +1889,8 @@ public long addConfigInfoAtomic(final long id, final String srcIp, final String final String encryptedDataKey = configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey(); ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.addConfigInfoAtomic(); + final String sql = configInfoMapper.insert(Arrays.asList("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")); final Object[] args = new Object[] {id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time, time, desc, use, effect, type, schema, encryptedDataKey}; @@ -1931,7 +1943,7 @@ public void removeConfigInfoAtomic(final String dataId, final String group, fina final String srcUser) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.removeConfigInfoAtomic(); + final String sql = configInfoMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id")); final Object[] args = new Object[] {dataId, group, tenantTmp}; EmbeddedStorageContextUtils.addSqlContext(sql, args); @@ -1959,7 +1971,7 @@ public void removeConfigInfoTag(final String dataId, final String group, final S String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag; ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - final String sql = configInfoTagMapper.removeConfigInfoTag(); + final String sql = configInfoTagMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "tag_id")); final Object[] args = new Object[] {dataId, group, tenantTmp, tagTmp}; EmbeddedStorageContextUtils.onDeleteConfigTagInfo(tenantTmp, group, dataId, tagTmp, srcIp); @@ -1988,7 +2000,8 @@ public void updateConfigInfoAtomic(final ConfigInfo configInfo, final String src configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey(); ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.updateConfigInfoAtomic(); + final String sql = configInfoMapper.update(Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name", "c_desc", "c_use", "effect", "type", + "c_schema", "encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id")); final Object[] args = new Object[] {configInfo.getContent(), md5Tmp, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp}; @@ -2009,7 +2022,8 @@ private void updateConfigInfoAtomicCas(final ConfigInfo configInfo, final String final String schema = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("schema"); ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.updateConfigInfoAtomic(); + final String sql = configInfoMapper.update(Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name", "c_desc", "c_use", "effect", "type", + "c_schema", "encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id")); final Object[] args = new Object[] {configInfo.getContent(), md5Tmp, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, @@ -2039,7 +2053,8 @@ public ConfigAdvanceInfo findConfigAdvanceInfo(final String dataId, final String List configTagList = this.selectTagByConfig(dataId, group, tenant); ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - ConfigAdvanceInfo configAdvance = databaseOperate.queryOne(configInfoMapper.findConfigAdvanceInfo(), + ConfigAdvanceInfo configAdvance = databaseOperate.queryOne(configInfoMapper.select(Arrays.asList("gmt_create", "gmt_modified", "src_user", "src_ip", "c_desc", "c_use", "effect", "type", "c_schema"), + Arrays.asList("data_id", "group_id", "tenant_id")), new Object[] {dataId, group, tenantTmp}, CONFIG_ADVANCE_INFO_ROW_MAPPER); if (CollectionUtils.isNotEmpty(configTagList)) { @@ -2061,7 +2076,9 @@ public ConfigAllInfo findConfigAllInfo(final String dataId, final String group, final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.findConfigAllInfo(); + final String sql = configInfoMapper.select(Arrays.asList("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"), + Arrays.asList("data_id", "group_id", "tenant_id")); List configTagList = selectTagByConfig(dataId, group, tenant); @@ -2092,7 +2109,8 @@ public void insertConfigHistoryAtomic(long configHistoryId, ConfigInfo configInf : configInfo.getEncryptedDataKey(); HistoryConfigInfoMapper historyConfigInfoMapper = (HistoryConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.HIS_CONFIG_INFO).get(); - final String sql = historyConfigInfoMapper.insertConfigHistoryAtomic(); + final String sql = historyConfigInfoMapper.insert(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", + "coutent", "md5", "src_ip", "src_user", "gmt_modified", "op_type", "encrypted_data_key")); final Object[] args = new Object[] {configHistoryId, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time, ops, encryptedDataKey}; @@ -2150,7 +2168,8 @@ public void updateConfigSubAtomic(final String dataId, final String group, final @Override public ConfigHistoryInfo detailConfigHistory(Long nid) { HistoryConfigInfoMapper historyConfigInfoMapper = (HistoryConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.HIS_CONFIG_INFO).get(); - String sqlFetchRows = historyConfigInfoMapper.detailConfigHistory(); + String sqlFetchRows = historyConfigInfoMapper.select(Arrays.asList("nid", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_user", "src_ip", "op_type", "gmt_create", + "encrypted_data_key"), Collections.singletonList("nid")); return databaseOperate.queryOne(sqlFetchRows, new Object[] {nid}, HISTORY_DETAIL_ROW_MAPPER); } @@ -2298,7 +2317,8 @@ public String generateLikeArgument(String s) { public ConfigInfoWrapper queryConfigInfo(final String dataId, final String group, final String tenant) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.queryConfigInfo(); + final String sql = configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "type", "gmt_modified", "md5", "encrypted_data_key"), + Arrays.asList("data_id", "group_id", "tenant_id")); return databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp}, CONFIG_INFO_WRAPPER_ROW_MAPPER); } @@ -2503,7 +2523,9 @@ public List queryConfigInfoByNamespace(String tenantId) { throw new IllegalArgumentException("tenantId can not be null"); } String tenantTmp = StringUtils.isBlank(tenantId) ? StringUtils.EMPTY : tenantId; - final String sql = "SELECT data_id,group_id,tenant_id,app_name,type FROM config_info WHERE tenant_id=?"; + ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); + final String sql = configInfoMapper.select(Arrays.asList("data_id", "group_id", "tenant_id", "app_name", "type"), + Collections.singletonList("tenant_id")); return databaseOperate.queryMany(sql, new Object[] {tenantTmp}, CONFIG_INFO_WRAPPER_ROW_MAPPER); } } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java index 7c684234824..c059acc6770 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java @@ -231,7 +231,8 @@ public void addConfigInfo4Beta(ConfigInfo configInfo, String betaIps, String src : configInfo.getEncryptedDataKey(); try { ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_BETA).get(); - jt.update(configInfoBetaMapper.addConfigInfo4Beta(), + jt.update(configInfoBetaMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "app_name", "content", "md5", "beta_ips", "src_ip", + "src_user,gmt_create", "gmt_modified", "encrypted_data_key")), configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp, configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, time, encryptedDataKey); } catch (CannotGetJdbcConnectionException e) { @@ -250,7 +251,8 @@ public void addConfigInfo4Tag(ConfigInfo configInfo, String tag, String srcIp, S try { ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - jt.update(configInfoTagMapper.addConfigInfo4Tag(), configInfo.getDataId(), + jt.update(configInfoTagMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "tag_id", "app_name", + "content", "md5", "src_ip", "src_user", "gmt_create", "gmt_modified")), configInfo.getDataId(), configInfo.getGroup(), tenantTmp, tagTmp, appNameTmp, configInfo.getContent(), md5, srcIp, srcUser, time, time); } catch (CannotGetJdbcConnectionException e) { @@ -336,7 +338,8 @@ public void updateConfigInfo4Beta(ConfigInfo configInfo, String betaIps, String : configInfo.getEncryptedDataKey(); try { ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_BETA).get(); - jt.update(configInfoBetaMapper.updateConfigInfo4Beta(), configInfo.getContent(), md5, betaIps, srcIp, srcUser, + jt.update(configInfoBetaMapper.update(Arrays.asList("content", "md5", "beta_ips", "src_ip", "src_user", "gmt_modified", "app_name", "encrypted_data_key"), + Arrays.asList("data_id", "group_id", "tenant_id")), configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, appNameTmp, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp); } catch (CannotGetJdbcConnectionException e) { LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e); @@ -370,7 +373,8 @@ public void updateConfigInfo4Tag(ConfigInfo configInfo, String tag, String srcIp try { String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE); ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - jt.update(configInfoTagMapper.updateConfigInfo4Tag(), configInfo.getContent(), md5, + jt.update(configInfoTagMapper.update(Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name"), + Arrays.asList("data_id", "group_id", "tenant_id", "tag_id")), configInfo.getContent(), md5, srcIp, srcUser, time, appNameTmp, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, tagTmp); } catch (CannotGetJdbcConnectionException e) { LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e); @@ -444,7 +448,8 @@ public void updateMd5(String dataId, String group, String tenant, String md5, Ti String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - jt.update(configInfoMapper.updateMd5(), + jt.update(configInfoMapper.update( + Collections.singletonList("md5"), Arrays.asList("data_id", "group_id", "tenant_id", "gmt_modified")), md5, dataId, group, tenantTmp, lastTime); } catch (CannotGetJdbcConnectionException e) { LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e); @@ -556,7 +561,7 @@ public void removeConfigInfo4Beta(final String dataId, final String group, final ConfigInfo configInfo = findConfigInfo4Beta(dataId, group, tenant); if (configInfo != null) { ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_BETA).get(); - jt.update(configInfoBetaMapper.removeConfigInfo4Beta(), dataId, + jt.update(configInfoBetaMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id")), dataId, group, tenantTmp); } } catch (CannotGetJdbcConnectionException e) { @@ -576,9 +581,9 @@ public boolean addAggrConfigInfo(final String dataId, final String group, String String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; final Timestamp now = new Timestamp(System.currentTimeMillis()); ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - String select = configInfoAggrMapper.select(); - String insert = configInfoAggrMapper.insert(); - String update = configInfoAggrMapper.update(); + String select = configInfoAggrMapper.select(Collections.singletonList("content"), Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); + String insert = configInfoAggrMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified")); + String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified"), Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); try { try { @@ -604,7 +609,7 @@ public void removeSingleAggrConfigInfo(final String dataId, final String group, final String datumId) { final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - String sql = configInfoAggrMapper.removeSingleAggrConfigInfo(); + String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); try { this.jt.update(sql, new PreparedStatementSetter() { @@ -627,7 +632,7 @@ public void setValues(PreparedStatement ps) throws SQLException { public void removeAggrConfigInfo(final String dataId, final String group, final String tenant) { final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - String sql = configInfoAggrMapper.removeAggrConfigInfo(); + String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id")); try { this.jt.update(sql, new PreparedStatementSetter() { @@ -732,7 +737,7 @@ public boolean replaceAggr(final String dataId, final String group, final String String appNameTmp = appName == null ? "" : appName; removeAggrConfigInfo(dataId, group, tenant); String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; - String sql = configInfoAggrMapper.replaceAggr(); + String sql = configInfoAggrMapper.insert(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified")); for (Map.Entry datumEntry : datumMap.entrySet()) { jt.update(sql, dataId, group, tenantTmp, datumEntry.getKey(), appNameTmp, datumEntry.getValue(), new Timestamp(System.currentTimeMillis())); @@ -777,7 +782,8 @@ public ConfigInfoBetaWrapper findConfigInfo4Beta(final String dataId, final Stri String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoBetaMapper configInfoBetaMapper = (ConfigInfoBetaMapper) mapperManager.findMapper(dataSource, TableConstant. CONFIG_INFO_BETA).get(); - return this.jt.queryForObject(configInfoBetaMapper.findConfigInfo4Beta(), + return this.jt.queryForObject(configInfoBetaMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "beta_ips", "encrypted_data_key"), + Arrays.asList("data_id", "group_id", "tenant_id")), new Object[] {dataId, group, tenantTmp}, CONFIG_INFO_BETA_WRAPPER_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null. return null; @@ -794,7 +800,8 @@ public ConfigInfoTagWrapper findConfigInfo4Tag(final String dataId, final String String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim(); try { ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - return this.jt.queryForObject(configInfoTagMapper.findConfigInfo4Tag(), + return this.jt.queryForObject(configInfoTagMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "tag_id", "app_name", "content"), + Arrays.asList("data_id", "group_id", "tenant_id", "tag_id")), new Object[] {dataId, group, tenantTmp, tagTmp}, CONFIG_INFO_TAG_WRAPPER_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null. return null; @@ -810,7 +817,8 @@ public ConfigInfo findConfigInfoApp(final String dataId, final String group, fin String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - return this.jt.queryForObject(configInfoMapper.findConfigInfoApp(), + return this.jt.queryForObject(configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content"), + Arrays.asList("data_id", "group_id", "tenant_id", "app_name")), new Object[] {dataId, group, tenantTmp, appName}, CONFIG_INFO_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null. return null; @@ -862,7 +870,8 @@ public ConfigInfo findConfigInfoAdvanceInfo(final String dataId, final String gr public ConfigInfoBase findConfigInfoBase(final String dataId, final String group) { try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - return this.jt.queryForObject(configInfoMapper.findConfigInfoBase(), + return this.jt.queryForObject(configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "content"), + Arrays.asList("data_id", "group_id", "tenant_id")), new Object[] {dataId, group, StringUtils.EMPTY}, CONFIG_INFO_BASE_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null. return null; @@ -877,7 +886,8 @@ public ConfigInfo findConfigInfo(long id) { try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); return this.jt - .queryForObject(configInfoMapper.findConfigInfoById(), + .queryForObject(configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content"), + Collections.singletonList("id")), new Object[] {id}, CONFIG_INFO_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null. return null; @@ -892,7 +902,8 @@ public ConfigInfoWrapper findConfigInfo(final String dataId, final String group, final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - return this.jt.queryForObject(configInfoMapper.findConfigInfoByDataId2Group2Tenant(), + return this.jt.queryForObject(configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "type", "encrypted_data_key"), + Arrays.asList("data_id", "group_id", "tenant_id")), new Object[] {dataId, group, tenantTmp}, CONFIG_INFO_WRAPPER_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null. return null; @@ -1715,7 +1726,8 @@ public Page findConfigInfoBaseLike(final int pageNo, final int p public ConfigInfoAggr findSingleConfigInfoAggr(String dataId, String group, String tenant, String datumId) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - String sql = configInfoAggrMapper.findSingleConfigInfoAggr(); + String sql = configInfoAggrMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "datum_id", "app_name", "content"), + Arrays.asList("data_id", "group_id", "tenant_id", "datum_id")); try { return this.jt @@ -1757,7 +1769,7 @@ public Page findConfigInfoAggrByPage(String dataId, String group String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); final int startRow = (pageNo - 1) * pageSize; - String sqlCountRows = configInfoAggrMapper.findConfigInfoAggrByPageCountRows(); + String sqlCountRows = configInfoAggrMapper.select(Arrays.asList("count(*)"), Arrays.asList("data_id", "group_id", "tenant_id")); String sqlFetchRows = configInfoAggrMapper.findConfigInfoAggrByPageFetchRows(startRow, pageSize); PaginationHelper helper = createPaginationHelper(); try { @@ -1893,7 +1905,8 @@ public List findAllAggrGroup() { @Override public List findDatumIdByContent(String dataId, String groupId, String content) { ConfigInfoAggrMapper configInfoAggrMapper = (ConfigInfoAggrMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_AGGR).get(); - String sql = configInfoAggrMapper.findDatumIdByContent(); + String sql = configInfoAggrMapper.select( + Collections.singletonList("datum_id"), Arrays.asList("data_id", "group_id", "content")); try { return this.jt.queryForList(sql, new Object[] {dataId, groupId, content}, String.class); @@ -2000,7 +2013,8 @@ public long addConfigInfoAtomic(final long configId, final String srcIp, final S KeyHolder keyHolder = new GeneratedKeyHolder(); ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - final String sql = configInfoMapper.addConfigInfoAtomic(); + final String sql = configInfoMapper.insert(Arrays.asList("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")); try { jt.update(new PreparedStatementCreator() { @@ -2108,7 +2122,7 @@ public void removeConfigInfoAtomic(final String dataId, final String group, fina String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - jt.update(configInfoMapper.removeConfigInfoAtomic(), dataId, group, + jt.update(configInfoMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id")), dataId, group, tenantTmp); } catch (CannotGetJdbcConnectionException e) { LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e); @@ -2143,7 +2157,7 @@ public void removeConfigInfoTag(final String dataId, final String group, final S String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag; try { ConfigInfoTagMapper configInfoTagMapper = (ConfigInfoTagMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO_TAG).get(); - jt.update(configInfoTagMapper.removeConfigInfoTag(), dataId, + jt.update(configInfoTagMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "tag_id")), dataId, group, tenantTmp, tagTmp); } catch (CannotGetJdbcConnectionException e) { LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e); @@ -2167,7 +2181,8 @@ public void updateConfigInfoAtomic(final ConfigInfo configInfo, final String src try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - jt.update(configInfoMapper.updateConfigInfoAtomic(), configInfo.getContent(), md5Tmp, srcIp, srcUser, + jt.update(configInfoMapper.update(Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name", "c_desc", "c_use", "effect", "type", + "c_schema", "encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id")), configInfo.getContent(), md5Tmp, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp); } catch (CannotGetJdbcConnectionException e) { @@ -2189,7 +2204,8 @@ private int updateConfigInfoAtomicCas(final ConfigInfo configInfo, final String try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - return jt.update(configInfoMapper.updateConfigInfoAtomic(), + return jt.update(configInfoMapper.update(Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name", "c_desc", "c_use", "effect", "type", + "c_schema", "encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id")), configInfo.getContent(), md5Tmp, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, configInfo.getMd5()); } catch (CannotGetJdbcConnectionException e) { @@ -2225,7 +2241,8 @@ public ConfigAdvanceInfo findConfigAdvanceInfo(final String dataId, final String try { List configTagList = this.selectTagByConfig(dataId, group, tenant); ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - ConfigAdvanceInfo configAdvance = this.jt.queryForObject(configInfoMapper.findConfigAdvanceInfo(), + ConfigAdvanceInfo configAdvance = this.jt.queryForObject(configInfoMapper.select(Arrays.asList("gmt_create", "gmt_modified", "src_user", "src_ip", "c_desc", "c_use", "effect", "type", "c_schema"), + Arrays.asList("data_id", "group_id", "tenant_id")), new Object[] {dataId, group, tenantTmp}, CONFIG_ADVANCE_INFO_ROW_MAPPER); if (configTagList != null && !configTagList.isEmpty()) { StringBuilder configTagsTmp = new StringBuilder(); @@ -2253,7 +2270,9 @@ public ConfigAllInfo findConfigAllInfo(final String dataId, final String group, try { List configTagList = this.selectTagByConfig(dataId, group, tenant); ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - ConfigAllInfo configAdvance = this.jt.queryForObject(configInfoMapper.findConfigAllInfo(), new Object[] {dataId, group, tenantTmp}, + ConfigAllInfo configAdvance = this.jt.queryForObject(configInfoMapper.select(Arrays.asList("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"), + Arrays.asList("data_id", "group_id", "tenant_id")), new Object[] {dataId, group, tenantTmp}, CONFIG_ALL_INFO_ROW_MAPPER); if (configTagList != null && !configTagList.isEmpty()) { StringBuilder configTagsTmp = new StringBuilder(); @@ -2287,9 +2306,10 @@ public void insertConfigHistoryAtomic(long id, ConfigInfo configInfo, String src try { HistoryConfigInfoMapper historyConfigInfoMapper = (HistoryConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.HIS_CONFIG_INFO).get(); jt.update( - historyConfigInfoMapper.insertConfigHistoryAtomic(), id, configInfo.getDataId(), configInfo.getGroup(), - tenantTmp, appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time, ops, - encryptedDataKey); + historyConfigInfoMapper.insert(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", + "src_ip", "src_user", "gmt_modified", "op_type", "encrypted_data_key")), + id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp, + configInfo.getContent(), md5Tmp, srcIp, srcUser, time, ops, encryptedDataKey); } catch (DataAccessException e) { LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e); throw e; @@ -2350,7 +2370,9 @@ public void updateConfigSubAtomic(final String dataId, final String group, final @Override public ConfigHistoryInfo detailConfigHistory(Long nid) { HistoryConfigInfoMapper historyConfigInfoMapper = (HistoryConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.HIS_CONFIG_INFO).get(); - String sqlFetchRows = historyConfigInfoMapper.detailConfigHistory(); + String sqlFetchRows = historyConfigInfoMapper.select(Arrays.asList("nid", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", + "src_user", "src_ip", "op_type", "gmt_create", "gmt_modified", "encrypted_data_key"), + Collections.singletonList("nid")); try { ConfigHistoryInfo historyInfo = jt .queryForObject(sqlFetchRows, new Object[] {nid}, HISTORY_DETAIL_ROW_MAPPER); @@ -2525,7 +2547,8 @@ public ConfigInfoWrapper queryConfigInfo(final String dataId, final String group String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - return this.jt.queryForObject(configInfoMapper.queryConfigInfo(), new Object[] {dataId, group, tenantTmp}, + return this.jt.queryForObject(configInfoMapper.select(Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "type", "gmt_modified", "md5", "encrypted_data_key"), + Arrays.asList("data_id", "group_id", "tenant_id")), new Object[] {dataId, group, tenantTmp}, CONFIG_INFO_WRAPPER_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { return null; @@ -2729,7 +2752,7 @@ public List queryConfigInfoByNamespace(String tenant) { String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; try { ConfigInfoMapper configInfoMapper = (ConfigInfoMapper) mapperManager.findMapper(dataSource, TableConstant.CONFIG_INFO).get(); - return this.jt.query(configInfoMapper.queryConfigInfoByNamespace(), + return this.jt.query(configInfoMapper.select(Arrays.asList("data_id", "group_id", "tenant_id", "app_name", "type"), Collections.singletonList("tenant_id")), new Object[]{tenantTmp}, CONFIG_INFO_WRAPPER_ROW_MAPPER); } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null. diff --git a/console/src/main/resources/application.properties b/console/src/main/resources/application.properties index b39c4bde6df..996228e488b 100644 --- a/console/src/main/resources/application.properties +++ b/console/src/main/resources/application.properties @@ -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: diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java index f4ee1bf955a..e8483f762cf 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java @@ -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; @@ -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 datumList) { @@ -61,17 +42,6 @@ public String batchRemoveAggr(List 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 datumIds, boolean isIn) { StringBuilder sql = new StringBuilder( @@ -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 " @@ -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; diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java index 6fd210e2c2a..ac3e9aea926 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java @@ -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; /** @@ -26,19 +27,7 @@ * @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() { @@ -46,17 +35,6 @@ public String updateConfigInfo4BetaCas() { + "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"; diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java index 346a818d4df..055eddce3da 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java @@ -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; @@ -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"; @@ -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"; @@ -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 " @@ -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 ids, Map params) { String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user," @@ -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 "); diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java index 7dac5e01987..8a8a99ac305 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java @@ -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; /** @@ -26,19 +27,7 @@ * @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() { @@ -46,12 +35,6 @@ public String updateConfigInfo4TagCas() { + "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 "; @@ -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; diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java index c47a1883055..142eada3460 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java @@ -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; @@ -29,7 +30,7 @@ * @author hyx **/ -public class ConfigInfoTagsRelationMapperByDerby implements ConfigTagsRelationMapper { +public class ConfigInfoTagsRelationMapperByDerby extends AbstractMapper implements ConfigTagsRelationMapper { @Override public String findConfigInfoAdvanceInfo(Map params, int tagSize) { diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java index 4eb606b5ede..ce61e8654cf 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java @@ -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; /** @@ -26,7 +27,7 @@ * @author hyx **/ -public class HistoryConfigInfoMapperByDerby implements HistoryConfigInfoMapper { +public class HistoryConfigInfoMapperByDerby extends AbstractMapper implements HistoryConfigInfoMapper { @Override public String removeConfigHistory() { @@ -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 < ?"; @@ -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 " diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java index ca6b0abded7..0f6d7c0b666 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java @@ -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; @@ -28,27 +29,7 @@ * @author hyx **/ -public class ConfigInfoAggrMapperByMySql 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 ConfigInfoAggrMapperByMySql extends AbstractMapper implements ConfigInfoAggrMapper { @Override public String batchRemoveAggr(List datumList) { @@ -60,16 +41,6 @@ public String batchRemoveAggr(List 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 datumIds, boolean isIn) { StringBuilder sql = new StringBuilder( @@ -95,24 +66,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 " @@ -124,11 +83,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; diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java index 0528d322043..26dea9943d2 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java @@ -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; /** @@ -26,18 +27,7 @@ * @author hyx **/ -public class ConfigInfoBetaMapperByMySql implements ConfigInfoBetaMapper { - - @Override - public String addConfigInfo4Beta() { - return "SELECT datum_id FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND content = ? "; - } - - @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 ConfigInfoBetaMapperByMySql extends AbstractMapper implements ConfigInfoBetaMapper { @Override public String updateConfigInfo4BetaCas() { @@ -45,17 +35,6 @@ public String updateConfigInfo4BetaCas() { + " 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"; diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java index 2ad215cb0f5..8d103e49a9b 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java @@ -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; @@ -33,7 +34,7 @@ * @author hyx **/ -public class ConfigInfoMapperByMySql implements ConfigInfoMapper { +public class ConfigInfoMapperByMySql extends AbstractMapper implements ConfigInfoMapper { private static final String DATA_ID = "dataId"; @@ -45,11 +46,6 @@ public class ConfigInfoMapperByMySql 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"; @@ -60,22 +56,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 " @@ -223,54 +203,12 @@ public String findChangeConfigFetchRows(Map params, final Timest return sqlFetchRows + where + " AND id > " + lastMaxId + " ORDER BY id ASC" + " LIMIT " + 0 + "," + pageSize; } - @Override - public String addConfigInfoAtomic() { - return "INSERT INTO config_info(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,md5,type,gmt_modified,encrypted_data_key FROM " + "( SELECT id FROM config_info ORDER BY id LIMIT ?,? ) 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,encrypted_data_key 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 ids, Map params) { String tenant = params.get("tenant"); @@ -631,12 +569,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 "); diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java index 95e7f33c0e0..0b42d772e3c 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java @@ -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; /** @@ -26,19 +27,7 @@ * @author hyx **/ -public class ConfigInfoTagMapperByMySql 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 ConfigInfoTagMapperByMySql extends AbstractMapper implements ConfigInfoTagMapper { @Override public String updateConfigInfo4TagCas() { @@ -46,12 +35,6 @@ public String updateConfigInfo4TagCas() { + "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(ID) FROM config_info_tag"; @@ -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; diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java index 0d6ef4ede25..e8a4f7d1e79 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java @@ -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; @@ -29,7 +30,7 @@ * @author hyx **/ -public class ConfigTagsRelationMapperByMySql implements ConfigTagsRelationMapper { +public class ConfigTagsRelationMapperByMySql extends AbstractMapper implements ConfigTagsRelationMapper { @Override public String findConfigInfoAdvanceInfo(Map params, int tagSize) { diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java index f7dd5f2a335..17c2ca367e7 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java @@ -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; /** @@ -26,7 +27,7 @@ * @author hyx **/ -public class HistoryConfigInfoMapperByMySql implements HistoryConfigInfoMapper { +public class HistoryConfigInfoMapperByMySql extends AbstractMapper implements HistoryConfigInfoMapper { @Override public String removeConfigHistory() { @@ -43,12 +44,6 @@ 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 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 = ?"; @@ -60,12 +55,6 @@ public String findConfigHistoryFetchRows(int startRow, int pageSize) { + "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC" + " LIMIT " + startRow + "," + pageSize; } - @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 " diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/AbstractMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/AbstractMapper.java new file mode 100644 index 00000000000..89007255768 --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/AbstractMapper.java @@ -0,0 +1,132 @@ +/* + * 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.mapper; + +import java.util.List; + +/** + * The abstract mapper contains CRUD methods. + * + * @author hyx + **/ + +public abstract class AbstractMapper implements Mapper { + + @Override + public String select(List columns, List where) { + StringBuilder sql = new StringBuilder(); + String method = "SELECT "; + sql.append(method); + 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++) { + sql.append(where.get(i)).append(" = ").append("?"); + if (i != where.size() - 1) { + sql.append(" AND "); + } + } + return sql.toString(); + } + + @Override + public String insert(List columns) { + StringBuilder sql = new StringBuilder(); + String method = "INSERT INTO "; + sql.append(method); + sql.append(getTableName()); + + int size = columns.size(); + sql.append("("); + for (int i = 0; i < size; i++) { + sql.append(columns.get(i)); + if (i != columns.size() - 1) { + sql.append(", "); + } + } + sql.append(") "); + + sql.append("VALUES"); + sql.append("("); + for (int i = 0; i < size; i++) { + sql.append("?"); + if (i != columns.size() - 1) { + sql.append(","); + } + } + sql.append(")"); + return sql.toString(); + } + + @Override + public String update(List columns, List 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++) { + sql.append(where.get(i)).append(" = ").append("?"); + if (i != where.size() - 1) { + sql.append(" AND "); + } + } + return sql.toString(); + } + + @Override + public String delete(List params) { + StringBuilder sql = new StringBuilder(); + String method = "DELETE "; + sql.append(method).append(" FROM ").append(getTableName()).append(" "); + for (int i = 0; i < params.size(); i++) { + sql.append(params.get(i)).append(" "); + if (i != params.size() - 1) { + sql.append("AND "); + } + } + + return sql.toString(); + } +} diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoAggrMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoAggrMapper.java index ba628560e87..b557d04c710 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoAggrMapper.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoAggrMapper.java @@ -26,42 +26,6 @@ public interface ConfigInfoAggrMapper extends Mapper { - /** - * Query content from config_info_aggr by dataId, groupId, tenantId and datumId. - * The default sql: - * SELECT content FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ? - * - * @return The sql of querying content from config_info_aggr by dataId, groupId, tenantId and datumId. - */ - String select(); - - /** - * Add configInfoAggr. - * The default sql: - * INSERT INTO config_info_aggr(data_id, group_id, tenant_id, datum_id, app_name, content, gmt_modified) VALUES(?,?,?,?,?,?,?) - * - * @return The sql of adding configInfoAggr. - */ - String insert(); - - /** - * Update configInfoAggr. - * The default sql: - * UPDATE config_info_aggr SET content = ? , gmt_modified = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ? - * - * @return The sql of updating configInfoAggr. - */ - String update(); - - /** - * Delete all pre-aggregation data under a dataId. - * The default sql: - * DELETE FROM config_info_aggr WHERE data_id=? AND group_id=? AND tenant_id=? - * - * @return The sql of deleting all pre-aggregation data under a dataId. - */ - String removeAggrConfigInfo(); - /** * To delete aggregated data in bulk, you need to specify a list of datum. * The default sql: @@ -72,25 +36,6 @@ public interface ConfigInfoAggrMapper extends Mapper { */ String batchRemoveAggr(List datumList); - /** - * Delete a single piece of data before aggregation. - * The default sql: - * DELETE FROM config_info_aggr WHERE data_id=? AND group_id=? AND tenant_id=? AND datum_id=? - * - * @return The sql of deleting a single piece of data before aggregation. - */ - String removeSingleAggrConfigInfo(); - - /** - * Batch replacement, first delete all the specified DataID+Group data in the aggregation table, and then insert the - * data. Any exception during the transaction process will force a TransactionSystemException to be thrown. - * The default sql: - * INSERT INTO config_info_aggr(data_id, group_id, tenant_id, datum_id, app_name, content, gmt_modified) VALUES(?,?,?,?,?,?,?) - * - * @return The sql of batching replacement. - */ - String replaceAggr(); - /** * Get count of aggregation config info. * The default sql: @@ -111,16 +56,6 @@ public interface ConfigInfoAggrMapper extends Mapper { */ String aggrConfigInfoCount(); - /** - * Find a single piece of data before aggregation. - * The default sql: - * 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=? - * - * @return The sql of finding a single piece of data before aggregation. - */ - String findSingleConfigInfoAggr(); - /** * Find all data before aggregation under a dataId. It is guaranteed not to return NULL. * The default sql: @@ -131,16 +66,6 @@ public interface ConfigInfoAggrMapper extends Mapper { */ String findConfigInfoAggr(); - /** - * Query the count of aggregation config info by dataId, groupId and tenantId. - * The default 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=? ORDER BY datum_id LIMIT ?,? - * - * @return The sql of querying the count of aggregation config info by dataId, groupId and tenantId. - */ - String findConfigInfoAggrByPageCountRows(); - /** * Query aggregation config info. * The default sql: @@ -161,13 +86,4 @@ public interface ConfigInfoAggrMapper extends Mapper { * @return The sql of finding all aggregated data sets. */ String findAllAggrGroup(); - - /** - * Find datumId by datum content. - * The default sql: - * SELECT datum_id FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND content = ? - * - * @return The sql of finding datumId by datum content. - */ - String findDatumIdByContent(); } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoBetaMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoBetaMapper.java index 2c62a9fb265..1f46dc47e5b 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoBetaMapper.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoBetaMapper.java @@ -24,26 +24,6 @@ public interface ConfigInfoBetaMapper extends Mapper { - /** - * Add beta configuration information. - * The default sql: - * 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(?,?,?,?,?,?,?,?,?,?,?,?) - * - * @return The sql of adding beta configuration information. - */ - String addConfigInfo4Beta(); - - /** - * Update beta configuration information. - * The default sql: - * 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=? - * - * @return The sql of updating beta configuration information. - */ - String updateConfigInfo4Beta(); - /** * Update beta configuration information. * UPDATE config_info_beta SET content=?, md5=?, beta_ips=?, src_ip=?,src_user=?,gmt_modified=?,app_name=? @@ -53,25 +33,6 @@ public interface ConfigInfoBetaMapper extends Mapper { */ String updateConfigInfo4BetaCas(); - /** - * Delete configuration information, physical deletion. - * The default sql: - * DELETE FROM config_info_beta WHERE data_id=? AND group_id=? AND tenant_id= - * - * @return The sql of deleting configuration information, physical deletion. - */ - String removeConfigInfo4Beta(); - - /** - * Query beta configuration information based on dataId and group. - * The default sql: - * 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 The sql of querying beta configuration information based on dataId and group. - */ - String findConfigInfo4Beta(); - /** * Query the count of beta configuration information. * The default sql: diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoMapper.java index 09cc0291418..7807274e6a6 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoMapper.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoMapper.java @@ -28,15 +28,6 @@ public interface ConfigInfoMapper extends Mapper { - /** - * Update md5. - * The default sql: - * UPDATE config_info SET md5 = ? WHERE data_id=? AND group_id=? AND tenant_id=? AND gmt_modified=? - * - * @return the sql of updating md5. - */ - String updateMd5(); - /** * Get the maxId. * The default sql: @@ -55,33 +46,6 @@ public interface ConfigInfoMapper extends Mapper { */ String findAllDataIdAndGroup(); - /** - * Query common configuration information based on dataId and group. - * The default sql: - * 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=? - * - * @return Query common configur. - */ - String findConfigInfoApp(); - - /** - * Query configuration information based on dataId and group. - * The default sql: - * SELECT id,data_id,group_id,content FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=? - * - * @return The sql to select config_info by dataId and group. - */ - String findConfigInfoBase(); - - /** - * Query configuration information by primary key ID. - * The default sql: - * SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE id=? - * - * @return The sql to select configInfo by ID. - */ - String findConfigInfoById(); - /** * Query configuration information based on dataId. * The default sql: @@ -257,57 +221,6 @@ public interface ConfigInfoMapper extends Mapper { String findChangeConfigFetchRows(Map params, final Timestamp startTime, final Timestamp endTime, int startRow, int pageSize, long lastMaxId); - /** - * Add configuration; database atomic operation, minimum sql action, no business encapsulation. - * The default sql: - * INSERT INTO config_info(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(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) - * - * @return The sql of adding configuration. - */ - String addConfigInfoAtomic(); - - /** - * Remove configuration; database atomic operation, minimum SQL action, no business encapsulation. - * The default sql: - * DELETE FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=? - * - * @return The sql of removing configuration. - */ - String removeConfigInfoAtomic(); - - /** - * Update configuration; database atomic operation, minimum SQL action, no business encapsulation. - * The default sql: - * 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=? - * - * @return The sql of updating configuration. - */ - String updateConfigInfoAtomic(); - - /** - * Query configuration information; database atomic operation, minimum SQL action, no business encapsulation. - * The default sql: - * 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=? - * - * @return The sql of querying configuration information. - */ - String findConfigAdvanceInfo(); - - /** - * Query configuration information; database atomic operation, minimum SQL action, no business encapsulation. - * The default sql: - * 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=? - * - * @return The sql of getting all config info. - */ - String findConfigAllInfo(); - /** * list group key md5 by page. * The default sql: @@ -319,25 +232,6 @@ String findChangeConfigFetchRows(Map params, final Timestamp sta */ String listGroupKeyMd5ByPageFetchRows(); - /** - * Query config info. - * The default sql: - * SELECT id,data_id,group_id,tenant_id,app_name,content,type,gmt_modified,md5,encrypted_data_key FROM config_info - * WHERE data_id=? AND group_id=? AND tenant_id=? - * - * @return The sql of querying config info. - */ - String queryConfigInfo(); - - /** - * Query base config info list by namespace. - * The default sql: - * SELECT data_id,group_id,tenant_id,app_name,type FROM config_info WHERE tenant_id=? - * - * @return The sql of querying dataId list by namespace. - */ - String queryConfigInfoByNamespace(); - /** * query all configuration information according to group, appName, tenant (for export). * The default sql: @@ -643,16 +537,6 @@ String findChangeConfigFetchRows(Map params, final Timestamp sta */ String findConfigInfosByIds(int idSize); - /** - * Query configuration information; database atomic operation, minimum SQL action, no business encapsulation. - * The default sql: - * 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=? - * - * @return The sql of querying configuration information. - */ - String findConfigInfoByDataId2Group2Tenant(); - /** * Remove configuration; database atomic operation, minimum SQL action, no business encapsulation. * diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoTagMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoTagMapper.java index c00523241b5..2f487f29807 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoTagMapper.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoTagMapper.java @@ -24,26 +24,6 @@ public interface ConfigInfoTagMapper extends Mapper { - /** - * Add tag configuration information and publish data change events. - * The default sql: - * 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(?,?,?,?,?,?,?,?,?,?,?) - * - * @return The sql of add tag configuration. - */ - String addConfigInfo4Tag(); - - /** - * Update tag configuration information. - * The default sql: - * 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=? - * - * @return The sql of updating tag configuration information. - */ - String updateConfigInfo4Tag(); - /** * Update tag configuration information. * The default sql: @@ -54,15 +34,6 @@ public interface ConfigInfoTagMapper extends Mapper { */ String updateConfigInfo4TagCas(); - /** - * Query tag configuration information based on dataId and group. - * The default sql: - * 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 The sql of querying tag configuration information based on dataId and group. - */ - String findConfigInfo4Tag(); - /** * Returns the number of beta configuration items. * The default sql: @@ -93,13 +64,4 @@ public interface ConfigInfoTagMapper extends Mapper { * @return The sql of querying all tag config info for dump task. */ String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize); - - /** - * Delete configuration; database atomic operation, minimum SQL action, no business encapsulation. - * The default sql: - * DELETE FROM config_info_tag WHERE data_id=? AND group_id=? AND tenant_id=? AND tag_id=? - * - * @return The sql of deleting configuration; database atomic operation, minimum SQL action, no business encapsulation. - */ - String removeConfigInfoTag(); } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/HistoryConfigInfoMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/HistoryConfigInfoMapper.java index db74c179c0b..83dc3464926 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/HistoryConfigInfoMapper.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/HistoryConfigInfoMapper.java @@ -51,16 +51,6 @@ public interface HistoryConfigInfoMapper extends Mapper { */ String findDeletedConfig(); - /** - * Update change records; database atomic operations, minimal sql actions, no business encapsulation. - * The default sql: - * 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(?,?,?,?,?,?,?,?,?,?,?,?) - * - * @return The sql of updating change records; database atomic operations, minimal sql actions, no business encapsulation. - */ - String insertConfigHistoryAtomic(); - /** * Query the numbers of history config information by data_id, group_id AND tenant_id. * The default sql: @@ -82,16 +72,6 @@ public interface HistoryConfigInfoMapper extends Mapper { */ String findConfigHistoryFetchRows(int startRow, int pageSize); - /** - * Get history config detail. - * The default sql: - * 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 = ? - * - * @return The sql of getting history config detail. - */ - String detailConfigHistory(); - /** * Get previous config detail. * The default sql: diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java index e9027c3266b..db43af0e860 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java @@ -16,6 +16,8 @@ package com.alibaba.nacos.plugin.datasource.mapper; +import java.util.List; + /** * The parent class of the all mappers. * @@ -24,6 +26,36 @@ public interface Mapper { + /** + * The select method contains columns and where params. + * @param columns The columns + * @param where The where params + * @return The sql of select + */ + String select(List columns, List where); + + /** + * The insert method contains columns. + * @param columns The columns + * @return The sql of insert + */ + String insert(List columns); + + /** + * The update method contains columns and where params. + * @param columns The columns + * @param where The where params + * @return The sql of update + */ + String update(List columns, List where); + + /** + * The delete method contains. + * @param params The params + * @return The sql of delete + */ + String delete(List params); + /** * Get the name of table. * @return The name of table.