support sharePreparedStatements option

This commit is contained in:
wenshao
2011-12-28 17:49:55 +08:00
parent f80fb10be2
commit 0a2d5f43c8
6 changed files with 168 additions and 40 deletions
@@ -119,6 +119,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
private boolean testOnReturn = DEFAULT_TEST_ON_RETURN;
private boolean testWhileIdle = DEFAULT_WHILE_IDLE;
protected boolean poolPreparedStatements = false;
protected boolean sharePreparedStatements = false;
protected int maxPoolPreparedStatementPerConnectionSize = 10;
protected boolean inited = false;
@@ -206,7 +207,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
if (transactionQueryTimeout <= 0) {
return queryTimeout;
}
return transactionQueryTimeout;
}
@@ -349,9 +350,21 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
}
public void setMaxPoolPreparedStatementPerConnectionSize(int maxPoolPreparedStatementPerConnectionSize) {
if (maxPoolPreparedStatementPerConnectionSize > 0) {
this.poolPreparedStatements = true;
}
this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
}
public boolean isSharePreparedStatements() {
return sharePreparedStatements;
}
public void setSharePreparedStatements(boolean sharePreparedStatements) {
this.sharePreparedStatements = sharePreparedStatements;
}
public void incrementDupCloseCount() {
dupCloseCount.incrementAndGet();
}
@@ -436,7 +449,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
}
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
this.maxPoolPreparedStatementPerConnectionSize = maxOpenPreparedStatements;
this.setMaxPoolPreparedStatementPerConnectionSize(maxOpenPreparedStatements);
}
public boolean isLogAbandoned() {
@@ -1044,9 +1057,9 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
void initStatement(PoolableConnection conn, Statement stmt) throws SQLException {
boolean transaction = !conn.getConnectionHolder().isUnderlyingAutoCommit();
int queryTimeout = transaction ? getTransactionQueryTimeout() : getQueryTimeout();
if (queryTimeout > 0) {
stmt.setQueryTimeout(queryTimeout);
}