mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve proxy performance
This commit is contained in:
@@ -36,7 +36,6 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
|
||||
@@ -57,6 +56,8 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
|
||||
private int closeCount;
|
||||
|
||||
private FilterChainImpl filterChain = null;
|
||||
|
||||
public ConnectionProxyImpl(DataSourceProxy dataSource, Connection connection, Properties properties, long id){
|
||||
super(connection, id);
|
||||
this.dataSource = dataSource;
|
||||
@@ -85,200 +86,319 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
return this.dataSource;
|
||||
}
|
||||
|
||||
public FilterChain createChain() {
|
||||
return new FilterChainImpl(dataSource);
|
||||
public FilterChainImpl createChain() {
|
||||
FilterChainImpl chain = this.filterChain;
|
||||
if (chain == null) {
|
||||
chain = new FilterChainImpl(dataSource);
|
||||
} else {
|
||||
this.filterChain = null;
|
||||
}
|
||||
|
||||
return chain;
|
||||
}
|
||||
|
||||
public void recycleFilterChain(FilterChainImpl chain) {
|
||||
chain.reset();
|
||||
this.filterChain = chain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
createChain().connection_clearWarnings(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_clearWarnings(this);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
createChain().connection_close(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_close(this);
|
||||
closeCount++;
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
createChain().connection_commit(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_commit(this);
|
||||
|
||||
if (transcationInfo != null) {
|
||||
transcationInfo.setEndTimeMillis();
|
||||
}
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||
return createChain().connection_createArrayOf(this, typeName, elements);
|
||||
FilterChainImpl chain = createChain();
|
||||
Array value = chain.connection_createArrayOf(this, typeName, elements);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blob createBlob() throws SQLException {
|
||||
return createChain().connection_createBlob(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
Blob value = chain.connection_createBlob(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clob createClob() throws SQLException {
|
||||
return createChain().connection_createClob(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
Clob value = chain.connection_createClob(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NClob createNClob() throws SQLException {
|
||||
return createChain().connection_createNClob(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
NClob value = chain.connection_createNClob(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLXML createSQLXML() throws SQLException {
|
||||
return createChain().connection_createSQLXML(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
SQLXML value = chain.connection_createSQLXML(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement() throws SQLException {
|
||||
return createChain().connection_createStatement(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
Statement stmt = chain.connection_createStatement(this);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
return createChain().connection_createStatement(this, resultSetType, resultSetConcurrency);
|
||||
public Statement createStatement(int resultSetType, //
|
||||
int resultSetConcurrency //
|
||||
) throws SQLException {
|
||||
FilterChainImpl chain = createChain();
|
||||
Statement stmt = chain.connection_createStatement(this, resultSetType, resultSetConcurrency);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
return createChain().connection_createStatement(this, resultSetType, resultSetConcurrency, resultSetHoldability);
|
||||
public Statement createStatement(int resultSetType, //
|
||||
int resultSetConcurrency, //
|
||||
int resultSetHoldability //
|
||||
) throws SQLException {
|
||||
FilterChainImpl chain = createChain();
|
||||
Statement stmt = chain.connection_createStatement(this, resultSetType, resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
||||
return createChain().connection_createStruct(this, typeName, attributes);
|
||||
FilterChainImpl chain = createChain();
|
||||
Struct value = chain.connection_createStruct(this, typeName, attributes);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
return createChain().connection_getAutoCommit(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.connection_getAutoCommit(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCatalog() throws SQLException {
|
||||
return createChain().connection_getCatalog(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
String value = chain.connection_getCatalog(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties getClientInfo() throws SQLException {
|
||||
return createChain().connection_getClientInfo(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
Properties value = chain.connection_getClientInfo(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientInfo(String name) throws SQLException {
|
||||
return createChain().connection_getClientInfo(this, name);
|
||||
FilterChainImpl chain = createChain();
|
||||
String value = chain.connection_getClientInfo(this, name);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoldability() throws SQLException {
|
||||
return createChain().connection_getHoldability(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.connection_getHoldability(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseMetaData getMetaData() throws SQLException {
|
||||
return createChain().connection_getMetaData(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
DatabaseMetaData value = chain.connection_getMetaData(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
return createChain().connection_getTransactionIsolation(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.connection_getTransactionIsolation(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||
return createChain().connection_getTypeMap(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
Map<String, Class<?>> value = chain.connection_getTypeMap(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return createChain().connection_getWarnings(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
SQLWarning value = chain.connection_getWarnings(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() throws SQLException {
|
||||
return createChain().connection_isClosed(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.connection_isClosed(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
return createChain().connection_isReadOnly(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.connection_isReadOnly(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
return createChain().connection_isValid(this, timeout);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.connection_isValid(this, timeout);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nativeSQL(String sql) throws SQLException {
|
||||
return createChain().connection_nativeSQL(this, sql);
|
||||
FilterChainImpl chain = createChain();
|
||||
String value = chain.connection_nativeSQL(this, sql);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||
return createChain().connection_prepareCall(this, sql);
|
||||
FilterChainImpl chain = createChain();
|
||||
CallableStatement stmt = chain.connection_prepareCall(this, sql);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
return createChain().connection_prepareCall(this, sql, resultSetType, resultSetConcurrency);
|
||||
FilterChainImpl chain = createChain();
|
||||
CallableStatement stmt = chain.connection_prepareCall(this, sql, resultSetType, resultSetConcurrency);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
|
||||
int resultSetHoldability) throws SQLException {
|
||||
return createChain().connection_prepareCall(this, sql, resultSetType, resultSetConcurrency,
|
||||
FilterChainImpl chain = createChain();
|
||||
CallableStatement stmt = chain.connection_prepareCall(this, sql, resultSetType, resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return createChain().connection_prepareStatement(this, sql);
|
||||
FilterChainImpl chain = createChain();
|
||||
PreparedStatement stmt = chain.connection_prepareStatement(this, sql);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||
return createChain().connection_prepareStatement(this, sql, autoGeneratedKeys);
|
||||
FilterChainImpl chain = createChain();
|
||||
PreparedStatement stmt = chain.connection_prepareStatement(this, sql, autoGeneratedKeys);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||
return createChain().connection_prepareStatement(this, sql, columnIndexes);
|
||||
FilterChainImpl chain = createChain();
|
||||
PreparedStatement stmt = chain.connection_prepareStatement(this, sql, columnIndexes);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||
return createChain().connection_prepareStatement(this, sql, columnNames);
|
||||
FilterChainImpl chain = createChain();
|
||||
PreparedStatement stmt = chain.connection_prepareStatement(this, sql, columnNames);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||
throws SQLException {
|
||||
return createChain().connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency);
|
||||
FilterChainImpl chain = createChain();
|
||||
PreparedStatement stmt = chain.connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
|
||||
int resultSetHoldability) throws SQLException {
|
||||
return createChain().connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency,
|
||||
FilterChainImpl chain = createChain();
|
||||
PreparedStatement stmt = chain.connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
recycleFilterChain(chain);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||
createChain().connection_releaseSavepoint(this, savepoint);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_releaseSavepoint(this, savepoint);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
createChain().connection_rollback(this);
|
||||
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_rollback(this);
|
||||
recycleFilterChain(chain);
|
||||
if (transcationInfo != null) {
|
||||
transcationInfo.setEndTimeMillis();
|
||||
}
|
||||
@@ -286,8 +406,9 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
|
||||
@Override
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
createChain().connection_rollback(this, savepoint);
|
||||
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_rollback(this, savepoint);
|
||||
recycleFilterChain(chain);
|
||||
if (transcationInfo != null) {
|
||||
transcationInfo.setEndTimeMillis();
|
||||
}
|
||||
@@ -305,52 +426,74 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
transcationInfo = null;
|
||||
}
|
||||
|
||||
createChain().connection_setAutoCommit(this, autoCommit);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setAutoCommit(this, autoCommit);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
createChain().connection_setCatalog(this, catalog);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setCatalog(this, catalog);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||
createChain().connection_setClientInfo(this, properties);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setClientInfo(this, properties);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||
createChain().connection_setClientInfo(this, name, value);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setClientInfo(this, name, value);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
createChain().connection_setHoldability(this, holdability);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setHoldability(this, holdability);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
createChain().connection_setReadOnly(this, readOnly);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setReadOnly(this, readOnly);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
return createChain().connection_setSavepoint(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
Savepoint savepoint = chain.connection_setSavepoint(this);
|
||||
recycleFilterChain(chain);
|
||||
return savepoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint(String name) throws SQLException {
|
||||
return createChain().connection_setSavepoint(this, name);
|
||||
FilterChainImpl chain = createChain();
|
||||
Savepoint savepoint = chain.connection_setSavepoint(this, name);
|
||||
recycleFilterChain(chain);
|
||||
return savepoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionIsolation(int level) throws SQLException {
|
||||
createChain().connection_setTransactionIsolation(this, level);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setTransactionIsolation(this, level);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||
createChain().connection_setTypeMap(this, map);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.connection_setTypeMap(this, map);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
public void setSchema(String schema) throws SQLException {
|
||||
@@ -378,7 +521,7 @@ public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionP
|
||||
if (iface == this.getClass() || iface == ConnectionProxy.class) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
return super.unwrap(iface);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
|
||||
@@ -51,6 +50,8 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
|
||||
protected Integer updateCount = null;
|
||||
|
||||
private FilterChainImpl filterChain = null;
|
||||
|
||||
public StatementProxyImpl(ConnectionProxy connection, Statement statement, long id){
|
||||
super(statement, id);
|
||||
this.connection = connection;
|
||||
@@ -65,8 +66,20 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
return this.statement;
|
||||
}
|
||||
|
||||
public FilterChain createChain() {
|
||||
return new FilterChainImpl(this.connection.getDirectDataSource());
|
||||
public FilterChainImpl createChain() {
|
||||
FilterChainImpl chain = this.filterChain;
|
||||
if (chain == null) {
|
||||
chain = new FilterChainImpl(this.getConnectionProxy().getDirectDataSource());
|
||||
} else {
|
||||
this.filterChain = null;
|
||||
}
|
||||
|
||||
return chain;
|
||||
}
|
||||
|
||||
public void recycleFilterChain(FilterChainImpl chain) {
|
||||
chain.reset();
|
||||
this.filterChain = chain;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,7 +94,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
|
||||
@Override
|
||||
public void cancel() throws SQLException {
|
||||
createChain().statement_cancel(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_cancel(this);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,18 +105,24 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
batchSqlList = new ArrayList<String>();
|
||||
}
|
||||
|
||||
createChain().statement_clearBatch(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_clearBatch(this);
|
||||
recycleFilterChain(chain);
|
||||
batchSqlList.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
createChain().statement_clearWarnings(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_clearWarnings(this);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
createChain().statement_close(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_close(this);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,7 +133,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
firstResultSet = createChain().statement_execute(this, sql);
|
||||
FilterChainImpl chain = createChain();
|
||||
firstResultSet = chain.statement_execute(this, sql);
|
||||
recycleFilterChain(chain);
|
||||
return firstResultSet;
|
||||
}
|
||||
|
||||
@@ -124,7 +147,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
firstResultSet = createChain().statement_execute(this, sql, autoGeneratedKeys);
|
||||
FilterChainImpl chain = createChain();
|
||||
firstResultSet = chain.statement_execute(this, sql, autoGeneratedKeys);
|
||||
recycleFilterChain(chain);
|
||||
return firstResultSet;
|
||||
}
|
||||
|
||||
@@ -136,7 +161,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
firstResultSet = createChain().statement_execute(this, sql, columnIndexes);
|
||||
FilterChainImpl chain = createChain();
|
||||
firstResultSet = chain.statement_execute(this, sql, columnIndexes);
|
||||
recycleFilterChain(chain);
|
||||
return firstResultSet;
|
||||
}
|
||||
|
||||
@@ -148,7 +175,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
firstResultSet = createChain().statement_execute(this, sql, columnNames);
|
||||
FilterChainImpl chain = createChain();
|
||||
firstResultSet = chain.statement_execute(this, sql, columnNames);
|
||||
recycleFilterChain(chain);
|
||||
return firstResultSet;
|
||||
}
|
||||
|
||||
@@ -159,8 +188,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
int[] updateCounts = createChain().statement_executeBatch(this);
|
||||
|
||||
FilterChainImpl chain = createChain();
|
||||
int[] updateCounts = chain.statement_executeBatch(this);
|
||||
recycleFilterChain(chain);
|
||||
if (updateCounts != null && updateCounts.length == 1) {
|
||||
updateCount = updateCounts[0];
|
||||
}
|
||||
@@ -177,7 +207,10 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
return createChain().statement_executeQuery(this, sql);
|
||||
FilterChainImpl chain = createChain();
|
||||
ResultSet resultSet = chain.statement_executeQuery(this, sql);
|
||||
recycleFilterChain(chain);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,7 +221,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
updateCount = createChain().statement_executeUpdate(this, sql);
|
||||
FilterChainImpl chain = createChain();
|
||||
updateCount = chain.statement_executeUpdate(this, sql);
|
||||
recycleFilterChain(chain);
|
||||
return updateCount;
|
||||
}
|
||||
|
||||
@@ -200,7 +235,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
updateCount = createChain().statement_executeUpdate(this, sql, autoGeneratedKeys);
|
||||
FilterChainImpl chain = createChain();
|
||||
updateCount = chain.statement_executeUpdate(this, sql, autoGeneratedKeys);
|
||||
recycleFilterChain(chain);
|
||||
return updateCount;
|
||||
}
|
||||
|
||||
@@ -212,7 +249,9 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
updateCount = createChain().statement_executeUpdate(this, sql, columnIndexes);
|
||||
FilterChainImpl chain = createChain();
|
||||
updateCount = chain.statement_executeUpdate(this, sql, columnIndexes);
|
||||
recycleFilterChain(chain);
|
||||
return updateCount;
|
||||
}
|
||||
|
||||
@@ -224,139 +263,207 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
lastExecuteStartNano = -1L;
|
||||
lastExecuteTimeNano = -1L;
|
||||
|
||||
updateCount = createChain().statement_executeUpdate(this, sql, columnNames);
|
||||
FilterChainImpl chain = createChain();
|
||||
updateCount = chain.statement_executeUpdate(this, sql, columnNames);
|
||||
recycleFilterChain(chain);
|
||||
return updateCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return createChain().statement_getConnection(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
Connection conn = chain.statement_getConnection(this);
|
||||
recycleFilterChain(chain);
|
||||
return conn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchDirection() throws SQLException {
|
||||
return createChain().statement_getFetchDirection(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getFetchDirection(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchSize() throws SQLException {
|
||||
return createChain().statement_getFetchSize(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getFetchSize(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getGeneratedKeys() throws SQLException {
|
||||
return createChain().statement_getGeneratedKeys(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
ResultSet value = chain.statement_getGeneratedKeys(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFieldSize() throws SQLException {
|
||||
return createChain().statement_getMaxFieldSize(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getMaxFieldSize(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxRows() throws SQLException {
|
||||
return createChain().statement_getMaxRows(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getMaxRows(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMoreResults() throws SQLException {
|
||||
updateCount = null;
|
||||
return createChain().statement_getMoreResults(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.statement_getMoreResults(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMoreResults(int current) throws SQLException {
|
||||
updateCount = null;
|
||||
return createChain().statement_getMoreResults(this, current);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.statement_getMoreResults(this, current);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getQueryTimeout() throws SQLException {
|
||||
return createChain().statement_getQueryTimeout(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getQueryTimeout(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getResultSet() throws SQLException {
|
||||
return createChain().statement_getResultSet(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
ResultSet value = chain.statement_getResultSet(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetConcurrency() throws SQLException {
|
||||
return createChain().statement_getResultSetConcurrency(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getResultSetConcurrency(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetHoldability() throws SQLException {
|
||||
return createChain().statement_getResultSetHoldability(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getResultSetHoldability(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetType() throws SQLException {
|
||||
return createChain().statement_getResultSetType(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
int value = chain.statement_getResultSetType(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
// bug fixed for oracle
|
||||
@Override
|
||||
public int getUpdateCount() throws SQLException {
|
||||
if (updateCount == null) {
|
||||
updateCount = createChain().statement_getUpdateCount(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
updateCount = chain.statement_getUpdateCount(this);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
return updateCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
return createChain().statement_getWarnings(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
SQLWarning value = chain.statement_getWarnings(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() throws SQLException {
|
||||
return createChain().statement_isClosed(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.statement_isClosed(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPoolable() throws SQLException {
|
||||
return createChain().statement_isPoolable(this);
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.statement_isPoolable(this);
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCursorName(String name) throws SQLException {
|
||||
createChain().statement_setCursorName(this, name);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setCursorName(this, name);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||
createChain().statement_setEscapeProcessing(this, enable);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setEscapeProcessing(this, enable);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchDirection(int direction) throws SQLException {
|
||||
createChain().statement_setFetchDirection(this, direction);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setFetchDirection(this, direction);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchSize(int rows) throws SQLException {
|
||||
createChain().statement_setFetchSize(this, rows);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setFetchSize(this, rows);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxFieldSize(int max) throws SQLException {
|
||||
createChain().statement_setMaxFieldSize(this, max);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setMaxFieldSize(this, max);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxRows(int max) throws SQLException {
|
||||
createChain().statement_setMaxRows(this, max);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setMaxRows(this, max);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPoolable(boolean poolable) throws SQLException {
|
||||
createChain().statement_setPoolable(this, poolable);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setPoolable(this, poolable);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQueryTimeout(int seconds) throws SQLException {
|
||||
createChain().statement_setQueryTimeout(this, seconds);
|
||||
FilterChainImpl chain = createChain();
|
||||
chain.statement_setQueryTimeout(this, seconds);
|
||||
recycleFilterChain(chain);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ public class MySqlPerfMain_visitor {
|
||||
|
||||
String sql = "SELECT ID, NAME, AGE FROM USER WHERE ID = ?";
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
perfMySql(sql);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class MySqlPerfMain_visitor {
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
|
||||
long startMillis = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000 * 100 * 1; ++i) {
|
||||
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
|
||||
execMySql(statementList);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - startMillis;
|
||||
|
||||
@@ -29,22 +29,6 @@ import com.alibaba.druid.wall.WallUtils;
|
||||
* @see
|
||||
*/
|
||||
public class MySqlWallTest1 extends TestCase {
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public MySqlWallTest1(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void test_stuff() throws Exception {
|
||||
Assert.assertTrue(WallUtils.isValidateMySql(//
|
||||
"select count(*) from (select DATE_FORMAT(staydate,'%m月') as month,sum(a) as addnum,sum(q) as quitnum from (select staydate,1 as a,0 as q from add_person union all select quitdate,0 as a,1 as q from quit_person) t where (DATE_FORMAT(staydate,'%Y')= ? ) group by DATE_FORMAT(staydate,'%Y-%m'))"));
|
||||
|
||||
Reference in New Issue
Block a user