bug fixed for sharedPreparedStatement

This commit is contained in:
温少
2012-05-10 15:47:09 +08:00
parent 6641086507
commit 4dc8a4336f
7 changed files with 283 additions and 23 deletions
@@ -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());