mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed : statement pool
This commit is contained in:
@@ -203,7 +203,8 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
throws SQLException {
|
||||
checkOpen();
|
||||
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M2);
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M2, resultSetType,
|
||||
resultSetConcurrency);
|
||||
|
||||
PreparedStatementHolder stmtHolder = null;
|
||||
|
||||
@@ -240,7 +241,8 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
int resultSetHoldability) throws SQLException {
|
||||
checkOpen();
|
||||
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M3);
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M3, resultSetType,
|
||||
resultSetConcurrency, resultSetHoldability);
|
||||
|
||||
PreparedStatementHolder stmtHolder = null;
|
||||
|
||||
@@ -279,7 +281,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
PreparedStatementHolder stmtHolder = null;
|
||||
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M4);
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M4, columnIndexes);
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
stmtHolder = holder.getStatementPool().get(key);
|
||||
}
|
||||
@@ -313,7 +315,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
PreparedStatementHolder stmtHolder = null;
|
||||
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M5);
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M5, columnNames);
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
stmtHolder = holder.getStatementPool().get(key);
|
||||
}
|
||||
@@ -347,7 +349,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
PreparedStatementHolder stmtHolder = null;
|
||||
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M6);
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M6, autoGeneratedKeys);
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
stmtHolder = holder.getStatementPool().get(key);
|
||||
}
|
||||
@@ -419,7 +421,8 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
PreparedStatementHolder stmtHolder = null;
|
||||
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_2);
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_2, resultSetType,
|
||||
resultSetConcurrency, resultSetHoldability);
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
stmtHolder = holder.getStatementPool().get(key);
|
||||
}
|
||||
@@ -455,7 +458,8 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
PreparedStatementHolder stmtHolder = null;
|
||||
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_3);
|
||||
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_3, resultSetType,
|
||||
resultSetConcurrency);
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
stmtHolder = holder.getStatementPool().get(key);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.sql.SQLException;
|
||||
import java.sql.SQLXML;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
|
||||
@@ -791,7 +792,42 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
|
||||
|
||||
protected final MethodType methodType;
|
||||
|
||||
private final int resultSetType;
|
||||
private final int resultSetConcurrency;
|
||||
private final int resultSetHoldability;
|
||||
private final int autoGeneratedKeys;
|
||||
private final int[] columnIndexes;
|
||||
private final String[] columnNames;
|
||||
|
||||
public PreparedStatementKey(String sql, String catalog, MethodType methodType) throws SQLException{
|
||||
this(sql, catalog, methodType, 0, 0, 0, 0, null, null);
|
||||
}
|
||||
|
||||
public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType,
|
||||
int resultSetConcurrency) throws SQLException{
|
||||
this(sql, catalog, methodType, resultSetType, resultSetConcurrency, 0, 0, null, null);
|
||||
}
|
||||
|
||||
public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType,
|
||||
int resultSetConcurrency, int resultSetHoldability) throws SQLException{
|
||||
this(sql, catalog, methodType, resultSetType, resultSetConcurrency, resultSetHoldability, 0, null, null);
|
||||
}
|
||||
|
||||
public PreparedStatementKey(String sql, String catalog, MethodType methodType, int autoGeneratedKeys) throws SQLException{
|
||||
this(sql, catalog, methodType, 0, 0, 0, autoGeneratedKeys, null, null);
|
||||
}
|
||||
|
||||
public PreparedStatementKey(String sql, String catalog, MethodType methodType, int[] columnIndexes) throws SQLException{
|
||||
this(sql, catalog, methodType, 0, 0, 0, 0, columnIndexes, null);
|
||||
}
|
||||
|
||||
public PreparedStatementKey(String sql, String catalog, MethodType methodType, String[] columnNames) throws SQLException{
|
||||
this(sql, catalog, methodType, 0, 0, 0, 0, null, columnNames);
|
||||
}
|
||||
|
||||
public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType,
|
||||
int resultSetConcurrency, int resultSetHoldability, int autoGeneratedKeys,
|
||||
int[] columnIndexes, String[] columnNames) throws SQLException{
|
||||
if (sql == null) {
|
||||
throw new SQLException("sql is null");
|
||||
}
|
||||
@@ -799,6 +835,24 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
|
||||
this.sql = sql;
|
||||
this.catalog = catalog;
|
||||
this.methodType = methodType;
|
||||
this.resultSetType = resultSetType;
|
||||
this.resultSetConcurrency = resultSetConcurrency;
|
||||
this.resultSetHoldability = resultSetHoldability;
|
||||
this.autoGeneratedKeys = autoGeneratedKeys;
|
||||
this.columnIndexes = columnIndexes;
|
||||
this.columnNames = columnNames;
|
||||
}
|
||||
|
||||
public int getResultSetType() {
|
||||
return resultSetType;
|
||||
}
|
||||
|
||||
public int getResultSetConcurrency() {
|
||||
return resultSetConcurrency;
|
||||
}
|
||||
|
||||
public int getResultSetHoldability() {
|
||||
return resultSetHoldability;
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
@@ -821,19 +875,58 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
|
||||
if (this.methodType != that.methodType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.resultSetType != that.resultSetType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.resultSetConcurrency != that.resultSetConcurrency) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.resultSetHoldability != that.resultSetHoldability) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.autoGeneratedKeys != that.autoGeneratedKeys) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Arrays.equals(columnIndexes, that.columnIndexes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Arrays.equals(columnNames, that.columnNames)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
|
||||
result = prime * result + ((sql == null) ? 0 : sql.hashCode());
|
||||
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
|
||||
result = prime * result + ((methodType == null) ? 0 : methodType.hashCode());
|
||||
|
||||
result = prime * result + resultSetConcurrency;
|
||||
result = prime * result + resultSetHoldability;
|
||||
result = prime * result + resultSetType;
|
||||
|
||||
result = prime * result + autoGeneratedKeys;
|
||||
|
||||
result = prime * result + Arrays.hashCode(columnIndexes);
|
||||
result = prime * result + Arrays.hashCode(columnNames);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int catalogHashCode = catalog == null ? 0 : catalog.hashCode();
|
||||
int sqlHashCode = sql.hashCode();
|
||||
|
||||
return sqlHashCode ^ catalogHashCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
raw = new MockCallableStatement(null, null);
|
||||
stmt = new PoolableCallableStatement(null,
|
||||
new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
|
||||
new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {
|
||||
|
||||
protected SQLException checkException(Throwable error) throws SQLException {
|
||||
if (error instanceof SQLException) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
raw = new MockPreparedStatement(null, null);
|
||||
stmt = new PoolablePreparedStatement(null,
|
||||
new PreparedStatementHolder(new PreparedStatementKey("", null, null), raw)) {
|
||||
new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {
|
||||
|
||||
protected SQLException checkException(Throwable error) throws SQLException {
|
||||
if (error instanceof SQLException) {
|
||||
|
||||
Reference in New Issue
Block a user