mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor DruidDataSource
This commit is contained in:
@@ -72,8 +72,8 @@ public class PreparedStatementPool {
|
||||
return holder;
|
||||
}
|
||||
|
||||
public void put(PreparedStatementHolder holder) throws SQLException {
|
||||
PreparedStatement stmt = holder.getStatement();
|
||||
public void put(PreparedStatementHolder stmtHolder) throws SQLException {
|
||||
PreparedStatement stmt = stmtHolder.getStatement();
|
||||
|
||||
if (stmt == null) {
|
||||
return;
|
||||
@@ -81,29 +81,34 @@ public class PreparedStatementPool {
|
||||
|
||||
if (dataSource.isOracle() && dataSource.isUseOracleImplicitCache()) {
|
||||
OracleUtils.enterImplicitCache(stmt);
|
||||
holder.setEnterOracleImplicitCache(true);
|
||||
stmtHolder.setEnterOracleImplicitCache(true);
|
||||
} else {
|
||||
holder.setEnterOracleImplicitCache(false);
|
||||
stmtHolder.setEnterOracleImplicitCache(false);
|
||||
}
|
||||
|
||||
PreparedStatementKey key = holder.getKey();
|
||||
PreparedStatementKey key = stmtHolder.getKey();
|
||||
|
||||
PreparedStatementHolder oldHolder = map.put(key, holder);
|
||||
if (oldHolder != null && oldHolder != holder) {
|
||||
oldHolder.setPooling(false);
|
||||
closeRemovedStatement(oldHolder);
|
||||
PreparedStatementHolder oldStmtHolder = map.put(key, stmtHolder);
|
||||
|
||||
if (oldStmtHolder == stmtHolder) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldStmtHolder != null) {
|
||||
oldStmtHolder.setPooling(false);
|
||||
closeRemovedStatement(oldStmtHolder);
|
||||
} else {
|
||||
if (holder.getHitCount() == 0) {
|
||||
if (stmtHolder.getHitCount() == 0) {
|
||||
dataSource.incrementCachedPreparedStatementCount();
|
||||
}
|
||||
}
|
||||
|
||||
holder.setPooling(true);
|
||||
stmtHolder.setPooling(true);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
String message = null;
|
||||
if (holder.getStatement() instanceof PreparedStatementProxy) {
|
||||
PreparedStatementProxy stmtProxy = (PreparedStatementProxy) holder.getStatement();
|
||||
if (stmtHolder.getStatement() instanceof PreparedStatementProxy) {
|
||||
PreparedStatementProxy stmtProxy = (PreparedStatementProxy) stmtHolder.getStatement();
|
||||
if (stmtProxy instanceof CallableStatementProxy) {
|
||||
message = "{conn-" + stmtProxy.getConnectionProxy().getId() + ", cstmt-" + stmtProxy.getId() + "} enter cache";
|
||||
} else {
|
||||
|
||||
@@ -25,6 +25,7 @@ public class TestOraclePrefetch extends TestCase {
|
||||
dataSource.setDriver(new OracleMockDriver());
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setConnectionProperties("defaultRowPrefetch=50");
|
||||
// dataSource.setFilters("log4j");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
@@ -92,6 +93,8 @@ public class TestOraclePrefetch extends TestCase {
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
Assert.assertEquals(1, dataSource.getCachedPreparedStatementCount());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user