|
16 | 16 |
|
17 | 17 | package com.alibaba.nacos.plugin.datasource.impl.mysql;
|
18 | 18 |
|
| 19 | +import com.alibaba.nacos.common.utils.ArrayUtils; |
19 | 20 | import com.alibaba.nacos.common.utils.CollectionUtils;
|
20 | 21 | import com.alibaba.nacos.common.utils.NamespaceUtil;
|
21 | 22 | import com.alibaba.nacos.common.utils.StringUtils;
|
22 | 23 | import com.alibaba.nacos.plugin.datasource.constants.ContextConstant;
|
23 | 24 | import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
|
24 | 25 | import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
25 | 26 | import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
|
| 27 | +import com.alibaba.nacos.plugin.datasource.mapper.ext.WhereBuilder; |
26 | 28 | import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
27 | 29 | import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
28 | 30 |
|
|
38 | 40 | **/
|
39 | 41 |
|
40 | 42 | public class ConfigInfoMapperByMySql extends AbstractMapperByMysql implements ConfigInfoMapper {
|
41 |
| - |
| 43 | + |
42 | 44 | private static final String DATA_ID = "dataId";
|
43 |
| - |
| 45 | + |
44 | 46 | private static final String GROUP = "group";
|
45 |
| - |
| 47 | + |
46 | 48 | private static final String APP_NAME = "appName";
|
47 |
| - |
| 49 | + |
48 | 50 | private static final String CONTENT = "content";
|
49 |
| - |
| 51 | + |
50 | 52 | private static final String TENANT = "tenant";
|
51 | 53 |
|
52 | 54 | @Override
|
@@ -83,9 +85,10 @@ public MapperResult findAllConfigKey(MapperContext context) {
|
83 | 85 |
|
84 | 86 | @Override
|
85 | 87 | public MapperResult findAllConfigInfoBaseFetchRows(MapperContext context) {
|
86 |
| - String sql = "SELECT t.id,data_id,group_id,content,md5" |
87 |
| - + " FROM ( SELECT id FROM config_info ORDER BY id LIMIT " + context.getStartRow() + "," |
88 |
| - + context.getPageSize() + " )" + " g, config_info t WHERE g.id = t.id "; |
| 88 | + String sql = |
| 89 | + "SELECT t.id,data_id,group_id,content,md5" + " FROM ( SELECT id FROM config_info ORDER BY id LIMIT " |
| 90 | + + context.getStartRow() + "," + context.getPageSize() + " )" |
| 91 | + + " g, config_info t WHERE g.id = t.id "; |
89 | 92 | return new MapperResult(sql, Collections.emptyList());
|
90 | 93 | }
|
91 | 94 |
|
@@ -228,33 +231,29 @@ public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) {
|
228 | 231 | final String group = (String) context.getWhereParameter(FieldConstant.GROUP_ID);
|
229 | 232 | final String appName = (String) context.getWhereParameter(FieldConstant.APP_NAME);
|
230 | 233 | final String content = (String) context.getWhereParameter(FieldConstant.CONTENT);
|
| 234 | + final String[] types = (String[]) context.getWhereParameter(FieldConstant.TYPE); |
231 | 235 |
|
232 |
| - List<Object> paramList = new ArrayList<>(); |
| 236 | + WhereBuilder where = new WhereBuilder( |
| 237 | + "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key,type FROM config_info"); |
| 238 | + where.like("tenant_id", tenant); |
233 | 239 |
|
234 |
| - final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info"; |
235 |
| - StringBuilder where = new StringBuilder(" WHERE "); |
236 |
| - where.append(" tenant_id LIKE ? "); |
237 |
| - paramList.add(tenant); |
238 |
| - |
239 |
| - if (!StringUtils.isBlank(dataId)) { |
240 |
| - where.append(" AND data_id LIKE ? "); |
241 |
| - paramList.add(dataId); |
242 |
| - |
| 240 | + if (StringUtils.isNotBlank(dataId)) { |
| 241 | + where.and().like("data_id", dataId); |
243 | 242 | }
|
244 |
| - if (!StringUtils.isBlank(group)) { |
245 |
| - where.append(" AND group_id LIKE ? "); |
246 |
| - paramList.add(group); |
| 243 | + if (StringUtils.isNotBlank(group)) { |
| 244 | + where.and().like("group_id", group); |
247 | 245 | }
|
248 |
| - if (!StringUtils.isBlank(appName)) { |
249 |
| - where.append(" AND app_name = ? "); |
250 |
| - paramList.add(appName); |
| 246 | + if (StringUtils.isNotBlank(appName)) { |
| 247 | + where.and().eq("app_name", appName); |
251 | 248 | }
|
252 |
| - if (!StringUtils.isBlank(content)) { |
253 |
| - where.append(" AND content LIKE ? "); |
254 |
| - paramList.add(content); |
| 249 | + if (StringUtils.isNotBlank(content)) { |
| 250 | + where.and().like("content", content); |
255 | 251 | }
|
256 |
| - return new MapperResult(sqlFetchRows + where + " LIMIT " + context.getStartRow() + "," + context.getPageSize(), |
257 |
| - paramList); |
| 252 | + if (!ArrayUtils.isEmpty(types)) { |
| 253 | + where.in("type", types); |
| 254 | + } |
| 255 | + where.limit(context.getStartRow(), context.getPageSize()); |
| 256 | + return where.build(); |
258 | 257 | }
|
259 | 258 |
|
260 | 259 | @Override
|
|
0 commit comments