Browse Source

Merge pull request #6199 in CORE/base-third from release/11.0 to bugfix/11.0

* commit '721bf03e601436a6fbc4eb4b474dff15c4b6b0b8':
  REPORT-74418 informix等老驱动未实现部分Connection接口导致druid创建线程退出
bugfix/11.0
superman 2 years ago
parent
commit
8738beafdc
  1. 59
      fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidConnectionHolder.java

59
fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidConnectionHolder.java

@ -27,12 +27,14 @@ import javax.sql.ConnectionEventListener;
import javax.sql.StatementEventListener; import javax.sql.StatementEventListener;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -41,6 +43,8 @@ import java.util.concurrent.locks.ReentrantLock;
*/ */
public final class DruidConnectionHolder { public final class DruidConnectionHolder {
private final static Log LOG = LogFactory.getLog(DruidConnectionHolder.class); private final static Log LOG = LogFactory.getLog(DruidConnectionHolder.class);
static Set<DbType> holdabilityUnsupportedDbTypes = new HashSet<>(Arrays.asList(DbType.sybase, DbType.db2, DbType.hive, DbType.odps));
public static boolean holdabilityUnsupported = false; public static boolean holdabilityUnsupported = false;
protected final DruidAbstractDataSource dataSource; protected final DruidAbstractDataSource dataSource;
@ -101,53 +105,46 @@ public final class DruidConnectionHolder {
this.lastActiveTimeMillis = connectTimeMillis; this.lastActiveTimeMillis = connectTimeMillis;
this.lastExecTimeMillis = connectTimeMillis; this.lastExecTimeMillis = connectTimeMillis;
this.underlyingAutoCommit = conn.getAutoCommit();
if (conn instanceof WrapperProxy) { if (conn instanceof WrapperProxy) {
this.connectionId = ((WrapperProxy) conn).getId(); this.connectionId = ((WrapperProxy) conn).getId();
} else { } else {
this.connectionId = dataSource.createConnectionId(); this.connectionId = dataSource.createConnectionId();
} }
{
boolean initUnderlyHoldability = !holdabilityUnsupported; // 下面是一些驱动的默认值,reset时用到
// autoCommit
this.underlyingAutoCommit = conn.getAutoCommit();
// holdability
DbType dbType = DbType.of(dataSource.dbTypeName); DbType dbType = DbType.of(dataSource.dbTypeName);
if (dbType == DbType.sybase // boolean initUnderlyingHoldability = !holdabilityUnsupported;
|| dbType == DbType.db2 // if (holdabilityUnsupportedDbTypes.contains(dbType)) {
|| dbType == DbType.hive // initUnderlyingHoldability = false;
|| dbType == DbType.odps // }
) {
initUnderlyHoldability = false; if (initUnderlyingHoldability) {
}
if (initUnderlyHoldability) {
try { try {
this.underlyingHoldability = conn.getHoldability(); this.underlyingHoldability = conn.getHoldability();
} catch (UnsupportedOperationException | AbstractMethodError | SQLFeatureNotSupportedException e) {
holdabilityUnsupported = true;
LOG.warn("getHoldability unsupported", e);
} catch (SQLException e) {
// bug fixed for hive jdbc-driver
if ("Method not supported".equals(e.getMessage())) {
holdabilityUnsupported = true;
}
LOG.warn("getHoldability error", e);
} catch (Throwable e) { } catch (Throwable e) {
holdabilityUnsupported = true;
LOG.warn("getHoldability error", e); LOG.warn("getHoldability error", e);
} }
} }
}
// readOnly
try {
this.underlyingReadOnly = conn.isReadOnly(); this.underlyingReadOnly = conn.isReadOnly();
} catch (Throwable e) {
LOG.warn("isReadOnly error", e);
}
// transactionIsolation
try { try {
this.underlyingTransactionIsolation = conn.getTransactionIsolation(); this.underlyingTransactionIsolation = conn.getTransactionIsolation();
} catch (SQLException e) { } catch (Throwable e) {
// compartible for alibaba corba LOG.warn("getTransactionIsolation error", e);
if ("HY000".equals(e.getSQLState())
|| "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException".equals(e.getClass().getName())) {
// skip
} else {
throw e;
}
} }
this.defaultHoldability = underlyingHoldability; this.defaultHoldability = underlyingHoldability;

Loading…
Cancel
Save