improved oracle pscache error handle.

This commit is contained in:
wenshao
2017-10-03 02:18:07 +08:00
parent 98496a2e5d
commit 57cd092e0b
3 changed files with 25 additions and 5 deletions
@@ -60,7 +60,7 @@ public final class DruidConnectionHolder {
private PreparedStatementPool statementPool;
private final List<Statement> statementTrace = new ArrayList<Statement>(2);
protected final List<Statement> statementTrace = new ArrayList<Statement>(2);
private final boolean defaultReadOnly;
private final int defaultHoldability;
@@ -22,6 +22,7 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
@@ -438,6 +439,17 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
this.setConnectionProperties(property);
}
}
{
String property = properties.getProperty("druid.maxPoolPreparedStatementPerConnectionSize");
if (property != null && property.length() > 0) {
try {
int value = Integer.parseInt(property);
this.setMaxPoolPreparedStatementPerConnectionSize(value);
} catch (NumberFormatException e) {
LOG.error("illegal property 'druid.maxPoolPreparedStatementPerConnectionSize'", e);
}
}
}
}
public boolean isKillWhenSocketReadTimeout() {
@@ -1443,6 +1455,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
if (requireDiscard) {
if (holder.statementTrace != null) {
for (Statement stmt : holder.statementTrace) {
JdbcUtils.close(stmt);
}
}
this.discardConnection(holder.getConnection());
holder.setDiscard(true);
}
@@ -167,14 +167,15 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
}
}
stmt.getPreparedStatementHolder().decrementInUseCount();
PreparedStatementHolder stmtHolder = stmt.getPreparedStatementHolder();
stmtHolder.decrementInUseCount();
if (stmt.isPooled() && holder.isPoolPreparedStatements() && stmt.exceptionCount == 0) {
holder.getStatementPool().put(stmt.getPreparedStatementHolder());
holder.getStatementPool().put(stmtHolder);
stmt.clearResultSet();
holder.removeTrace(stmt);
stmt.getPreparedStatementHolder().setFetchRowPeak(stmt.getFetchRowPeak());
stmtHolder.setFetchRowPeak(stmt.getFetchRowPeak());
stmt.setClosed(true); // soft set close
} else if (stmt.isPooled() && holder.isPoolPreparedStatements()) {
@@ -182,7 +183,8 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
stmt.clearResultSet();
holder.removeTrace(stmt);
holder.getStatementPool().remove(stmt.getPreparedStatementHolder());
holder.getStatementPool()
.remove(stmtHolder);
} else {
try {
//Connection behind the statement may be in invalid state, which will throw a SQLException.