Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.plugin.datasource.mapper;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* The mapper of config info.
*
* @author hyx
**/
public interface ConfigInfoMapper extends Mapper {
/**
* Get the maxId. The default sql: SELECT max(id) FROM config_info
*
* @param context sql paramMap
* @return the sql of getting the maxId.
*/
default MapperResult findConfigMaxId(MapperContext context) {
return new MapperResult("SELECT MAX(id) FROM config_info", Collections.emptyList());
}
/**
* Find all dataId and group. The default sql: SELECT DISTINCT data_id, group_id FROM config_info
*
* @param context sql paramMap
* @return The sql of finding all dataId and group.
*/
default MapperResult findAllDataIdAndGroup(MapperContext context) {
return new MapperResult("SELECT DISTINCT data_id, group_id FROM config_info", Collections.emptyList());
}
/**
* Query the count of config_info by tenantId and appName. The default sql: SELECT count(*) FROM config_info WHERE
* tenant_id LIKE ? AND app_name=?
*
* @param context sql paramMap
* @return The sql of querying the count of config_info.
*/
default MapperResult findConfigInfoByAppCountRows(MapperContext context) {
Object tenantId = context.getWhereParameter(FieldConstant.TENANT_ID);
Object appName = context.getWhereParameter(FieldConstant.APP_NAME);
String sql = "SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ?";
return new MapperResult(sql, CollectionUtils.list(tenantId, appName));
}
/**
* Query configuration information based on group. The default sql: SELECT
* id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE ? AND app_name=?
*
* @param context The context of startRow, pageSize
* @return The sql of querying configration information based on group.
*/
MapperResult findConfigInfoByAppFetchRows(MapperContext context);
/**
* Returns the number of configuration items. The default sql: SELECT count(*) FROM config_info WHERE tenant_id LIKE
* ?
*
* @param context sql paramMap
* @return The sql of querying the number of configuration items.
*/
default MapperResult configInfoLikeTenantCount(MapperContext context) {
Object tenantId = context.getWhereParameter(FieldConstant.TENANT_ID);
String sql = "SELECT count(*) FROM config_info WHERE tenant_id LIKE ?";
return new MapperResult(sql, Collections.singletonList(tenantId));
}
/**
* Get tenant id list by page. The default sql: SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY
* tenant_id LIMIT startRow, pageSize
*
* @param context The context of startRow, pageSize
* @return The sql of getting tenant id list by page.
*/
MapperResult getTenantIdList(MapperContext context);
/**
* Get group id list by page. The default sql: SELECT group_id FROM config_info WHERE tenant_id
* ='{defaultNamespaceId}' GROUP BY group_id LIMIT startRow, pageSize
*
* @param context The context of startRow, pageSize
* @return The sql of getting group id list by page.
*/
MapperResult getGroupIdList(MapperContext context);
/**
* Query all configuration information by page. The default sql: SELECT data_id,group_id,app_name FROM ( SELECT id
* FROM config_info WHERE tenant_id LIKE ? ORDER BY id LIMIT startRow, pageSize ) g, config_info t WHERE g.id = t.id
* "
*
* @param context The context of startRow, pageSize
* @return The sql of querying all configuration information.
*/
MapperResult findAllConfigKey(MapperContext context);
/**
* Query all configuration information by page. The default sql: SELECT t.id,data_id,group_id,content,md5 FROM (
* SELECT id FROM config_info ORDER BY id LIMIT ?,?) g, config_info t WHERE g.id = t.id
*
* @param context The context of startRow, pageSize
* @return The sql of querying all configuration information by page.
*/
MapperResult findAllConfigInfoBaseFetchRows(MapperContext context);
/**
* Query all config info. The default sql: SELECT
* id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key FROM config_info WHERE id
* > ? ORDER BY id ASC LIMIT startRow,pageSize
*
* @param context The context of startRow, pageSize
* @return The sql of querying all config info.
*/
MapperResult findAllConfigInfoFragment(MapperContext context);
/**
* Query change config. The default sql: SELECT data_id, group_id, tenant_id, app_name, content,
* gmt_modified,encrypted_data_key FROM config_info WHERE gmt_modified >=? AND gmt_modified <= ?
*
* @param context sql paramMap
* @return The sql of querying change config.
*/
default MapperResult findChangeConfig(MapperContext context) {
String sql =
"SELECT id, data_id, group_id, tenant_id, app_name,md5, gmt_modified, encrypted_data_key FROM config_info WHERE "
+ "gmt_modified >= ? and id > ? order by id limit ? ";
return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.START_TIME),
context.getWhereParameter(FieldConstant.LAST_MAX_ID),
context.getWhereParameter(FieldConstant.PAGE_SIZE)));
}
/**
* Get the count of config information. The default sql: SELECT count(*) FROM config_info WHERE ...
*
* @param context The map of params, the key is the parameter name(dataId, groupId, tenantId, appName, startTime,
* endTime, content), the value is the key's value.
* @return The sql of getting the count of config information.
*/
default MapperResult findChangeConfigCountRows(MapperContext context) {
final String tenant = (String) context.getWhereParameter(FieldConstant.TENANT);
final String dataId = (String) context.getWhereParameter(FieldConstant.DATA_ID);
final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
final Timestamp startTime = (Timestamp) context.getWhereParameter(FieldConstant.START_TIME);
final Timestamp endTime = (Timestamp) context.getWhereParameter(FieldConstant.END_TIME);
List