improve unpooled statement's performance

This commit is contained in:
wenshao
2013-06-08 14:01:52 +08:00
parent 1f45ea28ee
commit 2a48c90450
5 changed files with 68 additions and 36 deletions
@@ -145,7 +145,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
return;
}
if (holder.isPoolPreparedStatements()) {
if (stmt.isPooled()) {
try {
rawStatement.clearParameters();
} catch (SQLException ex) {
@@ -159,7 +159,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
}
stmt.getPreparedStatementHolder().decrementInUseCount();
if (holder.isPoolPreparedStatements()) {
if (stmt.isPooled() && holder.isPoolPreparedStatements()) {
holder.getStatementPool().put(stmt.getPreparedStatementHolder());
stmt.clearResultSet();
@@ -63,6 +63,8 @@ public class DruidPooledPreparedStatement extends DruidPooledStatement implement
private int currentQueryTimeout;
private int currentFetchDirection;
private int currentFetchSize;
private boolean pooled = false;
public DruidPooledPreparedStatement(DruidPooledConnection conn, PreparedStatementHolder holder) throws SQLException{
super(conn, holder.getStatement());
@@ -70,35 +72,39 @@ public class DruidPooledPreparedStatement extends DruidPooledStatement implement
this.holder = holder;
this.sql = holder.getKey().sql;
pooled = conn.getConnectionHolder().isPoolPreparedStatements();
// Remember the defaults
try {
defaultMaxFieldSize = stmt.getMaxFieldSize();
} catch (SQLException e) {
LOG.error("getMaxFieldSize error", e);
}
try {
defaultMaxRows = stmt.getMaxRows();
} catch (SQLException e) {
LOG.error("getMaxRows error", e);
}
if (pooled) {
try {
defaultMaxFieldSize = stmt.getMaxFieldSize();
} catch (SQLException e) {
LOG.error("getMaxFieldSize error", e);
}
try {
defaultQueryTimeout = stmt.getQueryTimeout();
} catch (SQLException e) {
LOG.error("getMaxRows error", e);
}
try {
defaultMaxRows = stmt.getMaxRows();
} catch (SQLException e) {
LOG.error("getMaxRows error", e);
}
try {
defaultFetchDirection = stmt.getFetchDirection();
} catch (SQLException e) {
LOG.error("getFetchDirection error", e);
}
try {
defaultQueryTimeout = stmt.getQueryTimeout();
} catch (SQLException e) {
LOG.error("getMaxRows error", e);
}
try {
defaultFetchSize = stmt.getFetchSize();
} catch (SQLException e) {
LOG.error("getFetchSize error", e);
try {
defaultFetchDirection = stmt.getFetchDirection();
} catch (SQLException e) {
LOG.error("getFetchDirection error", e);
}
try {
defaultFetchSize = stmt.getFetchSize();
} catch (SQLException e) {
LOG.error("getFetchSize error", e);
}
}
currentMaxFieldSize = defaultMaxFieldSize;
@@ -165,7 +171,7 @@ public class DruidPooledPreparedStatement extends DruidPooledStatement implement
boolean connectionClosed = this.conn.isClosed();
// Reset the defaults
if (!connectionClosed) {
if (pooled && !connectionClosed) {
try {
if (defaultMaxFieldSize != currentMaxFieldSize) {
stmt.setMaxFieldSize(defaultMaxFieldSize);
@@ -194,6 +200,10 @@ public class DruidPooledPreparedStatement extends DruidPooledStatement implement
conn.closePoolableStatement(this);
}
public boolean isPooled() {
return pooled;
}
void closeInternal() throws SQLException {
super.close();