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 594d6199d5c..af0197772bb 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 @@ -22,7 +22,7 @@ * @author hyx **/ -public interface ConfigInfoAggrMapper { +public interface ConfigInfoAggrMapper extends Mapper { /** * Query content from config_info_aggr by dataId, groupId, tenantId and datumId. 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 03986e61f22..8b555247ce3 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 @@ -22,7 +22,7 @@ * @author hyx **/ -public interface ConfigInfoBetaMapper { +public interface ConfigInfoBetaMapper extends Mapper { /** * Add beta configuration information. 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 8f2f2c81968..3349b7262eb 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 @@ -22,7 +22,7 @@ * @author hyx **/ -public interface ConfigInfoMapper { +public interface ConfigInfoMapper extends Mapper { /** * Update md5. 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 new file mode 100644 index 00000000000..bdda54fbffa --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/ConfigInfoTagMapper.java @@ -0,0 +1,103 @@ +/* + * 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; + +/** + * The config tag info mapper. + * + * @author hyx + **/ + +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: + * 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='') + * + * @return The sql of updating tag configuration information. + */ + 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: + * SELECT count(ID) FROM config_info_tag + * + * @return The sql of querying the number of beta configuration items. + */ + String configInfoTagCount(); + + /** + * The count of config_info table sql. + * The default sql: + * SELECT count(*) FROM config_info_tag + * + * @return The sql of the count of config_info table. + */ + String count(); + + /** + * Query all tag config info for dump task. + * The default sql: + * 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 + * + * @return The sql of querying all tag config info for dump task. + */ + String findAllConfigInfoTagForDumpAllFetch(); + + /** + * 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/GroupCapacityMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/GroupCapacityMapper.java new file mode 100644 index 00000000000..b12ffda77c3 --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/GroupCapacityMapper.java @@ -0,0 +1,121 @@ +/* + * 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; + +/** + * The group capacity mapper. + * + * @author hyx + **/ + +public interface GroupCapacityMapper extends Mapper { + + /** + * Get the group capacity. + * The default sql: + * SELECT id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, group_id FROM group_capacity + * WHERE group_id=? + * + * @return The sql of getting the group capacity. + */ + String getGroupCapacity(); + + /** + * Insert GroupCapacity into db. + * The default sql: + * INSERT INTO group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, + * gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info; + * + * @return The sql of add group capacity. + */ + String insertGroupCapacity(); + + /** + * Increment UsageWithDefaultQuotaLimit. + * The default sql: + * UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? + * WHERE group_id = ? AND `usage` < ? AND quota = 0 + * + * @return The sql of incrementing UsageWithDefaultQuotaLimit. + */ + String incrementUsageWithDefaultQuotaLimit(); + + /** + * Increment UsageWithQuotaLimit. + * The default sql: + * UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? + * WHERE group_id = ? AND `usage` < quota AND quota != 0 + * + * @return The sql of incrementing UsageWithQuotaLimit. + */ + String incrementUsageWithQuotaLimit(); + + /** + * Increment Usage. + * The default sql: + * UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? + * + * @return The sql of incrementing Usage. + */ + String incrementUsage(); + + /** + * Decrement Usage. + * The default sql: + * UPDATE group_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE group_id = ? AND `usage` > 0 + * + * @return The sql of decrementing usage. + */ + String decrementUsage(); + + /** + * Update GroupCapacity. + * The default sql: + * update group_capacity set ... gmt_modified = ? WHERE group_id = ? + * + * @return The sql of updating group capacity. + */ + String updateGroupCapacity(); + + /** + * Correct Usage. + * The default sql: + * UPDATE group_capacity SET `usage` = (SELECT count(*) FROM config_info), gmt_modified = ? WHERE + * group_id = ? + * + * @return The sql of correcting usage. + */ + String correctUsage(); + + /** + * Get group capacity list, noly has id and groupId value. + * The default sql: + * SELECT id, group_id FROM group_capacity WHERE id>? LIMIT ? + * + * @return The sql of getting group capacity list. + */ + String getCapacityList4CorrectUsage(); + + /** + * Delete GroupCapacity. + * The default sql: + * DELETE FROM group_capacity WHERE group_id = ?; + * + * @return The sql of deleting group capacity. + */ + String deleteGroupCapacity(); +} 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 new file mode 100644 index 00000000000..865aa1e47ba --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/HistoryConfigInfoMapper.java @@ -0,0 +1,102 @@ +/* + * 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; + +/** + * The history config info mapper. + * + * @author hyx + **/ + +public interface HistoryConfigInfoMapper extends Mapper { + + /** + * Delete data before startTime. + * The default sql: + * DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ? + * + * @return The sql of deleting data before startTime. + */ + String removeConfigHistory(); + + /** + * Get the number of configurations before the specified time. + * The default sql: + * SELECT count(*) FROM his_config_info WHERE gmt_modified < ? + * + * @return The sql of getting the number of configurations before the specified time. + */ + String findConfigHistoryCountByTime(); + + /** + * Query deleted config. + * The default sql: + * SELECT DISTINCT data_id, group_id, tenant_id FROM his_config_info WHERE op_type = 'D' AND gmt_modified >=? AND gmt_modified <= ? + * + * @return The sql of querying deleted config. + */ + 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: + * SELECT count(*) FROM his_config_info WHERE data_id = ? AND group_id = ? AND tenant_id = ? + * + * @return The sql of querying the numbers of history config information by data_id, group_id AND tenant_id. + */ + String findConfigHistoryCountRows(); + + /** + * List configuration history change record. + * The default sql: + * 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 + * + * @return The sql of listing configuration history change record. + */ + String findConfigHistoryFetchRows(); + + /** + * 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: + * 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 = ?) + * + * @return The sql of getting previous config detail. + */ + String detailPreviousConfigHistory(); +} diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/TenantCapacityMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/TenantCapacityMapper.java new file mode 100644 index 00000000000..199eb4d8e23 --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/TenantCapacityMapper.java @@ -0,0 +1,121 @@ +/* + * 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; + +/** + * The tenant capacity mapper. + * + * @author hyx + **/ + +public interface TenantCapacityMapper extends Mapper { + + /** + * Query the tenant capacity. + * The default sql: + * SELECT id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, tenant_id + * FROM tenant_capacity WHERE tenant_id=? + * + * @return The sql of querying the tenant capacity. + */ + String getTenantCapacity(); + + /** + * Insert TenantCapacity. + * The default sql: + * INSERT INTO tenant_capacity (tenant_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, + * gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE tenant_id=?; + * + * @return The sql of inserting tenant capacity. + */ + String insertTenantCapacity(); + + /** + * Increment UsageWithDefaultQuotaLimit. + * The default sql: + * UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? + * WHERE tenant_id = ? AND `usage` < ? AND quota = 0 + * + * @return The sql of incrementing UsageWithDefaultQuotaLimit. + */ + String incrementUsageWithDefaultQuotaLimit(); + + /** + * Increment UsageWithQuotaLimit. + * The default sql: + * UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? + * WHERE tenant_id = ? AND `usage` < quota AND quota != 0 + * + * @return The sql of incrementing UsageWithQuotaLimit. + */ + String incrementUsageWithQuotaLimit(); + + /** + * Increment Usage. + * The default sql: + * UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ? + * + * @return The sql of incrementing usage. + */ + String incrementUsage(); + + /** + * DecrementUsage. + * The default sql: + * UPDATE tenant_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` > 0 + * + * @return The sql of DecrementUsage. + */ + String decrementUsage(); + + /** + * Update TenantCapacity. + * The default sql: + * UPDATE tenant_capacity SET ... gmt_modified = ? WHERE tenant_id = ? + * + * @return The sql of updating TenantCapacity. + */ + String updateTenantCapacity(); + + /** + * Correct Usage. + * The default sql: + * UPDATE tenant_capacity SET `usage` = (SELECT count(*) FROM config_info + * WHERE tenant_id = ?), gmt_modified = ? WHERE tenant_id = ? + * + * @return The sql of correcting usage. + */ + String correctUsage(); + + /** + * Get TenantCapacity List, only including id and tenantId value. + * The default sql: + * SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ? + * + * @return The sql of getting TenantCapacity List, only including id and tenantId value. + */ + String getCapacityList4CorrectUsage(); + + /** + * Delete TenantCapacity. + * The default sql: + * DELETE FROM tenant_capacity WHERE tenant_id = ?; + * + * @return The sql of deleting tenant capacity. + */ + String deleteTenantCapacity(); +} diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/TenantInfoMapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/TenantInfoMapper.java new file mode 100644 index 00000000000..bcab1235f8f --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/TenantInfoMapper.java @@ -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.mapper; + +/** + * The tenant info mapper. + * + * @author hyx + **/ + +public interface TenantInfoMapper extends Mapper { + + /** + * Get the numbers of tenant information by tenant_id. + * The default sql: + * SELECT count(*) FROM tenant_info WHERE tenant_id = ? + * + * @return The sql of getting the numbers of tenant information by tenant_id. + */ + String tenantInfoCountByTenantId(); + + /** + * Insert tenant info. + * The default sql: + * INSERT INTO tenant_info(kp,tenant_id,tenant_name,tenant_desc,create_source,gmt_create,gmt_modified) VALUES(?,?,?,?,?,?,?) + * + * @return The sql of inserting tenant info. + */ + String insertTenantInfoAtomic(); + + /** + * Update tenantInfo showname. + * The default sql: + * UPDATE tenant_info SET tenant_name = ?, tenant_desc = ?, gmt_modified= ? WHERE kp=? AND tenant_id=? + * + * @return The sql of updating tenantInfo showname. + */ + String updateTenantNameAtomic(); + + /** + * Query tenant info. + * The default sql: + * SELECT tenant_id,tenant_name,tenant_desc FROM tenant_info WHERE kp=? + * + * @return The sql of querying tenant info. + */ + String findTenantByKp(); + + /** + * Query tenant info. + * The default sql: + * SELECT tenant_id,tenant_name,tenant_desc FROM tenant_info WHERE kp=? AND tenant_id=? + * + * @return The sql of querying tenant info. + */ + String findTenantByKpAndTenantId(); + + /** + * Remote tenant info. + * The default sql: + * DELETE FROM tenant_info WHERE kp=? AND tenant_id=? + * + * @return The sql of remoting tenant info. + */ + String removeTenantInfoAtomic(); +}