Search in sources :

Example 1 with ConfigKey

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);
}
Also used : ConfigKey(com.alibaba.nacos.config.server.model.ConfigKey) ConfigInfoAggr(com.alibaba.nacos.config.server.model.ConfigInfoAggr) ArrayList(java.util.ArrayList) Page(com.alibaba.nacos.config.server.model.Page)

Example 2 with ConfigKey

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);
}
Also used : ConfigKey(com.alibaba.nacos.config.server.model.ConfigKey) ArrayList(java.util.ArrayList) Page(com.alibaba.nacos.config.server.model.Page) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Example 3 with ConfigKey

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;
}
Also used : ConfigKey(com.alibaba.nacos.config.server.model.ConfigKey) Page(com.alibaba.nacos.config.server.model.Page)

Example 4 with ConfigKey

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;
    }
}
Also used : ConfigKey(com.alibaba.nacos.config.server.model.ConfigKey) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) ConfigInfoAggr(com.alibaba.nacos.config.server.model.ConfigInfoAggr) ArrayList(java.util.ArrayList) Page(com.alibaba.nacos.config.server.model.Page)

Example 5 with ConfigKey

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;
    }
}
Also used : ConfigKey(com.alibaba.nacos.config.server.model.ConfigKey) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) Page(com.alibaba.nacos.config.server.model.Page) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

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