Skip to content

Commit

Permalink
Support PolarDB-X.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyu-zzy authored and wenshao committed Nov 13, 2024
1 parent fdaad86 commit 6649929
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/com/alibaba/druid/DbType.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public enum DbType {
lealone(1L << 51),

athena(1L << 52),

polardbx(1L << 53),

ingres(0),
cloudscape(0),
timesten(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ protected void initCheck() throws SQLException {
|| JdbcUtils.MYSQL_DRIVER_603.equals(this.driverClass)
|| JdbcUtils.GOLDENDB_DRIVER.equals(this.driverClass)
|| JdbcUtils.GBASE8S_DRIVER.equals(this.driverClass)
|| JdbcUtils.POLARDBX_DRIVER.equals(this.driverClass)
) {
isMySql = true;
}
Expand Down Expand Up @@ -1118,6 +1119,9 @@ private void initExceptionSorter() {
} else if (realDriverClassName.equals(JdbcConstants.GOLDENDB_DRIVER)) {
this.exceptionSorter = new MySqlExceptionSorter();
this.isMySql = true;
} else if (realDriverClassName.equals(JdbcConstants.POLARDBX_DRIVER)) {
this.exceptionSorter = new MySqlExceptionSorter();
this.isMySql = true;
} else {
Class<?> superClass = driverClass.getSuperclass();
if (superClass != null && superClass != Object.class) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/alibaba/druid/sql/PagerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private static boolean limitQueryBlock(SQLSelect select, DbType dbType, int offs
case lealone:
case ads:
case clickhouse:
case polardbx:
return limitMySqlQueryBlock(queryBlock, dbType, offset, count, check);
case postgresql:
case greenplum:
Expand Down Expand Up @@ -548,6 +549,7 @@ private static SQLSelectQueryBlock createQueryBlock(DbType dbType) {
case mariadb:
case tidb:
case ads:
case polardbx:
return new MySqlSelectQueryBlock();
case oracle:
return new OracleSelectQueryBlock();
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/alibaba/druid/sql/SQLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ public static SQLASTOutputVisitor createFormatOutputVisitor(
case mysql:
case mariadb:
case tidb:
case polardbx:
return new MySqlOutputVisitor(out);
case postgresql:
case greenplum:
Expand Down Expand Up @@ -607,6 +608,7 @@ public static SchemaStatVisitor createSchemaStatVisitor(SchemaRepository reposit
case mariadb:
case tidb:
case elastic_search:
case polardbx:
return new MySqlSchemaStatVisitor(repository);
case postgresql:
case greenplum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public List<SQLObject> getChildren() {
DbType.trino,
DbType.postgresql,
DbType.mariadb,
DbType.tidb
DbType.tidb,
DbType.polardbx
);

public static boolean isSupport(DbType dbType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public List<SQLObject> getChildren() {
DbType.trino,
DbType.postgresql,
DbType.mariadb,
DbType.tidb
DbType.tidb,
DbType.polardbx
);

public static boolean isSupport(DbType dbType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public SQLDeleteStatement createSQLDeleteStatement() {
case mysql:
case mariadb:
case tidb:
case polardbx:
return new MySqlDeleteStatement();
case postgresql:
case greenplum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public SQLUpdateStatement createSQLUpdateStatement() {
case mysql:
case mariadb:
case tidb:
case polardbx:
return new MySqlUpdateStatement();
case oracle:
return new OracleUpdateStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public static SQLStatementParser createSQLStatementParser(String sql, DbType dbT
case mariadb:
case goldendb:
case oceanbase:
case drds: {
case drds:
case polardbx: {
return new MySqlStatementParser(sql, features);
}
case elastic_search: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ private SchemaResolveVisitor createResolveVisitor(SchemaResolveVisitor.Option...
case mariadb:
case tidb:
case sqlite:
case polardbx:
resolveVisitor = new SchemaResolveVisitorFactory.MySqlResolveVisitor(this, optionsValue);
break;
case oracle:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static ExportParameterVisitor createExportParameterVisitor(StringBuilder
case mysql:
case mariadb:
case tidb:
case polardbx:
return new MySqlExportParameterVisitor(out);
case oracle:
return new OracleExportParameterVisitor(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ public static ParameterizedVisitor createParameterizedOutputVisitor(StringBuilde
case oceanbase:
case drds:
case elastic_search:
case polardbx:
return new MySqlOutputVisitor(out, true);
case h2:
case lealone:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static SQLEvalVisitor createEvalVisitor(DbType dbType) {
case tidb:
case h2:
case lealone:
case polardbx:
return new MySqlEvalVisitorImpl();
case oracle:
return new OracleEvalVisitor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ protected SQLASTVisitor createOrderByVisitor(SQLOrderBy x) {
case mysql:
case mariadb:
case tidb:
case polardbx:
return new MySqlOrderByStatVisitor(x);
case postgresql:
case greenplum:
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/alibaba/druid/util/JdbcConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,6 @@ public interface JdbcConstants {
String OPENGAUSS_DRIVER = "org.opengauss.Driver";
String SUNDB = "sundb"; //科蓝数s据
String SUNDB_DRIVER = "csii.sundb.jdbc.SundbDriver";

String POLARDBX_DRIVER = "com.aliyun.polardbx.Driver";
}
7 changes: 7 additions & 0 deletions core/src/main/java/com/alibaba/druid/util/JdbcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ public static String getDriverClassName(String rawUrl) throws SQLException {
} else if (rawUrl.startsWith("jdbc:inspur:")) {
return JdbcConstants.KDB_DRIVER;
} else if (rawUrl.startsWith("jdbc:polardb")) {
if (rawUrl.startsWith("jdbc:polardbx:")) {
return JdbcConstants.POLARDBX_DRIVER;
}
return JdbcConstants.POLARDB_DRIVER;
} else if (rawUrl.startsWith("jdbc:highgo:")) {
return "com.highgo.jdbc.Driver";
Expand Down Expand Up @@ -657,6 +660,9 @@ public static DbType getDbTypeRaw(String rawUrl, String driverClassName) {
} else if (rawUrl.startsWith("jdbc:inspur:")) {
return DbType.kdb;
} else if (rawUrl.startsWith("jdbc:polardb")) {
if (rawUrl.startsWith("jdbc:polardbx:")) {
return DbType.polardbx;
}
return DbType.polardb;
} else if (rawUrl.startsWith("jdbc:highgo:")) {
return DbType.highgo;
Expand Down Expand Up @@ -992,6 +998,7 @@ public static boolean isMysqlDbType(DbType dbType) {
case h2:
case lealone:
case goldendb:
case polardbx:
return true;
default:
return false;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/alibaba/druid/wall/WallFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static WallProvider initWallProviderInternal(DataSourceProxy dataSource, String
case lealone:
case presto:
case trino:
case polardbx:
if (config == null) {
config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR);
}
Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/com/alibaba/druid/util/JdbcUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,15 @@ public void testGetTypeOceanBase_oracle() {
String dbType = JdbcUtils.getDbType(jdbcUrl, null);
assertEquals("Does not support OceanBase, for url like jdbc:oceanbase:oracle:...", DbType.oceanbase_oracle, dbType);
}

public void testGetDbTypePolarDBX() {
String jdbcUrl = "jdbc:polardbx://localhost:3306/test";
String dbType = JdbcUtils.getDbType(jdbcUrl, null);
assertEquals("Does not support PolarDB-X, for url like jdbc:polardbx:...", DbType.polardbx.name(), dbType);
}

public void testPolarDBXIsMySQLDBType() {
assertTrue("PolarDB-X suppose to be a MySQL compatible DB", JdbcUtils.isMysqlDbType(DbType.polardbx));
assertTrue("PolarDB-X suppose to be a MySQL compatible DB", JdbcUtils.isMysqlDbType("polardbx"));
}
}

0 comments on commit 6649929

Please sign in to comment.