add pscache testcase

This commit is contained in:
wenshao
2012-08-13 21:29:45 +08:00
parent 920ed6947d
commit 705552efd3
3 changed files with 199 additions and 4 deletions
@@ -36,6 +36,7 @@ public final class PreparedStatementHolder {
private boolean enterOracleImplicitCache = false;
private int inUseCount = 0;
private boolean pooling = false;
public PreparedStatementHolder(PreparedStatementKey key, PreparedStatement stmt){
this.key = key;
@@ -99,12 +100,21 @@ public final class PreparedStatementHolder {
public void incrementInUseCount() {
inUseCount++;
}
public void decrementInUseCount() {
inUseCount--;
}
public int getInUseCount() {
return inUseCount;
}
public boolean isPooling() {
return pooling;
}
public void setPooling(boolean pooling) {
this.pooling = pooling;
}
}
@@ -57,7 +57,7 @@ public class PreparedStatementPool {
if (holder.isInUse() && (!dataSource.isSharePreparedStatements())) {
return null;
}
holder.incrementHitCount();
dataSource.incrementCachedPreparedStatementHitCount();
if (holder.isEnterOracleImplicitCache()) {
@@ -88,6 +88,7 @@ public class PreparedStatementPool {
PreparedStatementHolder oldHolder = map.put(key, holder);
if (oldHolder != null && oldHolder != holder) {
oldHolder.setPooling(false);
dataSource.closePreapredStatement(oldHolder);
} else {
if (holder.getHitCount() == 0) {
@@ -95,6 +96,7 @@ public class PreparedStatementPool {
}
}
holder.setPooling(true);
}
public void clear() throws SQLException {
@@ -109,10 +111,11 @@ public class PreparedStatementPool {
}
private void closeRemovedStatement(PreparedStatementHolder holder) throws SQLException {
holder.setPooling(false);
if (holder.isInUse()) {
return;
}
if (holder.isEnterOracleImplicitCache()) {
OracleUtils.exitImplicitCacheToClose(holder.getStatement());
}
@@ -125,6 +128,10 @@ public class PreparedStatementPool {
return map;
}
public int size() {
return this.map.size();
}
public class LRUCache extends LinkedHashMap<PreparedStatementKey, PreparedStatementHolder> {
private static final long serialVersionUID = 1L;