Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #12342]: Improve the retrieval of ConfigInfoState to facilitate the extension and implementation of databases like Oracle. #12343

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,11 @@ public ConfigAllInfo findConfigAllInfo(final String dataId, final String group,
public ConfigInfoStateWrapper findConfigInfoState(final String dataId, final String group, final String tenant) {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
try {
return this.jt.queryForObject(
"SELECT id,data_id,group_id,tenant_id,gmt_modified FROM config_info WHERE data_id=? AND group_id=? AND tenant_id=?",
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
return this.jt.queryForObject(configInfoMapper.select(
Arrays.asList("id", "data_id", "group_id", "tenant_id", "gmt_modified"),
Arrays.asList("data_id", "group_id", "tenant_id")),
new Object[] {dataId, group, tenantTmp}, CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER);
} catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null.
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper;
import com.alibaba.nacos.sys.env.EnvUtil;
Expand Down Expand Up @@ -1093,7 +1094,7 @@ void testFindConfigInfoState() {
assertTrue(e.getMessage().endsWith("mock exp"));
}
}

@Test
void testFindAllConfigInfo4Export() {

Expand Down Expand Up @@ -1229,5 +1230,16 @@ void testFindAllConfigInfoFragment() {
}

}

@Test
void testBuildFindConfigInfoStateSql() {
MapperManager mapperManager = MapperManager.instance(false);
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
String select = configInfoMapper.select(
Arrays.asList("id", "data_id", "group_id", "tenant_id", "gmt_modified"),
Arrays.asList("data_id", "group_id", "tenant_id"));
assertEquals("SELECT id,data_id,group_id,tenant_id,gmt_modified FROM config_info WHERE data_id = ? AND group_id = ? AND tenant_id = ?", select);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,8 @@ public String update(List<String> columns, List<String> where) {
public String delete(List<String> params) {
StringBuilder sql = new StringBuilder();
String method = "DELETE ";
sql.append(method).append("FROM ").append(getTableName()).append(" ").append("WHERE ");
for (int i = 0; i < params.size(); i++) {
sql.append(params.get(i)).append(" ").append("=").append(" ? ");
if (i != params.size() - 1) {
sql.append("AND ");
}
}
sql.append(method).append("FROM ").append(getTableName()).append(" ");
appendWhereClause(params, sql);

return sql.toString();
}
Expand Down Expand Up @@ -155,7 +150,7 @@ public String[] getPrimaryKeyGeneratedKeys() {
return new String[]{"id"};
}

private void appendWhereClause(List<String> where, StringBuilder sql) {
protected void appendWhereClause(List<String> where, StringBuilder sql) {
sql.append("WHERE ");
for (int i = 0; i < where.size(); i++) {
sql.append(where.get(i)).append(" = ").append("?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void testUpdate() {
@Test
void testDelete() {
String sql = abstractMapper.delete(Arrays.asList("id"));
assertEquals("DELETE FROM tenant_info WHERE id = ? ", sql);
assertEquals("DELETE FROM tenant_info WHERE id = ?", sql);
}

@Test
Expand Down