mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support dynamic setUserOracleImplicitCache
This commit is contained in:
@@ -115,11 +115,11 @@ public final class ConnectionHolder {
|
||||
this.lastActiveTimeMillis = lastActiveMillis;
|
||||
}
|
||||
|
||||
public void addTrace(PoolableStatement stmt) {
|
||||
public void addTrace(DruidPooledStatement stmt) {
|
||||
statementTrace.add(stmt);
|
||||
}
|
||||
|
||||
public void removeTrace(PoolableStatement stmt) {
|
||||
public void removeTrace(DruidPooledStatement stmt) {
|
||||
statementTrace.remove(stmt);
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
protected final AtomicLong errorCount = new AtomicLong();
|
||||
protected final AtomicLong dupCloseCount = new AtomicLong();
|
||||
|
||||
protected final ConcurrentIdentityHashMap<PoolableConnection, ActiveConnectionTraceInfo> activeConnections = new ConcurrentIdentityHashMap<PoolableConnection, ActiveConnectionTraceInfo>();
|
||||
protected final ConcurrentIdentityHashMap<DruidPooledConnection, ActiveConnectionTraceInfo> activeConnections = new ConcurrentIdentityHashMap<DruidPooledConnection, ActiveConnectionTraceInfo>();
|
||||
|
||||
protected long id;
|
||||
|
||||
@@ -211,10 +211,20 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
|
||||
protected boolean isOracle = false;
|
||||
|
||||
protected boolean useOracleImplicitCache = false;
|
||||
|
||||
public boolean isOracle() {
|
||||
return isOracle;
|
||||
}
|
||||
|
||||
public boolean isUseOracleImplicitCache() {
|
||||
return useOracleImplicitCache;
|
||||
}
|
||||
|
||||
public void setUseOracleImplicitCache(boolean useOracleImplicitCache) {
|
||||
this.useOracleImplicitCache = useOracleImplicitCache;
|
||||
}
|
||||
|
||||
public Throwable getLastCreateError() {
|
||||
return lastCreateError;
|
||||
}
|
||||
@@ -1063,11 +1073,11 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
}
|
||||
}
|
||||
|
||||
public Set<PoolableConnection> getActiveConnections() {
|
||||
public Set<DruidPooledConnection> getActiveConnections() {
|
||||
return this.activeConnections.keySet();
|
||||
}
|
||||
|
||||
void removeActiveConnection(PoolableConnection conn) {
|
||||
void removeActiveConnection(DruidPooledConnection conn) {
|
||||
activeConnections.remove(conn);
|
||||
}
|
||||
|
||||
@@ -1115,7 +1125,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
return transactionIdSeed.getAndIncrement();
|
||||
}
|
||||
|
||||
void initStatement(PoolableConnection conn, Statement stmt) throws SQLException {
|
||||
void initStatement(DruidPooledConnection conn, Statement stmt) throws SQLException {
|
||||
boolean transaction = !conn.getConnectionHolder().isUnderlyingAutoCommit();
|
||||
|
||||
int queryTimeout = transaction ? getTransactionQueryTimeout() : getQueryTimeout();
|
||||
@@ -1125,10 +1135,10 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void handleConnectionException(PoolableConnection pooledConnection, Throwable t)
|
||||
public abstract void handleConnectionException(DruidPooledConnection pooledConnection, Throwable t)
|
||||
throws SQLException;
|
||||
|
||||
protected abstract void recycle(PoolableConnection pooledConnection) throws SQLException;
|
||||
protected abstract void recycle(DruidPooledConnection pooledConnection) throws SQLException;
|
||||
|
||||
abstract void incrementCreateCount();
|
||||
|
||||
@@ -1245,13 +1255,13 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
dataSource.validateConnection(conn);
|
||||
dataSource.createError = null;
|
||||
|
||||
// if (dataSource.isOracle() && dataSource.isPoolPreparedStatements()) {
|
||||
// int cacheSize = dataSource.getMaxPoolPreparedStatementPerConnectionSize();
|
||||
// if (cacheSize > 0) {
|
||||
// OracleUtils.setImplicitCachingEnabled(conn, true);
|
||||
// OracleUtils.setStatementCacheSize(conn, cacheSize);
|
||||
// }
|
||||
// }
|
||||
// if (dataSource.isOracle() && dataSource.isPoolPreparedStatements()) {
|
||||
// int cacheSize = dataSource.getMaxPoolPreparedStatementPerConnectionSize();
|
||||
// if (cacheSize > 0) {
|
||||
// OracleUtils.setImplicitCachingEnabled(conn, true);
|
||||
// OracleUtils.setStatementCacheSize(conn, cacheSize);
|
||||
// }
|
||||
// }
|
||||
} catch (SQLException ex) {
|
||||
dataSource.createErrorCount++;
|
||||
dataSource.createError = ex;
|
||||
|
||||
@@ -146,4 +146,8 @@ public interface DruidAbstractDataSourceMBean {
|
||||
long getCachedPreparedStatementMissCount();
|
||||
|
||||
long getCachedPreparedStatementHitCount();
|
||||
|
||||
boolean isUseOracleImplicitCache();
|
||||
|
||||
void setUseOracleImplicitCache(boolean useOracleImplicitCache);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.alibaba.druid.VERSION;
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.vendor.InformixExceptionSorter;
|
||||
import com.alibaba.druid.pool.vendor.MSSQLValidConnectionChecker;
|
||||
import com.alibaba.druid.pool.vendor.MockExceptionSorter;
|
||||
@@ -387,7 +387,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
PoolableConnection poolalbeConnection = getConnectionInternal(maxWaitMillis);
|
||||
DruidPooledConnection poolalbeConnection = getConnectionInternal(maxWaitMillis);
|
||||
|
||||
if (isTestOnBorrow()) {
|
||||
boolean validate = testConnectionInternal(poolalbeConnection.getConnection());
|
||||
@@ -462,8 +462,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
}
|
||||
|
||||
private PoolableConnection getConnectionInternal(long maxWait) throws SQLException {
|
||||
PoolableConnection poolalbeConnection;
|
||||
private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLException {
|
||||
DruidPooledConnection poolalbeConnection;
|
||||
|
||||
try {
|
||||
lock.lockInterruptibly();
|
||||
@@ -498,7 +498,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
activePeakTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
poolalbeConnection = new PoolableConnection(holder);
|
||||
poolalbeConnection = new DruidPooledConnection(holder);
|
||||
} catch (InterruptedException e) {
|
||||
connectErrorCount++;
|
||||
throw new SQLException(e.getMessage(), e);
|
||||
@@ -511,7 +511,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return poolalbeConnection;
|
||||
}
|
||||
|
||||
public void handleConnectionException(PoolableConnection pooledConnection, Throwable t) throws SQLException {
|
||||
public void handleConnectionException(DruidPooledConnection pooledConnection, Throwable t) throws SQLException {
|
||||
final ConnectionHolder holder = pooledConnection.getConnectionHolder();
|
||||
|
||||
errorCount.incrementAndGet();
|
||||
@@ -545,7 +545,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
/**
|
||||
* 回收连接
|
||||
*/
|
||||
protected void recycle(PoolableConnection pooledConnection) throws SQLException {
|
||||
protected void recycle(DruidPooledConnection pooledConnection) throws SQLException {
|
||||
final Connection conn = pooledConnection.getConnection();
|
||||
final ConnectionHolder holder = pooledConnection.getConnectionHolder();
|
||||
|
||||
@@ -992,19 +992,19 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
public int removeAbandoned() {
|
||||
int removeCount = 0;
|
||||
|
||||
Iterator<Map.Entry<PoolableConnection, ActiveConnectionTraceInfo>> iter = activeConnections.entrySet().iterator();
|
||||
Iterator<Map.Entry<DruidPooledConnection, ActiveConnectionTraceInfo>> iter = activeConnections.entrySet().iterator();
|
||||
|
||||
long currentMillis = System.currentTimeMillis();
|
||||
|
||||
List<PoolableConnection> abondonedList = new ArrayList<PoolableConnection>();
|
||||
List<DruidPooledConnection> abondonedList = new ArrayList<DruidPooledConnection>();
|
||||
|
||||
for (; iter.hasNext();) {
|
||||
Map.Entry<PoolableConnection, ActiveConnectionTraceInfo> entry = iter.next();
|
||||
Map.Entry<DruidPooledConnection, ActiveConnectionTraceInfo> entry = iter.next();
|
||||
ActiveConnectionTraceInfo activeInfo = entry.getValue();
|
||||
long timeMillis = currentMillis - activeInfo.getConnectTime();
|
||||
|
||||
if (timeMillis >= removeAbandonedTimeoutMillis) {
|
||||
PoolableConnection pooledConnection = entry.getKey();
|
||||
DruidPooledConnection pooledConnection = entry.getKey();
|
||||
JdbcUtils.close(pooledConnection);
|
||||
removeAbandonedCount++;
|
||||
removeCount++;
|
||||
@@ -1027,7 +1027,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
// multi-check dup close
|
||||
for (PoolableConnection conn : abondonedList) {
|
||||
for (DruidPooledConnection conn : abondonedList) {
|
||||
activeConnections.remove(conn);
|
||||
}
|
||||
|
||||
@@ -1051,18 +1051,18 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
static class ActiveConnectionTraceInfo {
|
||||
|
||||
private final PoolableConnection connection;
|
||||
private final DruidPooledConnection connection;
|
||||
private final long connectTime;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
|
||||
public ActiveConnectionTraceInfo(PoolableConnection connection, long connectTime, StackTraceElement[] stackTrace){
|
||||
public ActiveConnectionTraceInfo(DruidPooledConnection connection, long connectTime, StackTraceElement[] stackTrace){
|
||||
super();
|
||||
this.connection = connection;
|
||||
this.connectTime = connectTime;
|
||||
this.stackTrace = stackTrace;
|
||||
}
|
||||
|
||||
public PoolableConnection getConnection() {
|
||||
public DruidPooledConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -33,11 +33,11 @@ import java.util.Calendar;
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public class PoolableCallableStatement extends PoolablePreparedStatement implements CallableStatement {
|
||||
public class DruidPooledCallableStatement extends DruidPooledPreparedStatement implements CallableStatement {
|
||||
|
||||
private CallableStatement stmt;
|
||||
|
||||
public PoolableCallableStatement(PoolableConnection conn, PreparedStatementHolder holder) throws SQLException{
|
||||
public DruidPooledCallableStatement(DruidPooledConnection conn, PreparedStatementHolder holder) throws SQLException{
|
||||
super(conn, holder);
|
||||
this.stmt = (CallableStatement) holder.getStatement();
|
||||
}
|
||||
+22
-23
@@ -37,21 +37,20 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import javax.sql.ConnectionEvent;
|
||||
import javax.sql.ConnectionEventListener;
|
||||
import javax.sql.PooledConnection;
|
||||
import javax.sql.StatementEventListener;
|
||||
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
|
||||
import com.alibaba.druid.util.TransactionInfo;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public class PoolableConnection implements PooledConnection, Connection {
|
||||
public class DruidPooledConnection implements javax.sql.PooledConnection, Connection {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(PoolableConnection.class);
|
||||
private final static Log LOG = LogFactory.getLog(DruidPooledConnection.class);
|
||||
|
||||
protected Connection conn;
|
||||
protected ConnectionHolder holder;
|
||||
@@ -62,7 +61,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
private boolean closed = false;
|
||||
private final Thread ownerThread;
|
||||
|
||||
public PoolableConnection(ConnectionHolder holder){
|
||||
public DruidPooledConnection(ConnectionHolder holder){
|
||||
this.conn = holder.getConnection();
|
||||
this.holder = holder;
|
||||
dupCloseLogEnable = holder.getDataSource().isDupCloseLogEnable();
|
||||
@@ -96,12 +95,12 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
throw new SQLException("Error", t);
|
||||
}
|
||||
|
||||
|
||||
public boolean isOracle() {
|
||||
return holder.getDataSource().isOracle();
|
||||
}
|
||||
|
||||
void closePoolableStatement(PoolablePreparedStatement stmt) throws SQLException {
|
||||
void closePoolableStatement(DruidPooledPreparedStatement stmt) throws SQLException {
|
||||
if (this.holder == null) {
|
||||
return;
|
||||
}
|
||||
@@ -117,15 +116,15 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
if (holder == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
holder.getStatementPool().put(stmt.getPreparedStatementHolder());
|
||||
|
||||
|
||||
stmt.clearResultSet();
|
||||
holder.removeTrace(stmt);
|
||||
|
||||
|
||||
stmt.getPreparedStatementHolder().setFetchRowPeak(stmt.getFetchRowPeak());
|
||||
|
||||
|
||||
stmt.setClosed(true); // soft set close
|
||||
} else {
|
||||
stmt.closeInternal();
|
||||
@@ -204,7 +203,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -238,7 +237,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -273,7 +272,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -304,7 +303,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -335,7 +334,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -366,7 +365,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -399,7 +398,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmtHolder);
|
||||
DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -434,7 +433,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmtHolder);
|
||||
DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
|
||||
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -467,7 +466,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmtHolder);
|
||||
DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
return rtnVal;
|
||||
@@ -488,7 +487,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmt);
|
||||
|
||||
PoolableStatement poolableStatement = new PoolableStatement(this, stmt);
|
||||
DruidPooledStatement poolableStatement = new DruidPooledStatement(this, stmt);
|
||||
holder.addTrace(poolableStatement);
|
||||
|
||||
return poolableStatement;
|
||||
@@ -508,7 +507,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmt);
|
||||
|
||||
PoolableStatement poolableStatement = new PoolableStatement(this, stmt);
|
||||
DruidPooledStatement poolableStatement = new DruidPooledStatement(this, stmt);
|
||||
holder.addTrace(poolableStatement);
|
||||
|
||||
return poolableStatement;
|
||||
@@ -527,7 +526,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
holder.getDataSource().initStatement(this, stmt);
|
||||
|
||||
PoolableStatement poolableStatement = new PoolableStatement(this, stmt);
|
||||
DruidPooledStatement poolableStatement = new DruidPooledStatement(this, stmt);
|
||||
holder.addTrace(poolableStatement);
|
||||
|
||||
return poolableStatement;
|
||||
+3
-3
@@ -43,7 +43,7 @@ import com.alibaba.druid.util.OracleUtils;
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public class PoolablePreparedStatement extends PoolableStatement implements PreparedStatement {
|
||||
public class DruidPooledPreparedStatement extends DruidPooledStatement implements PreparedStatement {
|
||||
|
||||
private final PreparedStatementHolder holder;
|
||||
private final PreparedStatement stmt;
|
||||
@@ -60,7 +60,7 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
|
||||
private int currentFetchDirection;
|
||||
private int currentFetchSize;
|
||||
|
||||
public PoolablePreparedStatement(PoolableConnection conn, PreparedStatementHolder holder) throws SQLException{
|
||||
public DruidPooledPreparedStatement(DruidPooledConnection conn, PreparedStatementHolder holder) throws SQLException{
|
||||
super(conn, holder.getStatement());
|
||||
this.stmt = holder.getStatement();
|
||||
this.holder = holder;
|
||||
@@ -179,7 +179,7 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
|
||||
try {
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
PoolableResultSet poolableResultSet = new PoolableResultSet(this, rs);
|
||||
DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs);
|
||||
resultSetTrace.add(poolableResultSet);
|
||||
|
||||
return poolableResultSet;
|
||||
+4
-4
@@ -36,16 +36,16 @@ import java.util.Calendar;
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public final class PoolableResultSet extends PoolableWrapper implements ResultSet {
|
||||
public final class DruidPooledResultSet extends PoolableWrapper implements ResultSet {
|
||||
|
||||
private final ResultSet rs;
|
||||
private final PoolableStatement stmt;
|
||||
private final DruidPooledStatement stmt;
|
||||
private boolean closed = false;
|
||||
|
||||
protected int cursorIndex = 0;
|
||||
protected int fetchRowCount = 0;
|
||||
|
||||
public PoolableResultSet(PoolableStatement stmt, ResultSet rs){
|
||||
public DruidPooledResultSet(DruidPooledStatement stmt, ResultSet rs){
|
||||
super(rs);
|
||||
this.stmt = stmt;
|
||||
this.rs = rs;
|
||||
@@ -55,7 +55,7 @@ public final class PoolableResultSet extends PoolableWrapper implements ResultSe
|
||||
return stmt.checkException(error);
|
||||
}
|
||||
|
||||
public PoolableStatement getPoolableStatement() {
|
||||
public DruidPooledStatement getPoolableStatement() {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
+9
-9
@@ -29,17 +29,17 @@ import com.alibaba.druid.logging.LogFactory;
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
public class DruidPooledStatement extends PoolableWrapper implements Statement {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(PoolableStatement.class);
|
||||
private final static Log LOG = LogFactory.getLog(DruidPooledStatement.class);
|
||||
|
||||
private final Statement stmt;
|
||||
protected PoolableConnection conn;
|
||||
protected DruidPooledConnection conn;
|
||||
protected final List<ResultSet> resultSetTrace = new ArrayList<ResultSet>();
|
||||
protected boolean closed = false;
|
||||
protected int fetchRowPeak = -1;
|
||||
|
||||
public PoolableStatement(PoolableConnection conn, Statement stmt){
|
||||
public DruidPooledStatement(DruidPooledConnection conn, Statement stmt){
|
||||
super(stmt);
|
||||
|
||||
this.conn = conn;
|
||||
@@ -60,11 +60,11 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
return conn.handleException(error);
|
||||
}
|
||||
|
||||
public PoolableConnection getPoolableConnection() {
|
||||
public DruidPooledConnection getPoolableConnection() {
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void setPoolableConnection(PoolableConnection conn) {
|
||||
public void setPoolableConnection(DruidPooledConnection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
try {
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
|
||||
PoolableResultSet poolableResultSet = new PoolableResultSet(this, rs);
|
||||
DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs);
|
||||
resultSetTrace.add(poolableResultSet);
|
||||
|
||||
return poolableResultSet;
|
||||
@@ -284,7 +284,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
try {
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
|
||||
PoolableResultSet poolableResultSet = new PoolableResultSet(this, rs);
|
||||
DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs);
|
||||
resultSetTrace.add(poolableResultSet);
|
||||
|
||||
return poolableResultSet;
|
||||
@@ -443,7 +443,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
|
||||
try {
|
||||
ResultSet rs = stmt.getGeneratedKeys();
|
||||
|
||||
PoolableResultSet poolableResultSet = new PoolableResultSet(this, rs);
|
||||
DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs);
|
||||
|
||||
resultSetTrace.add(poolableResultSet);
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.alibaba.druid.pool;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
@@ -26,18 +26,28 @@ public final class PreparedStatementHolder {
|
||||
|
||||
private final PreparedStatementKey key;
|
||||
private final PreparedStatement statement;
|
||||
private int hitCount = 0;
|
||||
private int hitCount = 0;
|
||||
|
||||
private int fetchRowPeak = -1;
|
||||
private int fetchRowPeak = -1;
|
||||
|
||||
private int defaultRowPretch = -1;
|
||||
private int rowPrefetch = -1;
|
||||
private int defaultRowPretch = -1;
|
||||
private int rowPrefetch = -1;
|
||||
|
||||
private boolean enterOracleImplicitCache = false;
|
||||
|
||||
public PreparedStatementHolder(PreparedStatementKey key, PreparedStatement stmt){
|
||||
this.key = key;
|
||||
this.statement = stmt;
|
||||
}
|
||||
|
||||
public boolean isEnterOracleImplicitCache() {
|
||||
return enterOracleImplicitCache;
|
||||
}
|
||||
|
||||
public void setEnterOracleImplicitCache(boolean enterOracleImplicitCache) {
|
||||
this.enterOracleImplicitCache = enterOracleImplicitCache;
|
||||
}
|
||||
|
||||
public int getDefaultRowPretch() {
|
||||
return defaultRowPretch;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Map.Entry;
|
||||
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.util.OracleUtils;
|
||||
|
||||
/**
|
||||
@@ -32,10 +32,10 @@ import com.alibaba.druid.util.OracleUtils;
|
||||
*/
|
||||
public class PreparedStatementPool {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(PreparedStatementPool.class);
|
||||
private final static Log LOG = LogFactory.getLog(PreparedStatementPool.class);
|
||||
|
||||
private final Map<PreparedStatementKey, PreparedStatementHolder> map;
|
||||
private final DruidAbstractDataSource dataSource;
|
||||
private final LRUCache map;
|
||||
private final DruidAbstractDataSource dataSource;
|
||||
|
||||
public PreparedStatementPool(ConnectionHolder holder){
|
||||
this.dataSource = holder.getDataSource();
|
||||
@@ -56,7 +56,9 @@ public class PreparedStatementPool {
|
||||
if (holder != null) {
|
||||
holder.incrementHitCount();
|
||||
dataSource.incrementCachedPreparedStatementHitCount();
|
||||
OracleUtils.exitImplicitCacheToActive(holder.getStatement());
|
||||
if (holder.isEnterOracleImplicitCache()) {
|
||||
OracleUtils.exitImplicitCacheToActive(holder.getStatement());
|
||||
}
|
||||
} else {
|
||||
dataSource.incrementCachedPreparedStatementMissCount();
|
||||
}
|
||||
@@ -71,12 +73,15 @@ public class PreparedStatementPool {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dataSource.isOracle()) {
|
||||
if (dataSource.isOracle() && dataSource.isUseOracleImplicitCache()) {
|
||||
OracleUtils.enterImplicitCache(stmt);
|
||||
|
||||
holder.setEnterOracleImplicitCache(true);
|
||||
} else {
|
||||
holder.setEnterOracleImplicitCache(false);
|
||||
}
|
||||
|
||||
PreparedStatementKey key = holder.getKey();
|
||||
|
||||
PreparedStatementHolder oldHolder = map.put(key, holder);
|
||||
if (oldHolder != null && oldHolder != holder) {
|
||||
dataSource.closePreapredStatement(oldHolder);
|
||||
@@ -85,6 +90,7 @@ public class PreparedStatementPool {
|
||||
dataSource.incrementCachedPreparedStatementCount();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void clear() throws SQLException {
|
||||
@@ -99,7 +105,7 @@ public class PreparedStatementPool {
|
||||
}
|
||||
|
||||
private void closeStatement(PreparedStatementHolder holder) throws SQLException {
|
||||
if (dataSource.isOracle()) {
|
||||
if (holder.isEnterOracleImplicitCache()) {
|
||||
OracleUtils.exitImplicitCacheToClose(holder.getStatement());
|
||||
}
|
||||
dataSource.closePreapredStatement(holder);
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.PoolableConnection;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.ValidConnectionChecker;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.util.OracleUtils;
|
||||
@@ -57,8 +57,8 @@ public class OracleValidConnectionChecker implements ValidConnectionChecker, Ser
|
||||
}
|
||||
|
||||
try {
|
||||
if (conn instanceof PoolableConnection) {
|
||||
conn = ((PoolableConnection) conn).getConnection();
|
||||
if (conn instanceof DruidPooledConnection) {
|
||||
conn = ((DruidPooledConnection) conn).getConnection();
|
||||
}
|
||||
|
||||
if (conn instanceof ConnectionProxy) {
|
||||
|
||||
@@ -12,9 +12,9 @@ import javax.transaction.xa.Xid;
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.ConnectionHolder;
|
||||
import com.alibaba.druid.pool.PoolableConnection;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
|
||||
public class XAPoolableConnection extends PoolableConnection implements XAResource {
|
||||
public class XAPoolableConnection extends DruidPooledConnection implements XAResource {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(XAPoolableConnection.class);
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ import java.sql.Statement;
|
||||
|
||||
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
|
||||
|
||||
import com.alibaba.druid.pool.PoolableCallableStatement;
|
||||
import com.alibaba.druid.pool.PoolableConnection;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement;
|
||||
import com.alibaba.druid.pool.PoolableResultSet;
|
||||
import com.alibaba.druid.pool.PoolableStatement;
|
||||
import com.alibaba.druid.pool.DruidPooledCallableStatement;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement;
|
||||
import com.alibaba.druid.pool.DruidPooledResultSet;
|
||||
import com.alibaba.druid.pool.DruidPooledStatement;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
|
||||
@@ -40,8 +40,8 @@ public class DruidJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public Connection getNativeConnection(Connection conn) throws SQLException {
|
||||
if (conn instanceof PoolableConnection) {
|
||||
conn = ((PoolableConnection) conn).getConnection();
|
||||
if (conn instanceof DruidPooledConnection) {
|
||||
conn = ((DruidPooledConnection) conn).getConnection();
|
||||
}
|
||||
|
||||
if (conn instanceof ConnectionProxy) {
|
||||
@@ -58,8 +58,8 @@ public class DruidJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public Statement getNativeStatement(Statement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolableStatement) {
|
||||
stmt = ((PoolableStatement) stmt).getStatement();
|
||||
if (stmt instanceof DruidPooledStatement) {
|
||||
stmt = ((DruidPooledStatement) stmt).getStatement();
|
||||
}
|
||||
|
||||
if (stmt instanceof StatementProxy) {
|
||||
@@ -71,8 +71,8 @@ public class DruidJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public PreparedStatement getNativePreparedStatement(PreparedStatement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolablePreparedStatement) {
|
||||
stmt = ((PoolablePreparedStatement) stmt).getRawPreparedStatement();
|
||||
if (stmt instanceof DruidPooledPreparedStatement) {
|
||||
stmt = ((DruidPooledPreparedStatement) stmt).getRawPreparedStatement();
|
||||
}
|
||||
|
||||
if (stmt instanceof PreparedStatementProxy) {
|
||||
@@ -84,8 +84,8 @@ public class DruidJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public CallableStatement getNativeCallableStatement(CallableStatement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolableCallableStatement) {
|
||||
stmt = ((PoolableCallableStatement) stmt).getCallableStatementRaw();
|
||||
if (stmt instanceof DruidPooledCallableStatement) {
|
||||
stmt = ((DruidPooledCallableStatement) stmt).getCallableStatementRaw();
|
||||
}
|
||||
|
||||
if (stmt instanceof CallableStatementProxy) {
|
||||
@@ -97,8 +97,8 @@ public class DruidJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
|
||||
if (rs instanceof PoolableResultSet) {
|
||||
rs = ((PoolableResultSet) rs).getRawResultSet();
|
||||
if (rs instanceof DruidPooledResultSet) {
|
||||
rs = ((DruidPooledResultSet) rs).getRawResultSet();
|
||||
}
|
||||
|
||||
if (rs instanceof ResultSetProxy) {
|
||||
|
||||
@@ -9,11 +9,11 @@ import java.sql.Statement;
|
||||
|
||||
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
|
||||
|
||||
import com.alibaba.druid.pool.PoolableCallableStatement;
|
||||
import com.alibaba.druid.pool.PoolableConnection;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement;
|
||||
import com.alibaba.druid.pool.PoolableResultSet;
|
||||
import com.alibaba.druid.pool.PoolableStatement;
|
||||
import com.alibaba.druid.pool.DruidPooledCallableStatement;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement;
|
||||
import com.alibaba.druid.pool.DruidPooledResultSet;
|
||||
import com.alibaba.druid.pool.DruidPooledStatement;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
|
||||
@@ -39,8 +39,8 @@ public class DruidNativeJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public Connection getNativeConnection(Connection conn) throws SQLException {
|
||||
if (conn instanceof PoolableConnection) {
|
||||
conn = ((PoolableConnection) conn).getConnection();
|
||||
if (conn instanceof DruidPooledConnection) {
|
||||
conn = ((DruidPooledConnection) conn).getConnection();
|
||||
}
|
||||
|
||||
if (conn instanceof ConnectionProxy) {
|
||||
@@ -58,8 +58,8 @@ public class DruidNativeJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public Statement getNativeStatement(Statement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolableStatement) {
|
||||
stmt = ((PoolableStatement) stmt).getStatement();
|
||||
if (stmt instanceof DruidPooledStatement) {
|
||||
stmt = ((DruidPooledStatement) stmt).getStatement();
|
||||
}
|
||||
|
||||
if (stmt instanceof StatementProxy) {
|
||||
@@ -71,8 +71,8 @@ public class DruidNativeJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public PreparedStatement getNativePreparedStatement(PreparedStatement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolablePreparedStatement) {
|
||||
stmt = ((PoolablePreparedStatement) stmt).getRawPreparedStatement();
|
||||
if (stmt instanceof DruidPooledPreparedStatement) {
|
||||
stmt = ((DruidPooledPreparedStatement) stmt).getRawPreparedStatement();
|
||||
}
|
||||
|
||||
if (stmt instanceof PreparedStatementProxy) {
|
||||
@@ -84,8 +84,8 @@ public class DruidNativeJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public CallableStatement getNativeCallableStatement(CallableStatement stmt) throws SQLException {
|
||||
if (stmt instanceof PoolableCallableStatement) {
|
||||
stmt = ((PoolableCallableStatement) stmt).getCallableStatementRaw();
|
||||
if (stmt instanceof DruidPooledCallableStatement) {
|
||||
stmt = ((DruidPooledCallableStatement) stmt).getCallableStatementRaw();
|
||||
}
|
||||
|
||||
if (stmt instanceof CallableStatementProxy) {
|
||||
@@ -97,8 +97,8 @@ public class DruidNativeJdbcExtractor implements NativeJdbcExtractor {
|
||||
|
||||
@Override
|
||||
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
|
||||
if (rs instanceof PoolableResultSet) {
|
||||
rs = ((PoolableResultSet) rs).getRawResultSet();
|
||||
if (rs instanceof DruidPooledResultSet) {
|
||||
rs = ((DruidPooledResultSet) rs).getRawResultSet();
|
||||
}
|
||||
|
||||
if (rs instanceof ResultSetProxy) {
|
||||
|
||||
@@ -11,11 +11,11 @@ import oracle.jdbc.OracleStatement;
|
||||
import oracle.jdbc.internal.OraclePreparedStatement;
|
||||
import oracle.sql.ROWID;
|
||||
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement;
|
||||
|
||||
public class OracleUtils {
|
||||
|
||||
public static void clearDefines(PoolablePreparedStatement stmt) throws SQLException {
|
||||
public static void clearDefines(DruidPooledPreparedStatement stmt) throws SQLException {
|
||||
OracleStatement oracleStmt = stmt.unwrap(OracleStatement.class);
|
||||
oracleStmt.clearDefines();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user