mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
DruidDataSource add keepAlive support.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import com.alibaba.druid.pool.DruidAbstractDataSource.PhysicalConnectionInfo;
|
||||
import com.alibaba.druid.proxy.jdbc.WrapperProxy;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
@@ -43,12 +44,14 @@ public final class DruidConnectionHolder {
|
||||
private final static Log LOG = LogFactory.getLog(DruidConnectionHolder.class);
|
||||
|
||||
private final DruidAbstractDataSource dataSource;
|
||||
private final long connectionId;
|
||||
private final Connection conn;
|
||||
private final List<ConnectionEventListener> connectionEventListeners = new CopyOnWriteArrayList<ConnectionEventListener>();
|
||||
private final List<StatementEventListener> statementEventListeners = new CopyOnWriteArrayList<StatementEventListener>();
|
||||
protected final long connectTimeMillis;
|
||||
protected transient long lastActiveTimeMillis;
|
||||
private long useCount = 0;
|
||||
private long keepAliveCheckCount = 0;
|
||||
|
||||
private long lastNotEmptyWaitNanos;
|
||||
|
||||
@@ -103,6 +106,12 @@ public final class DruidConnectionHolder {
|
||||
|
||||
this.underlyingAutoCommit = conn.getAutoCommit();
|
||||
|
||||
if (conn instanceof WrapperProxy) {
|
||||
this.connectionId = ((WrapperProxy) conn).getId();
|
||||
} else {
|
||||
this.connectionId = dataSource.createConnectionId();
|
||||
}
|
||||
|
||||
{
|
||||
boolean initUnderlyHoldability = !holdabilityUnsupported;
|
||||
if (JdbcConstants.SYBASE.equals(dataSource.dbType) //
|
||||
@@ -240,10 +249,22 @@ public final class DruidConnectionHolder {
|
||||
return useCount;
|
||||
}
|
||||
|
||||
public long getConnectionId() {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
public void incrementUseCount() {
|
||||
useCount++;
|
||||
}
|
||||
|
||||
public long getKeepAliveCheckCount() {
|
||||
return keepAliveCheckCount;
|
||||
}
|
||||
|
||||
public void incrementKeepAliveCheckCount() {
|
||||
keepAliveCheckCount++;
|
||||
}
|
||||
|
||||
public void reset() throws SQLException {
|
||||
// reset default settings
|
||||
if (underlyingReadOnly != defaultReadOnly) {
|
||||
|
||||
Reference in New Issue
Block a user