[ISSUE #8312]Update the mappers. (#9171)

This commit is contained in:
The-Gamer-01 2022-09-18 18:21:43 +08:00 committed by KomachiSion
parent 30a9431bfc
commit 56c2a5954c
5 changed files with 172 additions and 14 deletions

View File

@ -46,7 +46,7 @@ public class ConfigInfoAggrMapperByMySql implements ConfigInfoAggrMapper {
@Override @Override
public String removeAggrConfigInfo() { public String removeAggrConfigInfo() {
return "DELETE FROM config_info_aggr WHERE data_id=? AND group_id=? AND tenant_id=?"; return "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ?";
} }
@Override @Override
@ -55,13 +55,13 @@ public class ConfigInfoAggrMapperByMySql implements ConfigInfoAggrMapper {
for (String datum : datumList) { for (String datum : datumList) {
datumString.append('\'').append(datum).append("',"); datumString.append('\'').append(datum).append("',");
} }
return "DELETE FROM config_info_aggr WHERE data_id=? AND group_id=? AND tenant_id=? AND datum_id IN (" return "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id IN ("
+ datumString.toString() + ")"; + datumString.toString() + ")";
} }
@Override @Override
public String removeSingleAggrConfigInfo() { public String removeSingleAggrConfigInfo() {
return "DELETE FROM config_info_aggr WHERE data_id=? AND group_id=? AND tenant_id=? AND datum_id=?"; return "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ?";
} }
@Override @Override
@ -77,13 +77,13 @@ public class ConfigInfoAggrMapperByMySql implements ConfigInfoAggrMapper {
@Override @Override
public String findSingleConfigInfoAggr() { public String findSingleConfigInfoAggr() {
return "SELECT id,data_id,group_id,tenant_id,datum_id,app_name,content FROM " 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=?"; + "config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ?";
} }
@Override @Override
public String findConfigInfoAggr() { public String findConfigInfoAggr() {
return "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM " 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"; + "config_info_aggr WHERE data_id= ? AND group_id= ? AND tenant_id= ? ORDER BY datum_id";
} }
@Override @Override
@ -94,8 +94,8 @@ public class ConfigInfoAggrMapperByMySql implements ConfigInfoAggrMapper {
@Override @Override
public String findConfigInfoAggrByPageFetchRows() { public String findConfigInfoAggrByPageFetchRows() {
return "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id=? AND " 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 LIMIT ?,?"; + "group_id= ? AND tenant_id= ? ORDER BY datum_id LIMIT ?,?";
} }
@Override @Override

View File

@ -34,25 +34,25 @@ public class ConfigInfoBetaMapperByMySql implements ConfigInfoBetaMapper {
@Override @Override
public String updateConfigInfo4Beta() { public String updateConfigInfo4Beta() {
return "UPDATE config_info_beta SET content=?, md5=?, beta_ips=?, src_ip=?,src_user=?,gmt_modified=?,app_name=?,encrypted_data_key=? " 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=?"; + " WHERE data_id= ? AND group_id= ? AND tenant_id= ?";
} }
@Override @Override
public String updateConfigInfo4BetaCas() { public String updateConfigInfo4BetaCas() {
return "UPDATE config_info_beta SET content=?, md5=?, beta_ips=?, src_ip=?,src_user=?,gmt_modified=?,app_name=? " return "UPDATE config_info_beta SET content= ?, md5= ?, beta_ips= ?, src_ip= ?,src_user= ?,gmt_modified= ?,app_name= ? "
+ " WHERE data_id=? AND group_id=? AND tenant_id=? AND (md5=? or md5 is null or md5='')"; + " WHERE data_id= ? AND group_id= ? AND tenant_id= ? AND (md5= ? or md5 is null or md5='')";
} }
@Override @Override
public String removeConfigInfo4Beta() { public String removeConfigInfo4Beta() {
return "DELETE FROM config_info_beta WHERE data_id=? AND group_id=? AND tenant_id=?"; return "DELETE FROM config_info_beta WHERE data_id= ? AND group_id= ? AND tenant_id= ?";
} }
@Override @Override
public String findConfigInfo4Beta() { public String findConfigInfo4Beta() {
return "SELECT id,data_id,group_id,tenant_id,app_name,content,beta_ips,encrypted_data_key FROM " 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=?"; + "config_info_beta WHERE data_id= ? AND group_id= ? AND tenant_id= ?";
} }
@Override @Override

View File

@ -0,0 +1,80 @@
/*
* 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.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper;
/**
* The mysql implementation of ConfigInfoTagMapper.
*
* @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= ?";
}
@Override
public String updateConfigInfo4TagCas() {
return "UPDATE config_info_tag SET content= ?, md5 = ?, src_ip= ?,src_user= ?,gmt_modified= ?,app_name= ? WHERE "
+ "data_id= ? AND group_id= ? AND tenant_id= ? AND tag_id= ? AND (md5= ? or md5 is null or md5='')";
}
@Override
public String findConfigInfo4Tag() {
return "SELECT id,data_id,group_id,tenant_id,tag_id,app_name,content "
+ "FROM config_info_tag WHERE data_id= ? AND group_id= ? AND tenant_id= ? AND tag_id= ?";
}
@Override
public String configInfoTagCount() {
return "SELECT count(ID) FROM config_info_tag";
}
@Override
public String count() {
return "SELECT count(*) FROM config_info_tag";
}
@Override
public String findAllConfigInfoTagForDumpAllFetchRows() {
return " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "
+ " FROM ( SELECT id FROM config_info_tag ORDER BY id LIMIT ?,? ) "
+ "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;
}
}

View File

@ -0,0 +1,78 @@
/*
* 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.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;
/**
* The mysql implementation of HistoryConfigInfoMapper.
*
* @author hyx
**/
public class HistoryConfigInfoMapperByMySql implements HistoryConfigInfoMapper {
@Override
public String removeConfigHistory() {
return "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";
}
@Override
public String findConfigHistoryCountByTime() {
return "SELECT count(*) FROM his_config_info WHERE gmt_modified < ?";
}
@Override
public String findDeletedConfig() {
return "SELECT DISTINCT data_id, group_id, tenant_id FROM his_config_info WHERE op_type = 'D' AND gmt_modified >= ? AND gmt_modified <= ?";
}
@Override
public String 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 = ?";
}
@Override
public String findConfigHistoryFetchRows() {
return "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC";
}
@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 "
+ "FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?) ";
}
@Override
public String getTableName() {
return TableConstant.HIS_CONFIG_INFO;
}
}

View File

@ -90,7 +90,7 @@ public interface ConfigInfoTagMapper extends Mapper {
* *
* @return The sql of querying all tag config info for dump task. * @return The sql of querying all tag config info for dump task.
*/ */
String findAllConfigInfoTagForDumpAllFetch(); String findAllConfigInfoTagForDumpAllFetchRows();
/** /**
* Delete configuration; database atomic operation, minimum SQL action, no business encapsulation. * Delete configuration; database atomic operation, minimum SQL action, no business encapsulation.