Skip to content

Commit

Permalink
[impr]同步更改为nacos2.2正式版的postgresql的插件适配
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchubuzai2018 committed Dec 15, 2022
1 parent fc7fc57 commit ff9717e
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 185 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant;

/**
* mysql database dialect.
* defauLT database dialect.
* @author Long Yu
*/
public class MysqlDatabaseDialect extends AbstractDatabaseDialect {
public class DefaultDatabaseDialect extends AbstractDatabaseDialect {

@Override
public String getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ public String getTableName() {
return TableConstant.CONFIG_INFO_AGGR;
}

public String getLimitPageSqlWithMark(String sql) {
return databaseDialect.getLimitPageSqlWithMark(sql);
}

@Override
public String findConfigInfoAggrByPageFetchRows(int startRow, int pageSize) {
return getLimitPageSqlWithMark("SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
+ "group_id= ? AND tenant_id= ? ORDER BY datum_id ");
return databaseDialect.getLimitPageSqlWithOffset(
"SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE data_id= ? AND "
+ "group_id= ? AND tenant_id= ? ORDER BY datum_id ", startRow, pageSize);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ public String getLimitPageSqlWithMark(String sql) {
return databaseDialect.getLimitPageSqlWithMark(sql);
}

@Override
public String findConfigInfoByDataIdFetchRows(int startRow, int pageSize) {
return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info "
+ "WHERE data_id = ? AND tenant_id = ? ",startRow, pageSize);
}


@Override
public String findConfigInfoByDataIdAndAppFetchRows(int startRow, int pageSize) {
return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info "
+ "WHERE data_id= ? AND tenant_id= ? AND app_name= ?",startRow, pageSize);
}

@Override
public String findConfigInfoByAppFetchRows(int startRow, int pageSize) {
return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info"
Expand Down Expand Up @@ -101,14 +88,6 @@ public String findAllConfigInfoBaseFetchRows(int startRow, int pageSize) {
+ " g, config_info t WHERE g.id = t.id ";
}

@Override
public String findAllConfigInfoForDumpAllFetchRows(int startRow, int pageSize) {
String innerSql = getLimitPageSqlWithMark(" SELECT id FROM config_info ORDER BY id ");
return " SELECT t.id,type,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified "
+ " FROM ( " + innerSql + " )"
+ " g, config_info t WHERE g.id = t.id ";
}

@Override
public String findAllConfigInfoFragment(int startRow, int pageSize) {
return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "
Expand Down Expand Up @@ -156,27 +135,6 @@ public String listGroupKeyMd5ByPageFetchRows(int startRow, int pageSize) {
+ "( " + innerSql + " ) g, config_info t WHERE g.id = t.id";
}

@Override
public String findConfigInfoLikeFetchRows(Map<String, String> params, int startRow, int pageSize) {
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE ";
String where = " 1=1 ";
if (!StringUtils.isEmpty(params.get(DATA_ID))) {
where += " AND data_id LIKE ? ";
}
if (!StringUtils.isEmpty(params.get(GROUP))) {
where += " AND group_id LIKE ? ";
}
where += " AND tenant_id LIKE ? ";
if (!StringUtils.isEmpty(params.get(APP_NAME))) {
where += " AND app_name = ? ";
}
if (!StringUtils.isBlank(params.get(CONTENT))) {
where += " AND content LIKE ? ";
}

return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
}

@Override
public String findConfigInfoBaseLikeFetchRows(Map<String, String> params, int startRow, int pageSize) {
final String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE ";
Expand All @@ -193,17 +151,6 @@ public String findConfigInfoBaseLikeFetchRows(Map<String, String> params, int st
return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
}

@Override
public String findConfigInfoByDataIdAndAdvanceFetchRows(Map<String, String> params, int startRow, int pageSize) {
final String appName = params.get(APP_NAME);
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE data_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return getLimitPageSqlWithOffset(sql.toString(), startRow, pageSize);
}

@Override
public String findConfigInfo4PageFetchRows(Map<String, String> params, int startRow, int pageSize) {
final String appName = params.get(APP_NAME);
Expand All @@ -224,34 +171,6 @@ public String findConfigInfo4PageFetchRows(Map<String, String> params, int start
return getLimitPageSqlWithOffset(sql + where, startRow, pageSize);
}

@Override
public String findConfigInfoBaseByDataIdFetchRows(int startRow, int pageSize) {
return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,content FROM config_info WHERE data_id=? AND tenant_id=? ",startRow, pageSize);
}

@Override
public String findConfigInfoByGroupFetchRows(int startRow, int pageSize) {
return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE"
+ " group_id=? AND tenant_id=? ",startRow, pageSize);
}

@Override
public String findConfigInfoByGroupAndAppFetchRows(int startRow, int pageSize) {
return getLimitPageSqlWithOffset("SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE "
+ "group_id=? AND tenant_id=? AND app_name =? ",startRow, pageSize);
}

@Override
public String findConfigInfoByAdvanceFetchRows(Map<String, String> params, int startRow, int pageSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE ? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return getLimitPageSqlWithOffset(sql.toString(),startRow, pageSize);
}

@Override
public String findConfigInfoBaseByGroupFetchRows(int startRow, int pageSize) {
String sql = "SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? ";
Expand Down Expand Up @@ -290,17 +209,6 @@ public String findAllConfigInfoFetchRows(int startRow, int pageSize) {
+ " g, config_info t WHERE g.id = t.id ";
}

@Override
public String findConfigInfoByGroupAndAdvanceFetchRows(Map<String, String> params, int startRow, int pageSize) {
final String appName = params.get(APP_NAME);
StringBuilder sql = new StringBuilder(
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE group_id=? AND tenant_id=? ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND app_name=? ");
}
return getLimitPageSqlWithOffset(sql.toString(),startRow, pageSize);
}

@Override
public String getTableName() {
return TableConstant.CONFIG_INFO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ public BaseConfigInfoTagMapper() {
databaseDialect = DatabaseDialectManager.getInstance().getDialect(getDataSource());
}

public String getLimitPageSqlWithMark(String sql) {
return databaseDialect.getLimitPageSqlWithMark(sql);
}

@Override
public String getTableName() {
return TableConstant.CONFIG_INFO_TAG;
}

@Override
public String findAllConfigInfoTagForDumpAllFetchRows(int startRow, int pageSize) {
String innerSql = getLimitPageSqlWithMark("SELECT id FROM config_info_tag ORDER BY id ");
String innerSql = databaseDialect.getLimitPageSqlWithOffset("SELECT id FROM config_info_tag ORDER BY id ",
startRow, pageSize);
return " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified "
+ " FROM ( " + innerSql + " ) "
+ "g, config_info_tag t WHERE g.id = t.id ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,6 @@ public String findConfigInfo4PageFetchRows(Map<String, String> params, int tagSi
return getLimitPageSqlWithOffset(sql + where,startRow,pageSize);
}

@Override
public String findConfigInfoByGroupAndAdvanceFetchRows(final Map<String, String> params, int tagSize, int startRow, int pageSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.group_id=? AND a.tenant_id=? ");

sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");

if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}

return getLimitPageSqlWithOffset(sql.toString(),startRow,pageSize);
}

@Override
public String findConfigInfoLike4PageFetchRows(final Map<String, String> params, int tagSize, int startRow, int pageSize) {
final String appName = params.get("appName");
Expand Down Expand Up @@ -134,28 +111,7 @@ public String findConfigInfoLike4PageFetchRows(final Map<String, String> params,
where.append('?');
}
where.append(") ");
return getLimitPageSqlWithOffset(sqlFetchRows + where,startRow,pageSize);
}

@Override
public String findConfigInfoByAdvanceFetchRows(Map<String, String> params, int tagSize, int startRow, int pageSize) {
final String appName = params.get("appName");
StringBuilder sql = new StringBuilder(
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
+ "config_tags_relation b ON a.id=b.id WHERE a.tenant_id=? ");
sql.append(" AND b.tag_name IN (");
for (int i = 0; i < tagSize; i++) {
if (i != 0) {
sql.append(", ");
}
sql.append('?');
}
sql.append(") ");
if (StringUtils.isNotBlank(appName)) {
sql.append(" AND a.app_name=? ");
}
return getLimitPageSqlWithOffset(sql.toString(),startRow,pageSize);
return getLimitPageSqlWithOffset(sqlFetchRows + where, startRow, pageSize);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.alibaba.nacos.common.spi.NacosServiceLoader;
import com.alibaba.nacos.plugin.datasource.dialect.DatabaseDialect;
import com.alibaba.nacos.plugin.datasource.dialect.MysqlDatabaseDialect;
import com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -56,7 +56,7 @@ private DatabaseDialectManager() {
public DatabaseDialect getDialect(String databaseType) {
DatabaseDialect databaseDialect = SUPPORT_DIALECT_MAP.get(databaseType);
if (databaseDialect == null) {
return new MysqlDatabaseDialect();
return new DefaultDatabaseDialect();
}
return databaseDialect;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
#
#

com.alibaba.nacos.plugin.datasource.dialect.MysqlDatabaseDialect
com.alibaba.nacos.plugin.datasource.dialect.DefaultDatabaseDialect

1 change: 0 additions & 1 deletion nacos-datasource-plugin-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

<modules>
<module>nacos-datasource-plugin-ext-base</module>
<module>nacos-all-datasource-plugin-ext</module>
<module>nacos-postgresql-datasource-plugin-ext</module>
</modules>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<alibaba-nacos.version>2.2.0-BETA</alibaba-nacos.version>
<alibaba-nacos.version>2.2.0</alibaba-nacos.version>
<maven-flatten-version>1.1.0</maven-flatten-version>
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
<junit.version>4.12</junit.version>
Expand Down

0 comments on commit ff9717e

Please sign in to comment.