[ISSUE #8312]Finish all mappers. (#9199)

* [ISSUE #8312]Finish all mappers.

* [ISSUE #8312]Fix some bugs about mapper.
This commit is contained in:
The-Gamer-01 2022-09-25 13:52:25 +08:00 committed by KomachiSion
parent 6a871b316f
commit a8d63609f2
9 changed files with 1571 additions and 95 deletions

View File

@ -73,6 +73,26 @@ public class ConfigInfoAggrMapperByDerby implements ConfigInfoAggrMapper {
@Override
public String aggrConfigInfoCount(List<String> datumIds, boolean isIn) {
StringBuilder sql = new StringBuilder(
" SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id");
if (isIn) {
sql.append(" IN (");
} else {
sql.append(" NOT IN (");
}
for (int i = 0, size = datumIds.size(); i < size; i++) {
if (i > 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(')');
return sql.toString();
}
@Override
public String aggrConfigInfoCount() {
return " SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}

View File

@ -22,7 +22,6 @@ import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -34,17 +33,17 @@ import java.util.Map;
public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
private static final String DATA_ID = "dataId";
private static final String DATA_ID = "data_id";
private static final String GROUP = "group";
private static final String GROUP = "group_id";
private static final String APP_NAME = "appName";
private static final String APP_NAME = "app_name";
private static final String CONTENT = "content";
@Override
public String updateMd5() {
return "UPDATE config_info SET md5 = ? WHERE data_id=? AND group_id=? AND tenant_id=? AND gmt_modified=?";
return "UPDATE config_info SET md5 = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND gmt_modified = ?";
}
@Override
@ -59,34 +58,35 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
@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=?";
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=?";
return "SELECT id,data_id,group_id,content FROM config_info WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}
@Override
public String findConfigInfo() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE id=?";
public String findConfigInfoById() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE id = ?";
}
@Override
public String findConfigInfoByDataIdFetchRows() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND "
+ "tenant_id=?";
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id = ? AND "
+ "tenant_id = ?";
}
@Override
public String findConfigInfoByDataIdAndAppCountRows() {
return "SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=? AND app_name=?";
return "SELECT count(*) FROM config_info WHERE data_id = ? AND tenant_id = ? AND app_name = ?";
}
@Override
public String findConfigInfoByDataIdAndAppFetchRows() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND "
+ "tenant_id=? AND app_name=?";
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id = ? AND "
+ "tenant_id = ? AND app_name = ?";
}
@Override
@ -96,18 +96,18 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
@Override
public String findConfigInfoByAppCountRows() {
return "SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name=?";
return "SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ?";
}
@Override
public String findConfigInfoByAppFetchRows() {
return "SELECT ID,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE ? AND "
+ "app_name=?";
+ "app_name = ?";
}
@Override
public String configInfoLikeTenantCount() {
return null;
return "SELECT count(*) FROM config_info WHERE tenant_id LIKE ?";
}
@Override
@ -122,7 +122,7 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
@Override
public String findAllConfigKey() {
return " SELECT data_id,group_id,app_name FROM "
return " SELECT data_id,group_id,app_name FROM "
+ " ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id LIMIT ?, ? ) "
+ "g, config_info t WHERE g.id = t.id ";
}
@ -143,56 +143,58 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
@Override
public String findAllConfigInfoFragment() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type FROM config_info WHERE id > ? "
return "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type FROM config_info WHERE id > ? "
+ "ORDER BY id ASC LIMIT ?,?";
}
@Override
public String findChangeConfig() {
return "SELECT data_id, group_id, tenant_id, app_name, content, gmt_modified FROM config_info WHERE "
+ "gmt_modified >=? AND gmt_modified <= ?";
+ "gmt_modified > = ? AND gmt_modified <= ?";
}
@Override
public String findChangeConfigCountRows(Map<String, String> params, final Timestamp startTime, final Timestamp endTime) {
public String findChangeConfigCountRows(Map<String, String> params, final Timestamp startTime,
final Timestamp endTime) {
return "SELECT data_id, group_id, tenant_id, app_name, content, gmt_modified FROM config_info WHERE "
+ "gmt_modified >=? AND gmt_modified <= ?";
+ "gmt_modified > = ? AND gmt_modified <= ?";
}
@Override
public String findChangeConfigFetchRows(Map<String, String> params, final Timestamp startTime, final Timestamp endTime) {
public String findChangeConfigFetchRows(Map<String, String> params, final Timestamp startTime,
final Timestamp endTime) {
return "SELECT data_id, group_id, tenant_id, app_name, content, gmt_modified FROM config_info WHERE "
+ "gmt_modified >=? AND gmt_modified <= ?";
+ "gmt_modified > = ? AND gmt_modified <= ?";
}
@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,"
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=?";
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=?";
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=?";
+ "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=?";
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}
@Override
@ -204,12 +206,12 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
@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=?";
+ "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=?";
return "SELECT data_id,group_id,tenant_id,app_name,type FROM config_info WHERE tenant_id = ?";
}
@Override
@ -217,7 +219,6 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,"
+ "src_ip,c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
List<Object> paramList = new ArrayList<>();
if (!CollectionUtils.isEmpty(ids)) {
where.append(" id IN (");
for (int i = 0; i < ids.size(); i++) {
@ -225,27 +226,38 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
where.append(", ");
}
where.append('?');
paramList.add(ids.get(i));
}
where.append(") ");
} else {
where.append(" tenant_id=? ");
where.append(" tenant_id = ? ");
if (!StringUtils.isEmpty(params.get(DATA_ID))) {
where.append(" AND data_id LIKE ? ");
}
if (StringUtils.isNotEmpty(params.get(GROUP))) {
where.append(" AND group_id=? ");
where.append(" AND group_id = ? ");
}
if (StringUtils.isNotEmpty(params.get(APP_NAME))) {
where.append(" AND app_name=? ");
where.append(" AND app_name = ? ");
}
}
return sql + where;
}
@Override
public String findConfigInfoByBatch(List<String> dataIds, int subQueryLimit) {
return null;
public String findConfigInfoByBatch(int paramSize) {
String sqlStart = "SELECT data_id, group_id, tenant_id, app_name, content FROM config_info"
+ " WHERE group_id = ? AND tenant_id = ? AND data_id IN (";
String sqlEnd = ")";
StringBuilder subQuerySql = new StringBuilder();
for (int i = 0; i < paramSize; i++) {
subQuerySql.append('?');
if (i != paramSize - 1) {
subQuerySql.append(',');
}
}
return sqlStart + subQuerySql.toString() + sqlEnd;
}
@Override
@ -320,6 +332,261 @@ public class ConfigInfoMapperByDerby implements ConfigInfoMapper {
return sqlFetchRows + where;
}
@Override
public String findConfigInfoByDataIdCountRows() {
return "SELECT count(*) FROM config_info WHERE data_id = ? AND tenant_id = ?";
}
@Override
public String findConfigInfoByDataIdAndAdvanceCountRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder("SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfo4PageCountRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
final String sqlCount = "SELECT count(*) FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
}
return sqlCount + where;
}
@Override
public String findConfigInfo4PageFetchRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
}
return sql + where;
}
@Override
public String findConfigInfoBaseByDataIdCountRows() {
return "SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoBaseByDataIdFetchRows() {
return "SELECT id,data_id,group_id,content FROM config_info WHERE data_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoByGroupCountRows() {
return "SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoByGroupFetchRows() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND "
+ "tenant_id=?";
}
@Override
public String findConfigInfoByGroupAndAppCountRows() {
return "SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=? AND app_name =?";
}
@Override
public String findConfigInfoByGroupAndAppFetchRows() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND "
+ "tenant_id=? AND app_name =?";
}
@Override
public String findConfigInfoByAdvanceCountRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder("SELECT count(*) FROM config_info WHERE tenant_id LIKE ? ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByAdvanceFetchRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info where tenant_id LIKE ? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoBaseByGroupCountRows() {
return "SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoBaseByGroupFetchRows() {
return "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoLike4PageCountRows(Map<String, String> params) {
final String appName = params.get("appName");
final String content = params.get("content");
final String dataId = params.get("dataId");
final String group = params.get("groupId");
final String sqlCountRows = "SELECT count(*) FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
}
return sqlCountRows + where;
}
@Override
public String findConfigInfoLike4PageFetchRows(Map<String, String> params) {
final String appName = params.get("appName");
final String content = params.get("content");
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
}
return sqlFetchRows + where;
}
@Override
public String findAllConfigInfoFetchRows() {
return " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "
+ " FROM ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id LIMIT ?,? )"
+ " g, config_info t WHERE g.id = t.id ";
}
@Override
public String findConfigInfoAdvanceInfo(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoByGroupAndAdvanceCountRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByGroupAndAdvanceFetchRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfosByIds(int idSize) {
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE ");
sql.append("id IN (");
for (int i = 0; i < idSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
return sql.toString();
}
@Override
public String 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 ");
sql.append("id IN (");
for (int i = 0; i < size; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
return sql.toString();
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO;

View File

@ -0,0 +1,331 @@
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.derby;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;
import java.util.Map;
/**
* The derby implementation of ConfigTagsRelationMapper.
*
* @author hyx
**/
public class ConfigInfoTagsRelationMapperByDerby implements ConfigTagsRelationMapper {
@Override
public String findConfigInfoAdvanceInfo(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.group_id=? AND a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoByDataIdAndAdvanceCountRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.tenant_id=? ");
sqlCount.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sqlCount.append(", ");
}
sqlCount.append('?');
}
sqlCount.append(") ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND a.app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfo4PageCountRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlCount = "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id";
where.append(" a.tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlCount + where;
}
@Override
public String findConfigInfo4PageFetchRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sql = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id";
where.append(" a.tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sql + where;
}
@Override
public String findConfigInfoByGroupAndAdvanceCountRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.group_id=? AND a.tenant_id=? ");
sqlCount.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sqlCount.append(", ");
}
sqlCount.append('?');
}
sqlCount.append(") ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND a.app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByGroupAndAdvanceFetchRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.group_id=? AND a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoLike4PageCountRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String content = params.get("content");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlCountRows = "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";
where.append(" a.tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND a.data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND a.group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND a.app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlCountRows + where;
}
@Override
public String findConfigInfoLike4PageFetchRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String content = params.get("content");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlFetchRows =
"SELECT a.ID,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id ";
where.append(" a.tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND a.data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND a.group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND a.app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlFetchRows + where;
}
@Override
public String addConfigTagRelationAtomic() {
return "INSERT INTO config_tags_relation(id,tag_name,tag_type,data_id,group_id,tenant_id) "
+ "VALUES(?,?,?,?,?,?)";
}
@Override
public String removeTagByIdAtomic() {
return "DELETE FROM config_tags_relation WHERE id=?";
}
@Override
public String getConfigTagsByTenant() {
return "SELECT tag_name FROM config_tags_relation WHERE tenant_id = ? ";
}
@Override
public String selectTagByConfig() {
return "SELECT tag_name FROM config_tags_relation WHERE data_id=? AND group_id=? AND tenant_id = ? ";
}
@Override
public String findConfigInfoByAdvanceCountRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.tenant_id=? ");
sqlCount.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sqlCount.append(", ");
}
sqlCount.append('?');
}
sqlCount.append(") ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND a.app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByAdvanceFetchRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
}

View File

@ -71,7 +71,27 @@ public class ConfigInfoAggrMapperByMySql implements ConfigInfoAggrMapper {
@Override
public String aggrConfigInfoCount(List<String> datumIds, boolean isIn) {
return "SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
StringBuilder sql = new StringBuilder(
" SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id");
if (isIn) {
sql.append(" IN (");
} else {
sql.append(" NOT IN (");
}
for (int i = 0, size = datumIds.size(); i < size; i++) {
if (i > 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(')');
return sql.toString();
}
@Override
public String aggrConfigInfoCount() {
return " SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
}
@Override

View File

@ -71,13 +71,13 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
}
@Override
public String findConfigInfo() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE id= ?";
public String findConfigInfoById() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE id = ?";
}
@Override
public String findConfigInfoByDataIdFetchRows() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id= ? AND tenant_id= ?";
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id = ? AND tenant_id = ?";
}
@Override
@ -154,7 +154,8 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
}
@Override
public String findChangeConfigCountRows(Map<String, String> params, final Timestamp startTime, final Timestamp endTime) {
public String findChangeConfigCountRows(Map<String, String> params, final Timestamp startTime,
final Timestamp endTime) {
final String tenant = params.get(TENANT);
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
@ -168,11 +169,11 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
if (!StringUtils.isBlank(group)) {
where += " AND group_id LIKE ? ";
}
if (!StringUtils.isBlank(tenantTmp)) {
where += " AND tenant_id = ? ";
}
if (!StringUtils.isBlank(appName)) {
where += " AND app_name = ? ";
}
@ -186,7 +187,8 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
}
@Override
public String findChangeConfigFetchRows(Map<String, String> params, final Timestamp startTime, final Timestamp endTime) {
public String findChangeConfigFetchRows(Map<String, String> params, final Timestamp startTime,
final Timestamp endTime) {
final String tenant = params.get(TENANT);
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
@ -200,11 +202,11 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
if (!StringUtils.isBlank(group)) {
where += " AND group_id LIKE ? ";
}
if (!StringUtils.isBlank(tenantTmp)) {
where += " AND tenant_id = ? ";
}
if (!StringUtils.isBlank(appName)) {
where += " AND app_name = ? ";
}
@ -250,7 +252,7 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
@Override
public String listGroupKeyMd5ByPageFetchRows() {
return " SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "
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";
}
@ -269,6 +271,9 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
public String findAllConfigInfo4Export(List<Long> ids, Map<String, String> params) {
String tenant = params.get("tenant");
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
String sql =
"SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,src_ip,"
+ "c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
List<Object> paramList = new ArrayList<>();
if (!CollectionUtils.isEmpty(ids)) {
@ -294,26 +299,20 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
where.append(" AND app_name= ? ");
}
}
return null;
return sql + where;
}
@Override
public String findConfigInfoByBatch(List<String> dataIds, int subQueryLimit) {
public String findConfigInfoByBatch(int paramSize) {
String sqlStart = "SELECT data_id, group_id, tenant_id, app_name, content "
+ "FROM config_info WHERE group_id = ? AND tenant_id = ? AND data_id IN (";
String sqlEnd = ")";
StringBuilder subQuerySql = new StringBuilder();
for (int i = 0; i < dataIds.size(); i += subQueryLimit) {
// dataids
List<String> params = new ArrayList<>(
dataIds.subList(i, i + subQueryLimit < dataIds.size() ? i + subQueryLimit : dataIds.size()));
for (int j = 0; j < params.size(); j++) {
subQuerySql.append('?');
if (j != params.size() - 1) {
subQuerySql.append(',');
}
for (int i = 0; i < paramSize; i++) {
subQuerySql.append('?');
if (i != paramSize - 1) {
subQuerySql.append(',');
}
}
return sqlStart + subQuerySql.toString() + sqlEnd;
@ -336,7 +335,7 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
if (!StringUtils.isBlank(params.get(CONTENT))) {
where += " AND content LIKE ? ";
}
return sqlCountRows + where;
}
@ -357,7 +356,7 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
if (!StringUtils.isBlank(params.get(CONTENT))) {
where += " AND content LIKE ? ";
}
return sqlFetchRows + where;
}
@ -365,7 +364,7 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
public String findConfigInfoBaseLikeCountRows(Map<String, String> params) {
final String sqlCountRows = "SELECT count(*) FROM config_info WHERE ";
String where = " 1=1 AND tenant_id='' ";
if (!StringUtils.isBlank(params.get(DATA_ID))) {
where += " AND data_id LIKE ? ";
}
@ -394,6 +393,258 @@ public class ConfigInfoMapperByMySql implements ConfigInfoMapper {
return sqlFetchRows + where;
}
@Override
public String findConfigInfoByDataIdCountRows() {
return "SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoByDataIdAndAdvanceCountRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
StringBuilder sqlCount = new StringBuilder("SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfo4PageCountRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
final String sqlCount = "SELECT count(*) FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
}
return sqlCount + where;
}
@Override
public String findConfigInfo4PageFetchRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
final String dataId = params.get(DATA_ID);
final String group = params.get(GROUP);
final String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND app_name=? ");
}
return sql + where;
}
@Override
public String findConfigInfoBaseByDataIdCountRows() {
return "SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoBaseByDataIdFetchRows() {
return "SELECT id,data_id,group_id,content FROM config_info WHERE data_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoByGroupCountRows() {
return "SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoByGroupFetchRows() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoByGroupAndAppCountRows() {
return "SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=? AND app_name =?";
}
@Override
public String findConfigInfoByGroupAndAppFetchRows() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=? AND app_name =?";
}
@Override
public String findConfigInfoByAdvanceCountRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder("SELECT count(*) FROM config_info WHERE tenant_id LIKE ? ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByAdvanceFetchRows(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE ? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoBaseByGroupCountRows() {
return "SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoBaseByGroupFetchRows() {
return "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=?";
}
@Override
public String findConfigInfoLike4PageCountRows(Map<String, String> params) {
String dataId = params.get(DATA_ID);
String group = params.get(GROUP);
final String appName = params.get(APP_NAME);
final String content = params.get(CONTENT);
final String sqlCountRows = "SELECT count(*) FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
}
return sqlCountRows + where;
}
@Override
public String findConfigInfoLike4PageFetchRows(Map<String, String> params) {
String dataId = params.get(DATA_ID);
String group = params.get(GROUP);
final String appName = params.get(APP_NAME);
final String content = params.get(CONTENT);
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info";
StringBuilder where = new StringBuilder(" WHERE ");
where.append(" tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND content LIKE ? ");
}
return sqlFetchRows + where;
}
@Override
public String findAllConfigInfoFetchRows() {
return " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "
+ " FROM ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id LIMIT ?,? )"
+ " g, config_info t WHERE g.id = t.id ";
}
@Override
public String findConfigInfoAdvanceInfo(Map<String, String> params) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoByGroupAndAdvanceCountRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByGroupAndAdvanceFetchRows(Map<String, String> params) {
final String appName = params.get(APP_NAME);
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfosByIds(int idSize) {
StringBuilder sql = new StringBuilder(
"SELECT ID,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE ");
sql.append("id IN (");
for (int i = 0; i < idSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
return sql.toString();
}
@Override
public String 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 ");
sql.append("id IN (");
for (int i = 0; i < size; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
return sql.toString();
}
@Override
public String getTableName() {
return TableConstant.CONFIG_INFO;

View File

@ -0,0 +1,321 @@
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.impl.mysql;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper;
import java.util.Map;
/**
* The mysql implementation of ConfigTagsRelationMapper.
*
* @author hyx
**/
public class ConfigTagsRelationMapperByMySql implements ConfigTagsRelationMapper {
@Override
public String findConfigInfoAdvanceInfo(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.group_id=? AND a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoByDataIdAndAdvanceCountRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.tenant_id=? ");
sqlCount.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sqlCount.append(", ");
}
sqlCount.append('?');
}
sqlCount.append(") ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND a.app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfo4PageCountRows(final Map<String, String> params, final int tagSize) {
final String appName = params.get("appName");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlCount = "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id";
where.append(" a.tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlCount;
}
@Override
public String findConfigInfo4PageFetchRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sql = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id";
where.append(" a.tenant_id=? ");
if (StringUtils.isNotBlank(dataId)) {
where.append(" AND a.data_id=? ");
}
if (StringUtils.isNotBlank(group)) {
where.append(" AND a.group_id=? ");
}
if (StringUtils.isNotBlank(appName)) {
where.append(" AND a.app_name=? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sql + where;
}
@Override
public String findConfigInfoByGroupAndAdvanceCountRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.group_id=? AND a.tenant_id=? ");
sqlCount.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sqlCount.append(", ");
}
sqlCount.append('?');
}
sqlCount.append(") ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND a.app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByGroupAndAdvanceFetchRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.group_id=? AND a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
@Override
public String findConfigInfoLike4PageCountRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String content = params.get("content");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlCountRows = "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";
where.append(" a.tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND a.data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND a.group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND a.app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlCountRows + where;
}
@Override
public String findConfigInfoLike4PageFetchRows(final Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
final String content = params.get("content");
final String dataId = params.get("dataId");
final String group = params.get("group");
StringBuilder where = new StringBuilder(" WHERE ");
final String sqlFetchRows = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content "
+ "FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id ";
where.append(" a.tenant_id LIKE ? ");
if (!StringUtils.isBlank(dataId)) {
where.append(" AND a.data_id LIKE ? ");
}
if (!StringUtils.isBlank(group)) {
where.append(" AND a.group_id LIKE ? ");
}
if (!StringUtils.isBlank(appName)) {
where.append(" AND a.app_name = ? ");
}
if (!StringUtils.isBlank(content)) {
where.append(" AND a.content LIKE ? ");
}
where.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
where.append(", ");
}
where.append('?');
}
where.append(") ");
return sqlFetchRows + where;
}
@Override
public String addConfigTagRelationAtomic() {
return "INSERT INTO config_tags_relation(id,tag_name,tag_type,data_id,group_id,tenant_id) VALUES(?,?,?,?,?,?)";
}
@Override
public String removeTagByIdAtomic() {
return "DELETE FROM config_tags_relation WHERE id=?";
}
@Override
public String getConfigTagsByTenant() {
return "SELECT tag_name FROM config_tags_relation WHERE tenant_id = ? ";
}
@Override
public String selectTagByConfig() {
return "SELECT tag_name FROM config_tags_relation WHERE data_id=? AND group_id=? AND tenant_id = ? ";
}
@Override
public String findConfigInfoByAdvanceCountRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sqlCount = new StringBuilder(
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.tenant_id=? ");
sqlCount.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sqlCount.append(", ");
}
sqlCount.append('?');
}
sqlCount.append(") ");
if (StringUtils.isNotBlank(appName)) {
sqlCount.append(" AND a.app_name=? ");
}
return sqlCount.toString();
}
@Override
public String findConfigInfoByAdvanceFetchRows(Map<String, String> params, int tagSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return sql.toString();
}
}

