mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -1316,7 +1316,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.validConnectionChecker = new MSSQLValidConnectionChecker();
|
||||
|
||||
} else if (realDriverClassName.equals(JdbcConstants.POSTGRESQL_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)) {
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.POLARDB_DRIVER)) {
|
||||
this.validConnectionChecker = new PGValidConnectionChecker();
|
||||
}
|
||||
}
|
||||
@@ -1347,7 +1348,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.exceptionSorter = new SybaseExceptionSorter();
|
||||
|
||||
} else if (realDriverClassName.equals(JdbcConstants.POSTGRESQL_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)) {
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.POLARDB_DRIVER)) {
|
||||
this.exceptionSorter = new PGExceptionSorter();
|
||||
|
||||
} else if (realDriverClassName.equals("com.alibaba.druid.mock.MockDriver")) {
|
||||
|
||||
@@ -899,7 +899,8 @@ public class SQLUtils {
|
||||
return name;
|
||||
}
|
||||
} else if (JdbcConstants.POSTGRESQL.equals(dbType)
|
||||
|| JdbcConstants.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcConstants.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcConstants.POLARDB.equals(dbType)) {
|
||||
if (PGUtils.isKeyword(normalizeName)) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,8 @@ public class SQLParserUtils {
|
||||
}
|
||||
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGSQLStatementParser(sql);
|
||||
}
|
||||
|
||||
@@ -129,7 +130,8 @@ public class SQLParserUtils {
|
||||
}
|
||||
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGExprParser(sql);
|
||||
}
|
||||
|
||||
@@ -164,7 +166,8 @@ public class SQLParserUtils {
|
||||
}
|
||||
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGLexer(sql);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ public final class ExportParameterVisitorUtils {
|
||||
}
|
||||
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGExportParameterVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +276,8 @@ public class ParameterizedOutputVisitorUtils {
|
||||
}
|
||||
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
return new PGOutputVisitor(out, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,8 @@ public class SQLEvalVisitorUtils {
|
||||
}
|
||||
|
||||
if (JdbcConstants.POSTGRESQL.equals(dbType)
|
||||
|| JdbcConstants.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcConstants.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcConstants.POLARDB.equals(dbType)) {
|
||||
return new PGEvalVisitor();
|
||||
}
|
||||
|
||||
|
||||
@@ -117,4 +117,10 @@ public interface JdbcConstants {
|
||||
|
||||
String CLICKHOUSE = "clickhouse";
|
||||
String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
|
||||
|
||||
/**
|
||||
* Aliyun PolarDB
|
||||
*/
|
||||
String POLARDB = "polardb";
|
||||
String POLARDB_DRIVER = "com.aliyun.polardb.Driver";
|
||||
}
|
||||
|
||||
@@ -493,7 +493,9 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return JdbcConstants.CLICKHOUSE_DRIVER;
|
||||
} else if(rawUrl.startsWith("jdbc:presto:")) {
|
||||
return JdbcConstants.PRESTO_DRIVER;
|
||||
}else {
|
||||
} else if (rawUrl.startsWith("jdbc:polardb")) {
|
||||
return JdbcConstants.POLARDB_DRIVER;
|
||||
} else {
|
||||
throw new SQLException("unknown jdbc driver : " + rawUrl);
|
||||
}
|
||||
}
|
||||
@@ -586,8 +588,10 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return ELASTIC_SEARCH;
|
||||
} else if (rawUrl.startsWith("jdbc:clickhouse:")) {
|
||||
return CLICKHOUSE;
|
||||
}else if (rawUrl.startsWith("jdbc:presto:")) {
|
||||
} else if (rawUrl.startsWith("jdbc:presto:")) {
|
||||
return PRESTO;
|
||||
} else if (rawUrl.startsWith("jdbc:polardb")) {
|
||||
return POLARDB;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,8 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
|
||||
|
||||
provider = new SQLServerWallProvider(config);
|
||||
} else if (JdbcUtils.POSTGRESQL.equals(dbType)
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)) {
|
||||
|| JdbcUtils.ENTERPRISEDB.equals(dbType)
|
||||
|| JdbcUtils.POLARDB.equals(dbType)) {
|
||||
if (config == null) {
|
||||
config = new WallConfig(PGWallProvider.DEFAULT_CONFIG_DIR);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.alibaba.druid.polardb;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class PolarDBDataSourceTest extends TestCase {
|
||||
|
||||
private String jdbcUrl;
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jdbcUrl = "jdbc:polardb://a.b.c.d:5432/polardb";
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setUsername("polardb");
|
||||
dataSource.setPassword("polardb");
|
||||
dataSource.setValidationQuery("select 1");
|
||||
dataSource.setFilters("stat");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void testDataSource() throws SQLException {
|
||||
dataSource.init();
|
||||
|
||||
Assert.assertTrue(JdbcConstants.POLARDB.equals(dataSource.getDbType()));
|
||||
Assert.assertTrue(JdbcConstants.POLARDB_DRIVER.equals(dataSource.getDriverClassName()));
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT 1");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while(rs.next()) {
|
||||
|
||||
}
|
||||
JdbcUtils.close(rs);
|
||||
JdbcUtils.close(stmt);
|
||||
JdbcUtils.close(conn);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user