From 0780ba32133b868b4e4f45f5462b7a4dd71e23d5 Mon Sep 17 00:00:00 2001 From: rinoux Date: Tue, 28 Jun 2022 17:56:43 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-74418=20informix=E7=AD=89=E8=80=81?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E6=9C=AA=E5=AE=9E=E7=8E=B0=E9=83=A8=E5=88=86?= =?UTF-8?q?Connection=E6=8E=A5=E5=8F=A3=E5=AF=BC=E8=87=B4druid=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=BA=BF=E7=A8=8B=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../druid/pool/DruidConnectionHolder.java | 71 +++++++++---------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidConnectionHolder.java b/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidConnectionHolder.java index 5f8c0485e..8c38882de 100644 --- a/fine-druid/src/main/java/com/fr/third/alibaba/druid/pool/DruidConnectionHolder.java +++ b/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 java.sql.Connection; import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.ReentrantLock; @@ -41,6 +43,8 @@ import java.util.concurrent.locks.ReentrantLock; */ public final class DruidConnectionHolder { private final static Log LOG = LogFactory.getLog(DruidConnectionHolder.class); + + static Set holdabilityUnsupportedDbTypes = new HashSet<>(Arrays.asList(DbType.sybase, DbType.db2, DbType.hive, DbType.odps)); public static boolean holdabilityUnsupported = false; protected final DruidAbstractDataSource dataSource; @@ -101,53 +105,46 @@ public final class DruidConnectionHolder { this.lastActiveTimeMillis = connectTimeMillis; this.lastExecTimeMillis = connectTimeMillis; - this.underlyingAutoCommit = conn.getAutoCommit(); - if (conn instanceof WrapperProxy) { this.connectionId = ((WrapperProxy) conn).getId(); } else { this.connectionId = dataSource.createConnectionId(); } - { - boolean initUnderlyHoldability = !holdabilityUnsupported; - DbType dbType = DbType.of(dataSource.dbTypeName); - if (dbType == DbType.sybase // - || dbType == DbType.db2 // - || dbType == DbType.hive // - || dbType == DbType.odps // - ) { - initUnderlyHoldability = false; - } - if (initUnderlyHoldability) { - try { - 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) { - LOG.warn("getHoldability error", e); - } + + // 下面是一些驱动的默认值,reset时用到 + + // autoCommit + this.underlyingAutoCommit = conn.getAutoCommit(); + + // holdability + DbType dbType = DbType.of(dataSource.dbTypeName); + boolean initUnderlyingHoldability = !holdabilityUnsupported; + if (holdabilityUnsupportedDbTypes.contains(dbType)) { + initUnderlyingHoldability = false; + } + + if (initUnderlyingHoldability) { + try { + this.underlyingHoldability = conn.getHoldability(); + } catch (Throwable e) { + holdabilityUnsupported = true; + LOG.warn("getHoldability error", e); } } - this.underlyingReadOnly = conn.isReadOnly(); + // readOnly + try { + this.underlyingReadOnly = conn.isReadOnly(); + } catch (Throwable e) { + LOG.warn("isReadOnly error", e); + } + + // transactionIsolation try { this.underlyingTransactionIsolation = conn.getTransactionIsolation(); - } catch (SQLException e) { - // compartible for alibaba corba - if ("HY000".equals(e.getSQLState()) - || "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException".equals(e.getClass().getName())) { - // skip - } else { - throw e; - } + } catch (Throwable e) { + LOG.warn("getTransactionIsolation error", e); } this.defaultHoldability = underlyingHoldability;