View File

@ -102,6 +102,15 @@ public interface ConfigInfoAggrMapper extends Mapper {
*/
String aggrConfigInfoCount(List<String> datumIds, boolean isIn);
/**
* Get count of aggregation config info.
* The default sql:
* SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?
*
* @return The count of getting count of aggregation config info.
*/
String aggrConfigInfoCount();
/**
* Find a single piece of data before aggregation.
* The default sql:

View File

@ -80,7 +80,7 @@ public interface ConfigInfoMapper extends Mapper {
*
* @return The sql to select configInfo by ID.
*/
String findConfigInfo();
String findConfigInfoById();
/**
* Query configuration information based on dataId.
@ -344,11 +344,10 @@ public interface ConfigInfoMapper extends Mapper {
* The default sql:
* SELECT data_id, group_id, tenant_id, app_name, content FROM config_info WHERE group_id = ? AND tenant_id = ? AND data_id IN (...)
*
* @param dataIds data id list
* @param subQueryLimit sub query limit
* @param paramSize The size of ids.
* @return The sql to get config information by batch.
*/
String findConfigInfoByBatch(List<String> dataIds, int subQueryLimit);
String findConfigInfoByBatch(int paramSize);
/**
* Get the count of config information.
@ -393,4 +392,234 @@ public interface ConfigInfoMapper extends Mapper {
* @return The sql of getting the config information.
*/
String findConfigInfoBaseLikeFetchRows(Map<String, String> params);
/**
* To get number of config information by dataId and tenantId.
* The default sql:
* SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=?
*
* @return The sql of query number.
*/
String findConfigInfoByDataIdCountRows();
/**
* find the count of data_id AND tenant_id.
* The default sql:
* SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=? ...
*
* @param params The map of appName/
* @return The sql of finding the count of data_id and tenant_id.
*/
String findConfigInfoByDataIdAndAdvanceCountRows(Map<String, String> params);
/**
* find config info.
* The default sql:
* SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND tenant_id=? ...
*
* @param params The map of app name.
* @return The sql of finding config info.
*/
String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, String> params);
/**
* find the count of config info.
* The default sql:
* SELECT count(*) FROM config_info ...
*
* @param params The mpa of dataId, groupId and appName.
* @return The count of config info.
*/
String findConfigInfo4PageCountRows(Map<String, String> params);
/**
* find config info.
* The default sql:
* SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info ...
*
* @param params The mpa of dataId, groupId and appName.
* @return The sql of finding config info.
*/
String findConfigInfo4PageFetchRows(Map<String, String> params);
/**
* The count of querying configuration information based on dataId.
* The default sql:
* SELECT count(*) FROM config_info WHERE data_id=? AND tenant_id=?
*
* @return The sql of query count.
*/
String findConfigInfoBaseByDataIdCountRows();
/**
* Query configuration information based on dataId.
* The default sql:
* SELECT id,data_id,group_id,content FROM config_info WHERE data_id=? AND tenant_id=?
*
* @return The sql of query configuration information based on dataId.
*/
String findConfigInfoBaseByDataIdFetchRows();
/**
* Get the count of querying configuration information based on group.
* The default sql:
* SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=?
*
* @return The count of config info by groupId and tenantId.
*/
String findConfigInfoByGroupCountRows();
/**
* Get the config info by groupId and tenantId.
* The default sql:
* SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=?
*
* @return Get the config info by groupId and tenantId.
*/
String findConfigInfoByGroupFetchRows();
/**
* The count of querying configuration information based on group.
* The default sql:
* SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=? AND app_name =?
*
* @return The sql of the count of querying configuration information based on group.
*/
String findConfigInfoByGroupAndAppCountRows();
/**
* Query configuration information based on group.
* The default sql:
* SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=? AND app_name =?
*
* @return The sql of querying configuration information based on group.
*/
String findConfigInfoByGroupAndAppFetchRows();
/**
* Query configuration information count.
* The default sql:
* SELECT count(*) FROM config_info WHERE tenant_id LIKE ? ...
*
* @param params The map of appName.
* @return Query configuration information count.
*/
String findConfigInfoByAdvanceCountRows(Map<String, String> params);
/**
* Query configuration information.
* The default sql:
* SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE ? ...
*
* @param params The map of appName.
* @return Query configuration information.
*/
String findConfigInfoByAdvanceFetchRows(Map<String, String> params);
/**
* Query configuration information count based on group.
* The default sql:
* SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=?
*
* @return Query configuration information count based on group.
*/
String findConfigInfoBaseByGroupCountRows();
/**
* Query configuration information based on group.
* The default sql:
* SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=?
*
* @return Query configuration information based on group.
*/
String findConfigInfoBaseByGroupFetchRows();
/**
* Query config info count.
* The default sql:
* SELECT count(*) FROM config_info ...
*
* @param params The map of dataId, group, appName, content
* @return The sql of querying config info count
*/
String findConfigInfoLike4PageCountRows(Map<String, String> params);
/**
* Query config info.
* The default sql:
* SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info ...
*
* @param params The map of dataId, group, appName, content
* @return The sql of querying config info
*/
String findConfigInfoLike4PageFetchRows(Map<String, String> params);
/**
* Query all configuration information by page.
* The default sql:
* SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 "
* + " FROM ( SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id LIMIT ?,? )"
* + " g, config_info t WHERE g.id = t.id
*
* @return Query all configuration information by page.
*/
String findAllConfigInfoFetchRows();
/**
* Query 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=? ...
*
* @param params The map of appName.
* @return The sql of querying configuration information based on dataId and group.
*/
String findConfigInfoAdvanceInfo(Map<String, String> params);
/**
* Query configuration information count.
* The default sql:
* SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=? ...
*
* @param params The map of appName.
* @return The sql of querying configuration information count
*/
String findConfigInfoByGroupAndAdvanceCountRows(Map<String, String> params);
/**
* Query configuration information.
* The default sql:
* SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=? ...
*
* @param params The map of appName.
* @return The sql of querying configuration information
*/
String findConfigInfoByGroupAndAdvanceFetchRows(Map<String, String> params);
/**
* find ConfigInfo by ids.
* The default sql:
* SELECT ID,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE id IN (...)
*
* @param idSize the size of ids.
* @return find ConfigInfo by ids.
*/
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.
*
* @param size The size of ids.
* @return The sql of removing configuration.
*/
String removeConfigInfoByIdsAtomic(int size);
}

