Skip to content

Commit

Permalink
[alibaba#11035] (PR-4/4) config module, alternate string method. (ali…
Browse files Browse the repository at this point in the history
  • Loading branch information
IJiaPu authored Sep 22, 2023
1 parent f79868f commit a9d303c
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -365,7 +364,7 @@ public void run() {
RequestUtil
.getRemoteIp((HttpServletRequest) clientSub.asyncContext.getRequest()),
"polling", clientSub.clientMd5Map.size(), clientSub.probeRequestSize, groupKey);
clientSub.sendResponse(Arrays.asList(groupKey));
clientSub.sendResponse(Collections.singletonList(groupKey));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG;
Expand Down Expand Up @@ -99,7 +100,7 @@ public GroupCapacity getGroupCapacity(String groupId) {
TableConstant.GROUP_CAPACITY);
String sql = groupCapacityMapper.select(
Arrays.asList("id", "quota", "`usage`", "`max_size`", "max_aggr_count", "max_aggr_size", "group_id"),
Arrays.asList("group_id"));
Collections.singletonList("group_id"));
List<GroupCapacity> list = jdbcTemplate.query(sql, new Object[] {groupId}, GROUP_CAPACITY_ROW_MAPPER);
if (list.isEmpty()) {
return null;
Expand Down Expand Up @@ -374,7 +375,7 @@ public boolean deleteGroupCapacity(final String group) {
TableConstant.GROUP_CAPACITY);
PreparedStatementCreator preparedStatementCreator = connection -> {
PreparedStatement ps = connection.prepareStatement(
groupCapacityMapper.delete(Arrays.asList("group_id")));
groupCapacityMapper.delete(Collections.singletonList("group_id")));
ps.setString(1, group);
return ps;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public Page<ConfigInfoAggr> findConfigInfoAggrByPage(String dataId, String group
ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_AGGR);
final int startRow = (pageNo - 1) * pageSize;
final String sqlCountRows = configInfoAggrMapper.select(Arrays.asList("count(*)"),
final String sqlCountRows = configInfoAggrMapper.select(Collections.singletonList("count(*)"),
Arrays.asList("data_id", "group_id", "tenant_id"));

MapperContext context = new MapperContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ private ConfigOperateResult getBetaOperateResult(String dataId, String group, St

@Override
public ConfigOperateResult addConfigInfo4Beta(ConfigInfo configInfo, String betaIps, String srcIp, String srcUser) {
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
String encryptedDataKey = StringUtils.isBlank(configInfo.getEncryptedDataKey()) ? StringUtils.EMPTY
: configInfo.getEncryptedDataKey();
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
String encryptedDataKey = StringUtils.defaultEmptyIfBlank(configInfo.getEncryptedDataKey());

configInfo.setTenant(tenantTmp);
try {
Expand Down Expand Up @@ -195,10 +194,9 @@ public void removeConfigInfo4Beta(final String dataId, final String group, final
@Override
public ConfigOperateResult updateConfigInfo4Beta(ConfigInfo configInfo, String betaIps, String srcIp,
String srcUser) {
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
String encryptedDataKey = StringUtils.isBlank(configInfo.getEncryptedDataKey()) ? StringUtils.EMPTY
: configInfo.getEncryptedDataKey();
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
String encryptedDataKey = StringUtils.defaultEmptyIfBlank(configInfo.getEncryptedDataKey());

configInfo.setTenant(tenantTmp);
try {
Expand Down Expand Up @@ -227,9 +225,9 @@ public ConfigOperateResult updateConfigInfo4Beta(ConfigInfo configInfo, String b
@Override
public ConfigOperateResult updateConfigInfo4BetaCas(ConfigInfo configInfo, String betaIps, String srcIp,
String srcUser) {
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());

configInfo.setTenant(tenantTmp);
try {
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,8 @@ public ConfigOperateResult insertOrUpdateCas(String srcIp, String srcUser, Confi
@Override
public long addConfigInfoAtomic(final long id, final String srcIp, final String srcUser,
final ConfigInfo configInfo, Map<String, Object> configAdvanceInfo) {
final String appNameTmp =
StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
final String tenantTmp =
StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
final String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
final String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
final String desc = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("desc");
final String use = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("use");
final String effect = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("effect");
Expand Down Expand Up @@ -460,7 +458,7 @@ public List<ConfigInfo> removeConfigInfoByIds(final List<Long> ids, final String
public void removeTagByIdAtomic(long id) {
ConfigTagsRelationMapper configTagsRelationMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.CONFIG_TAGS_RELATION);
final String sql = configTagsRelationMapper.delete(Arrays.asList("id"));
final String sql = configTagsRelationMapper.delete(Collections.singletonList("id"));
final Object[] args = new Object[] {id};
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
Expand Down Expand Up @@ -585,10 +583,8 @@ public ConfigOperateResult updateConfigInfoCas(final ConfigInfo configInfo, fina

private ConfigOperateResult updateConfigInfoAtomicCas(final ConfigInfo configInfo, final String srcIp,
final String srcUser, Map<String, Object> configAdvanceInfo) {
final String appNameTmp =
StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
final String tenantTmp =
StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
final String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
final String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
final String desc = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("desc");
final String use = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("use");
Expand Down Expand Up @@ -626,10 +622,8 @@ private ConfigOperateResult updateConfigInfoAtomicCas(final ConfigInfo configInf
@Override
public void updateConfigInfoAtomic(final ConfigInfo configInfo, final String srcIp, final String srcUser,
Map<String, Object> configAdvanceInfo) {
final String appNameTmp =
StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
final String tenantTmp =
StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
final String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
final String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
final String desc = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("desc");
final String use = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("use");
Expand Down Expand Up @@ -659,7 +653,7 @@ public void updateMd5(String dataId, String group, String tenant, String md5, Ti
try {
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
final String sql = configInfoMapper.update(Arrays.asList("md5"),
final String sql = configInfoMapper.update(Collections.singletonList("md5"),
Arrays.asList("data_id", "group_id", "tenant_id", "gmt_modified"));
final Object[] args = new Object[] {md5, dataId, group, tenantTmp, lastTime};

Expand Down Expand Up @@ -1161,7 +1155,7 @@ public Page<ConfigInfoWrapper> findChangeConfig(final String dataId, final Strin
public List<String> selectTagByConfig(String dataId, String group, String tenant) {
ConfigTagsRelationMapper configTagsRelationMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.CONFIG_TAGS_RELATION);
String sql = configTagsRelationMapper.select(Arrays.asList("tag_name"),
String sql = configTagsRelationMapper.select(Collections.singletonList("tag_name"),
Arrays.asList("data_id", "group_id", "tenant_id"));
return databaseOperate.queryMany(sql, new Object[] {dataId, group, tenant}, String.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER;
Expand Down Expand Up @@ -103,8 +104,7 @@ public ConfigInfoStateWrapper findConfigInfo4TagState(final String dataId, final
}

private ConfigOperateResult getTagOperateResult(String dataId, String group, String tenant, String tag) {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;

String tenantTmp = StringUtils.defaultEmptyIfBlank(tenant);
ConfigInfoStateWrapper configInfo4Tag = this.findConfigInfo4TagState(dataId, group, tenantTmp, tag);
if (configInfo4Tag == null) {
return new ConfigOperateResult(false);
Expand All @@ -115,8 +115,8 @@ private ConfigOperateResult getTagOperateResult(String dataId, String group, Str

@Override
public ConfigOperateResult addConfigInfo4Tag(ConfigInfo configInfo, String tag, String srcIp, String srcUser) {
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim();

configInfo.setTenant(tenantTmp);
Expand Down Expand Up @@ -186,8 +186,8 @@ public void removeConfigInfoTag(final String dataId, final String group, final S

@Override
public ConfigOperateResult updateConfigInfo4Tag(ConfigInfo configInfo, String tag, String srcIp, String srcUser) {
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim();

configInfo.setTenant(tenantTmp);
Expand Down Expand Up @@ -219,8 +219,8 @@ public ConfigOperateResult updateConfigInfo4Tag(ConfigInfo configInfo, String ta
@Override
public ConfigOperateResult updateConfigInfo4TagCas(ConfigInfo configInfo, String tag, String srcIp,
String srcUser) {
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim();

configInfo.setTenant(tenantTmp);
Expand Down Expand Up @@ -309,7 +309,7 @@ public List<String> findConfigInfoTags(String dataId, String group, String tenan
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
ConfigInfoTagMapper configInfoTagMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_TAG);
final String sql = configInfoTagMapper.select(Arrays.asList("tag_id"),
final String sql = configInfoTagMapper.select(Collections.singletonList("tag_id"),
Arrays.asList("data_id", "group_id", "tenant_id"));

return databaseOperate.queryMany(sql, new Object[] {dataId, group, tenantTmp}, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ public List<ConfigInfoWrapper> convertDeletedConfig(List<Map<String, Object>> li
@Override
public void insertConfigHistoryAtomic(long configHistoryId, ConfigInfo configInfo, String srcIp, String srcUser,
final Timestamp time, String ops) {
String appNameTmp = StringUtils.isBlank(configInfo.getAppName()) ? StringUtils.EMPTY : configInfo.getAppName();
String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
String encryptedDataKey = StringUtils.isBlank(configInfo.getEncryptedDataKey()) ? StringUtils.EMPTY
: configInfo.getEncryptedDataKey();

String encryptedDataKey = StringUtils.defaultEmptyIfBlank(configInfo.getEncryptedDataKey());

HistoryConfigInfoMapper historyConfigInfoMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
final String sql = historyConfigInfoMapper.insert(
Expand Down
Loading

0 comments on commit a9d303c

Please sign in to comment.