Search in sources :

Example 6 with ConfigKey

use of com.alibaba.nacos.config.server.model.ConfigKey in project nacos by alibaba.

the class ExternalStoragePersistServiceImpl 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 ");
    // Whitelist, please leave the synchronization condition empty, there is no configuration that meets the conditions
    if (configKeys.length == 0 && blacklist == false) {
        Page<ConfigInfo> page = new Page<ConfigInfo>();
        page.setTotalCount(0);
        return page;
    }
    PaginationHelper<ConfigInfo> helper = createPaginationHelper();
    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(") ");
        }
    }
    try {
        return helper.fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(), params.toArray(), pageNo, pageSize, CONFIG_INFO_ROW_MAPPER);
    } catch (CannotGetJdbcConnectionException e) {
        LogUtil.FATAL_LOG.error("[db-error] " + e.toString(), e);
        throw e;
    }
}
Also used : ConfigKey(com.alibaba.nacos.config.server.model.ConfigKey) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) ArrayList(java.util.ArrayList) Page(com.alibaba.nacos.config.server.model.Page) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Aggregations

ConfigKey (com.alibaba.nacos.config.server.model.ConfigKey)6 Page (com.alibaba.nacos.config.server.model.Page)6 ArrayList (java.util.ArrayList)4 CannotGetJdbcConnectionException (org.springframework.jdbc.CannotGetJdbcConnectionException)3 ConfigInfo (com.alibaba.nacos.config.server.model.ConfigInfo)2 ConfigInfoAggr (com.alibaba.nacos.config.server.model.ConfigInfoAggr)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1