replace "+=" to StringBuilder append method

This commit is contained in:
Brian Huang 2020-06-12 22:00:08 +08:00
parent 3ea2200fb0
commit 8c0f52f987
2 changed files with 81 additions and 81 deletions

View File

@ -991,7 +991,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
} }
PaginationHelper<ConfigInfo> helper = createPaginationHelper(); PaginationHelper<ConfigInfo> helper = createPaginationHelper();
return helper return helper
.fetchPage(sqlCount + where, sql + where, paramList.toArray(), pageNo, .fetchPage(sqlCount + where.toString(), sql + where.toString(), paramList.toArray(), pageNo,
pageSize, CONFIG_INFO_ROW_MAPPER); pageSize, CONFIG_INFO_ROW_MAPPER);
} }
@ -1597,7 +1597,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final ConfigKey[] configKeys, final boolean blacklist) { final ConfigKey[] configKeys, final boolean blacklist) {
String sqlCountRows = "select count(*) from config_info where "; 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 "; String sqlFetchRows = "select ID,data_id,group_id,tenant_id,app_name,content from config_info where ";
String where = " 1=1 "; StringBuilder where = new StringBuilder(" 1=1 ");
// White list, please synchronize the condition is empty, there is no qualified configuration // White list, please synchronize the condition is empty, there is no qualified configuration
if (configKeys.length == 0 && !blacklist) { if (configKeys.length == 0 && !blacklist) {
Page<ConfigInfo> page = new Page<ConfigInfo>(); Page<ConfigInfo> page = new Page<ConfigInfo>();
@ -1619,74 +1619,74 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
if (blacklist) { if (blacklist) {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " and "; where.append(" and ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id not like ? "; where.append(" data_id not like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " group_id not like ? "; where.append(" group_id not like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " app_name != ? "; where.append(" app_name != ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
else { else {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " or "; where.append(" or ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id like ? "; where.append(" data_id like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " group_id like ? "; where.append(" group_id like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " app_name = ? "; where.append(" app_name = ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
} }
PaginationHelper<ConfigInfo> helper = createPaginationHelper(); PaginationHelper<ConfigInfo> helper = createPaginationHelper();
return helper return helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), .fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(), params.toArray(),
pageNo, pageSize, CONFIG_INFO_ROW_MAPPER); pageNo, pageSize, CONFIG_INFO_ROW_MAPPER);
} }
@ -1769,7 +1769,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
String sqlCountRows = "select count(*) from config_info_aggr where "; 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 "; String sqlFetchRows = "select data_id,group_id,tenant_id,datum_id,app_name,content from config_info_aggr where ";
String where = " 1=1 "; StringBuilder where = new StringBuilder(" 1=1 ");
// White list, please synchronize the condition is empty, there is no qualified configuration // White list, please synchronize the condition is empty, there is no qualified configuration
if (configKeys.length == 0 && blacklist == false) { if (configKeys.length == 0 && blacklist == false) {
Page<ConfigInfoAggr> page = new Page<ConfigInfoAggr>(); Page<ConfigInfoAggr> page = new Page<ConfigInfoAggr>();
@ -1790,74 +1790,74 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
if (blacklist) { if (blacklist) {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " and "; where.append(" and ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id not like ? "; where.append(" data_id not like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " group_id not like ? "; where.append(" group_id not like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " app_name != ? "; where.append(" app_name != ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
else { else {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " or "; where.append(" or ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id like ? "; where.append(" data_id like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " group_id like ? "; where.append(" group_id like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " app_name = ? "; where.append(" app_name = ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
} }
PaginationHelper<ConfigInfoAggr> helper = createPaginationHelper(); PaginationHelper<ConfigInfoAggr> helper = createPaginationHelper();
return helper return helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), .fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(), params.toArray(),
pageNo, pageSize, CONFIG_INFO_AGGR_ROW_MAPPER); pageNo, pageSize, CONFIG_INFO_AGGR_ROW_MAPPER);
} }

View File

@ -1926,7 +1926,7 @@ public class ExternalStoragePersistServiceImpl implements PersistService {
final ConfigKey[] configKeys, final boolean blacklist) { final ConfigKey[] configKeys, final boolean blacklist) {
String sqlCountRows = "select count(*) from config_info where "; 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 "; String sqlFetchRows = "select ID,data_id,group_id,tenant_id,app_name,content from config_info where ";
String where = " 1=1 "; StringBuilder where = new StringBuilder(" 1=1 ");
// 白名单请同步条件为空则没有符合条件的配置 // 白名单请同步条件为空则没有符合条件的配置
if (configKeys.length == 0 && blacklist == false) { if (configKeys.length == 0 && blacklist == false) {
Page<ConfigInfo> page = new Page<ConfigInfo>(); Page<ConfigInfo> page = new Page<ConfigInfo>();
@ -1949,74 +1949,74 @@ public class ExternalStoragePersistServiceImpl implements PersistService {
if (blacklist) { if (blacklist) {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " and "; where.append(" and ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id not like ? "; where.append(" data_id not like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " group_id not like ? "; where.append(" group_id not like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " app_name != ? "; where.append(" app_name != ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
else { else {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " or "; where.append(" or ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id like ? "; where.append(" data_id like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " group_id like ? "; where.append(" group_id like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " app_name = ? "; where.append(" app_name = ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
} }
try { try {
return helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, return helper.fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(),
params.toArray(), pageNo, pageSize, CONFIG_INFO_ROW_MAPPER); params.toArray(), pageNo, pageSize, CONFIG_INFO_ROW_MAPPER);
} }
catch (CannotGetJdbcConnectionException e) { catch (CannotGetJdbcConnectionException e) {
@ -2168,7 +2168,7 @@ public class ExternalStoragePersistServiceImpl implements PersistService {
String sqlCountRows = "select count(*) from config_info_aggr where "; 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 "; String sqlFetchRows = "select data_id,group_id,tenant_id,datum_id,app_name,content from config_info_aggr where ";
String where = " 1=1 "; StringBuilder where = new StringBuilder(" 1=1 ");
// 白名单请同步条件为空则没有符合条件的配置 // 白名单请同步条件为空则没有符合条件的配置
if (configKeys.length == 0 && blacklist == false) { if (configKeys.length == 0 && blacklist == false) {
Page<ConfigInfoAggr> page = new Page<ConfigInfoAggr>(); Page<ConfigInfoAggr> page = new Page<ConfigInfoAggr>();
@ -2190,75 +2190,75 @@ public class ExternalStoragePersistServiceImpl implements PersistService {
if (blacklist) { if (blacklist) {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " and "; where.append(" and ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id not like ? "; where.append(" data_id not like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " group_id not like ? "; where.append(" group_id not like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " or "; where.append(" or ");
} }
where += " app_name != ? "; where.append(" app_name != ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
else { else {
if (isFirst) { if (isFirst) {
isFirst = false; isFirst = false;
where += " and "; where.append(" and ");
} }
else { else {
where += " or "; where.append(" or ");
} }
where += "("; where.append("(");
boolean isFirstSub = true; boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) { if (!StringUtils.isBlank(dataId)) {
where += " data_id like ? "; where.append(" data_id like ? ");
params.add(generateLikeArgument(dataId)); params.add(generateLikeArgument(dataId));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(group)) { if (!StringUtils.isBlank(group)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " group_id like ? "; where.append(" group_id like ? ");
params.add(generateLikeArgument(group)); params.add(generateLikeArgument(group));
isFirstSub = false; isFirstSub = false;
} }
if (!StringUtils.isBlank(appName)) { if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) { if (!isFirstSub) {
where += " and "; where.append(" and ");
} }
where += " app_name = ? "; where.append(" app_name = ? ");
params.add(appName); params.add(appName);
isFirstSub = false; isFirstSub = false;
} }
where += ") "; where.append(") ");
} }
} }
try { try {
Page<ConfigInfoAggr> result = helper Page<ConfigInfoAggr> result = helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, .fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(),
params.toArray(), pageNo, pageSize, params.toArray(), pageNo, pageSize,
CONFIG_INFO_AGGR_ROW_MAPPER); CONFIG_INFO_AGGR_ROW_MAPPER);
return result; return result;