mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Add OceanBaseValidConnectionChecker and fix oceanbase dbtype
This commit is contained in:
@@ -1333,7 +1333,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|| realDriverClassName.equals(JdbcConstants.ENTERPRISEDB_DRIVER)
|
||||
|| realDriverClassName.equals(JdbcConstants.POLARDB_DRIVER)) {
|
||||
this.validConnectionChecker = new PGValidConnectionChecker();
|
||||
} else if (realDriverClassName.equals(JdbcConstants.OCEANBASE_DRIVER)
|
||||
|| (realDriverClassName.equals(JdbcConstants.OCEANBASE_DRIVER2))) {
|
||||
DbType dbType = DbType.of(this.dbTypeName);
|
||||
this.validConnectionChecker = new OceanBaseValidConnectionChecker(dbType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initExceptionSorter() {
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.pool.vendor;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.pool.ValidConnectionChecker;
|
||||
import com.alibaba.druid.pool.ValidConnectionCheckerAdapter;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import sun.security.pkcs11.Secmod;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class OceanBaseValidConnectionChecker extends ValidConnectionCheckerAdapter implements ValidConnectionChecker {
|
||||
private String oracleModeValidateQuery = "SELECT 'x' FROM DUAL";
|
||||
private String mysqlModeValidateQuery = "SELECT 'x'";
|
||||
private DbType dbType;
|
||||
public OceanBaseValidConnectionChecker() { configFromProperties(System.getProperties()); dbType = null; }
|
||||
public OceanBaseValidConnectionChecker(DbType dbType) {this.dbType = dbType;configFromProperties(System.getProperties()); }
|
||||
public boolean isValidConnection(final Connection c, String validateQuery, int validationQueryTimeout) throws Exception {
|
||||
if (c.isClosed()) {
|
||||
return false;
|
||||
}
|
||||
if (validateQuery == null || validateQuery.isEmpty()) {
|
||||
if(dbType != null) {
|
||||
if(dbType == DbType.oceanbase) {
|
||||
validateQuery = mysqlModeValidateQuery;
|
||||
} else {
|
||||
validateQuery = oracleModeValidateQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Statement stmt = null;
|
||||
|
||||
try {
|
||||
stmt = c.createStatement();
|
||||
if (validationQueryTimeout > 0) {
|
||||
stmt.setQueryTimeout(validationQueryTimeout);
|
||||
}
|
||||
stmt.execute(validateQuery);
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
JdbcUtils.close(stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,7 @@ public interface JdbcConstants {
|
||||
DbType OCEANBASE = DbType.oceanbase;
|
||||
DbType OCEANBASE_ORACLE = DbType.oceanbase_oracle;
|
||||
String OCEANBASE_DRIVER = "com.alipay.oceanbase.jdbc.Driver";
|
||||
String OCEANBASE_DRIVER2 = "com.oceanbase.jdbc.Driver";
|
||||
|
||||
DbType INFORMIX = DbType.informix;
|
||||
|
||||
@@ -150,4 +151,5 @@ public interface JdbcConstants {
|
||||
*/
|
||||
DbType OSCAR = DbType.oscar;
|
||||
String OSCAR_DRIVER = "com.oscar.Driver";
|
||||
|
||||
}
|
||||
|
||||
@@ -928,13 +928,13 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
|
||||
public static boolean isOracleDbType(String dbType) {
|
||||
return DbType.oracle.name().equals(dbType) || //
|
||||
DbType.oceanbase.name().equals(dbType) || //
|
||||
DbType.oceanbase_oracle.name().equals(dbType) || //
|
||||
DbType.ali_oracle.name().equalsIgnoreCase(dbType);
|
||||
}
|
||||
|
||||
public static boolean isOracleDbType(DbType dbType) {
|
||||
return DbType.oracle == dbType || //
|
||||
DbType.oceanbase == dbType || //
|
||||
DbType.oceanbase_oracle == dbType || //
|
||||
DbType.ali_oracle == dbType;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user