View File

@ -26,26 +26,17 @@ import java.util.Map;
public interface ConfigTagsRelationMapper {
/**
* The default sql:
* SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN
* config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.group_id=? AND a.tenant_id=?
* AND b.tag_name IN (...) ...;
*
* @param configAdvanceInfo advance info
* @return * Query configuration information based on dataId and group.
*/
String findConfigInfoAdvanceInfo(Map<String, Object> configAdvanceInfo);
/**
* Get the count of relations.
* The default sql:
* SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.tenant_id=? ...
*
* @param configAdvanceInfo advance info
* @param params The map of dataId and tenantId.
* @param tagSize the tags name size.
* @return The sql of getting the count of relations.
*/
String findConfigInfoByDataIdAndAdvanceCountRows(Map<String, Object> configAdvanceInfo);
String findConfigInfoByDataIdAndAdvanceCountRows(Map<String, String> params, int tagSize);
/**
* Find config info.
@ -53,22 +44,23 @@ public interface ConfigTagsRelationMapper {
* SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN
* config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.tenant_id AND b.tag_name IN (...) ...
*
* @param configAdvanceInfo advance info
* @param params The map of appName.
* @param tagSize the tags name size.
* @return The sql of finding config info.
*/
String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, Object> configAdvanceInfo);
String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, String> params, int tagSize);
/**
* Get the count of config info.
* The default sql:
* SELECT count(*) FROM config_info WHERE ...
*
* @param configAdvanceInfo advance info
* @param params The map of params, the key is the parameter name(dataId, groupId, tenantId, appName, startTime, endTime, content),
* the value is the key's value.
* @param tagSize the tags name size.
* @return The sql of get config info.
*/
String findConfigInfo4PageCountRows(final Map<String, Object> configAdvanceInfo, final Map<String, String> params);
String findConfigInfo4PageCountRows(final Map<String, String> params, int tagSize);
/**
* Find config info.
@ -76,21 +68,22 @@ public interface ConfigTagsRelationMapper {
* SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN
* config_tags_relation b ON a.id=b.i ...
*
* @param configAdvanceInfo advance info
* @param params The keys and values are dataId and group.
* @param tagSize the tags name size.
* @return The sql of finding config info.
*/
String findConfigInfo4PageFetchRows(Map<String, Object> configAdvanceInfo, final Map<String, String> params);
String findConfigInfo4PageFetchRows(final Map<String, String> params, int tagSize);
/**
* Get the count of config information by group id and tenant id and tag name.
* The default sql:
* SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id=? AND b.tag_name IN (...)
*
* @param configAdvanceInfo advance info
* @param params The keys and values are dataId and group.
* @param tagSize the tags name size.
* @return The sql of querying configuration information.
*/
String findConfigInfoByGroupAndAdvanceCountRows(Map<String, Object> configAdvanceInfo);
String findConfigInfoByGroupAndAdvanceCountRows(final Map<String, String> params, int tagSize);
/**
* Query configuration information.
@ -98,21 +91,22 @@ public interface ConfigTagsRelationMapper {
* SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
* config_tags_relation b ON a.id=b.id WHERE a.tenant_id=? AND b.tag_name IN (...) ...
*
* @param configAdvanceInfo advance info
* @param params the keys and values are dataId and group.
* @param tagSize the tags name size.
* @return The sql of querying configuration information.
*/
String findConfigInfoByGroupAndAdvanceFetchRows(Map<String, Object> configAdvanceInfo);
String findConfigInfoByGroupAndAdvanceFetchRows(final Map<String, String> params, int tagSize);
/**
* Get the count of config information by config tags relation.
* The default sql:
* SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id
*
* @param configAdvanceInfo advance info
* @param params the keys and values are dataId and group.
* @param tagSize the tags name size.
* @return The sql of getting the count of config information.
*/
String findConfigInfoLike4PageCountRows(Map<String, Object> configAdvanceInfo, final Map<String, String> params);
String findConfigInfoLike4PageCountRows(final Map<String, String> params, int tagSize);
/**
* Query config info.
@ -120,11 +114,11 @@ public interface ConfigTagsRelationMapper {
* SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content
* FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id
*
* @param configAdvanceInfo advance info
* @param params the keys and values are dataId and group.
* @param tagSize the tags name size.
* @return The sql of querying config info.
*/
String findConfigInfoLike4PageFetchRows(Map<String, Object> configAdvanceInfo, final Map<String, String> params);
String findConfigInfoLike4PageFetchRows(final Map<String, String> params, int tagSize);
/**
* Add configuration; database atomic operation, minimum sql action, no business encapsulation.
@ -161,4 +155,38 @@ public interface ConfigTagsRelationMapper {
* @return The sql of querying tag list
*/
String selectTagByConfig();
/**
* The number of config.
* The default sql:
* SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.tenant_id=?
*
* @param params The map of appName.
* @param tagSize The size of tags.
* @return The number of config.
*/
String findConfigInfoByAdvanceCountRows(Map<String, String> params, int tagSize);
/**
* Query configuration information.
* The default sql:
* SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.tenant_id=?
*
* @param params The map of appName.
* @param tagSize The size of tags.
* @return The sql of querying configuration information.
*/
String findConfigInfoByAdvanceFetchRows(Map<String, String> params, int tagSize);
/**
* The default sql:
* SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN
* config_tags_relation b ON a.id=b.id WHERE a.data_id=? AND a.group_id=? AND a.tenant_id=?
* AND b.tag_name IN (...) ...;
*
* @param params The map of appName.
* @param tagSize the tags name size.
* @return * Query configuration information based on dataId and group.
*/
String findConfigInfoAdvanceInfo(Map<String, String> params, int tagSize);
}