use of com.alibaba.nacos.config.server.model.ConfigKey in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method findConfigInfoAggrLike.
@Override
public Page<ConfigInfoAggr> findConfigInfoAggrLike(final int pageNo, final int pageSize, ConfigKey[] configKeys, boolean blacklist) {
String sqlCountRows = "SELECT count(*) FROM config_info_aggr WHERE ";
String sqlFetchRows = "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE ";
StringBuilder where = new StringBuilder(" 1=1 ");
// White list, please synchronize the condition is empty, there is no qualified configuration
if (configKeys.length == 0 && blacklist == false) {
Page<ConfigInfoAggr> page = new Page<ConfigInfoAggr>();
page.setTotalCount(0);
return page;
}
List<String> params = new ArrayList<String>();
boolean isFirst = true;
for (ConfigKey configInfoAggr : configKeys) {
String dataId = configInfoAggr.getDataId();
String group = configInfoAggr.getGroup();
String appName = configInfoAggr.getAppName();
if (StringUtils.isBlank(dataId) && StringUtils.isBlank(group) && StringUtils.isBlank(appName)) {
break;
}
if (blacklist) {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" AND ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id NOT LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" group_id NOT LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" app_name != ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
} else {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" OR ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" group_id LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" app_name = ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
}
}
PaginationHelper<ConfigInfoAggr> helper = createPaginationHelper();
return helper.fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(), params.toArray(), pageNo, pageSize, CONFIG_INFO_AGGR_ROW_MAPPER);
}
use of com.alibaba.nacos.config.server.model.ConfigKey in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method findConfigInfoLike.
@Override
public Page<ConfigInfo> findConfigInfoLike(final int pageNo, final int pageSize, final ConfigKey[] configKeys, final boolean blacklist) {
String sqlCountRows = "SELECT count(*) FROM config_info WHERE ";
String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE ";
StringBuilder where = new StringBuilder(" 1=1 ");
// White list, please synchronize the condition is empty, there is no qualified configuration
if (configKeys.length == 0 && !blacklist) {
Page<ConfigInfo> page = new Page<ConfigInfo>();
page.setTotalCount(0);
return page;
}
List<String> params = new ArrayList<String>();
boolean isFirst = true;
for (ConfigKey configInfo : configKeys) {
String dataId = configInfo.getDataId();
String group = configInfo.getGroup();
String appName = configInfo.getAppName();
if (StringUtils.isBlank(dataId) && StringUtils.isBlank(group) && StringUtils.isBlank(appName)) {
break;
}
if (blacklist) {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" AND ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id NOT LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" group_id NOT LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" app_name != ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
} else {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" OR ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" group_id LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" app_name = ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
}
}
PaginationHelper<ConfigInfo> helper = createPaginationHelper();
return helper.fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(), params.toArray(), pageNo, pageSize, CONFIG_INFO_ROW_MAPPER);
}
use of com.alibaba.nacos.config.server.model.ConfigKey in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method findAllConfigKey.
@Override
public Page<ConfigKey> findAllConfigKey(final int pageNo, final int pageSize, final String tenant) {
final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
final String select = " 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 ";
final int totalCount = configInfoCount(tenant);
int pageCount = totalCount / pageSize;
if (totalCount > pageSize * pageCount) {
pageCount++;
}
if (pageNo > pageCount) {
return null;
}
final Page<ConfigKey> page = new Page<ConfigKey>();
page.setPageNumber(pageNo);
page.setPagesAvailable(pageCount);
page.setTotalCount(totalCount);
List<ConfigKey> result = databaseOperate.queryMany(select, new Object[] { generateLikeArgument(tenantTmp), (pageNo - 1) * pageSize, pageSize }, // new Object[0],
CONFIG_KEY_ROW_MAPPER);
for (ConfigKey item : result) {
page.getPageItems().add(item);
}
return page;
}
use of com.alibaba.nacos.config.server.model.ConfigKey in project nacos by alibaba.
the class ExternalStoragePersistServiceImpl method findConfigInfoAggrLike.
@Override
public Page<ConfigInfoAggr> findConfigInfoAggrLike(final int pageNo, final int pageSize, ConfigKey[] configKeys, boolean blacklist) {
String sqlCountRows = "SELECT count(*) FROM config_info_aggr WHERE ";
String sqlFetchRows = "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE ";
StringBuilder where = new StringBuilder(" 1=1 ");
// Whitelist, please leave the synchronization condition empty, there is no configuration that meets the conditions
if (configKeys.length == 0 && blacklist == false) {
Page<ConfigInfoAggr> page = new Page<ConfigInfoAggr>();
page.setTotalCount(0);
return page;
}
PaginationHelper<ConfigInfoAggr> helper = createPaginationHelper();
List<String> params = new ArrayList<String>();
boolean isFirst = true;
for (ConfigKey configInfoAggr : configKeys) {
String dataId = configInfoAggr.getDataId();
String group = configInfoAggr.getGroup();
String appName = configInfoAggr.getAppName();
if (StringUtils.isBlank(dataId) && StringUtils.isBlank(group) && StringUtils.isBlank(appName)) {
break;
}
if (blacklist) {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" AND ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id NOT LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" group_id NOT LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" app_name != ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
} else {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" OR ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" group_id LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" app_name = ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
}
}
try {
Page<ConfigInfoAggr> result = helper.fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(), params.toArray(), pageNo, pageSize, CONFIG_INFO_AGGR_ROW_MAPPER);
return result;
} catch (CannotGetJdbcConnectionException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e);
throw e;
}
}
use of com.alibaba.nacos.config.server.model.ConfigKey in project nacos by alibaba.
the class ExternalStoragePersistServiceImpl method findAllConfigKey.
@Override
public Page<ConfigKey> findAllConfigKey(final int pageNo, final int pageSize, final String tenant) {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
String select = " 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 ";
final int totalCount = configInfoCount(tenant);
int pageCount = totalCount / pageSize;
if (totalCount > pageSize * pageCount) {
pageCount++;
}
if (pageNo > pageCount) {
return null;
}
final Page<ConfigKey> page = new Page<ConfigKey>();
page.setPageNumber(pageNo);
page.setPagesAvailable(pageCount);
page.setTotalCount(totalCount);
try {
List<ConfigKey> result = jt.query(select, new Object[] { generateLikeArgument(tenantTmp), (pageNo - 1) * pageSize, pageSize }, // new Object[0],
CONFIG_KEY_ROW_MAPPER);
for (ConfigKey item : result) {
page.getPageItems().add(item);
}
return page;
} catch (EmptyResultDataAccessException e) {
return page;
} catch (CannotGetJdbcConnectionException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e);
throw e;
}
}
Aggregations