mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for sharedPreparedStatement
This commit is contained in:
@@ -151,19 +151,7 @@ public final class ConnectionHolder {
|
||||
}
|
||||
|
||||
public boolean isPoolPreparedStatements() {
|
||||
// if (dataSource.isOracle()) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
boolean poolPreparedStatements = dataSource.isPoolPreparedStatements();
|
||||
if (poolPreparedStatements) {
|
||||
boolean transaction = !isUnderlyingAutoCommit();
|
||||
if (transaction && !dataSource.isSharePreparedStatements()) {
|
||||
poolPreparedStatements = false;
|
||||
}
|
||||
}
|
||||
|
||||
return poolPreparedStatements;
|
||||
return dataSource.isPoolPreparedStatements();
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
|
||||
@@ -118,6 +118,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
return;
|
||||
}
|
||||
|
||||
stmt.getPreparedStatementHolder().decrementInUseCount();
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
holder.getStatementPool().put(stmt.getPreparedStatementHolder());
|
||||
|
||||
@@ -202,7 +203,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -210,6 +211,11 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
|
||||
return rtnVal;
|
||||
}
|
||||
|
||||
private void initStatement(PreparedStatementHolder stmtHolder) throws SQLException {
|
||||
stmtHolder.incrementInUseCount();
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||
@@ -236,7 +242,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -271,7 +277,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -302,7 +308,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -333,7 +339,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -364,7 +370,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -397,7 +403,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
|
||||
|
||||
@@ -432,7 +438,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
|
||||
|
||||
@@ -465,7 +471,7 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
|
||||
}
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
initStatement(stmtHolder);
|
||||
|
||||
DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
|
||||
holder.addTrace(rtnVal);
|
||||
|
||||
@@ -35,6 +35,8 @@ public final class PreparedStatementHolder {
|
||||
|
||||
private boolean enterOracleImplicitCache = false;
|
||||
|
||||
private int inUseCount = 0;
|
||||
|
||||
public PreparedStatementHolder(PreparedStatementKey key, PreparedStatement stmt){
|
||||
this.key = key;
|
||||
this.statement = stmt;
|
||||
@@ -90,4 +92,19 @@ public final class PreparedStatementHolder {
|
||||
return hitCount;
|
||||
}
|
||||
|
||||
public boolean isInUse() {
|
||||
return inUseCount <= 0;
|
||||
}
|
||||
|
||||
public void incrementInUseCount() {
|
||||
inUseCount++;
|
||||
}
|
||||
|
||||
public void decrementInUseCount() {
|
||||
inUseCount--;
|
||||
}
|
||||
|
||||
public int getInUseCount() {
|
||||
return inUseCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,10 @@ public class PreparedStatementPool {
|
||||
PreparedStatementHolder holder = map.get(key);
|
||||
|
||||
if (holder != null) {
|
||||
holder.incrementHitCount();
|
||||
if (holder.isInUse() && (!dataSource.isSharePreparedStatements())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
dataSource.incrementCachedPreparedStatementHitCount();
|
||||
if (holder.isEnterOracleImplicitCache()) {
|
||||
OracleUtils.exitImplicitCacheToActive(holder.getStatement());
|
||||
|
||||
Reference in New Issue
Block a user