mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -88,6 +88,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
public int getFilterSize() {
|
||||
return filterSize;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterChain cloneChain() {
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
|
||||
|
||||
public DruidPooledConnection(DruidConnectionHolder holder){
|
||||
super(holder.getConnection());
|
||||
|
||||
|
||||
this.conn = holder.getConnection();
|
||||
this.holder = holder;
|
||||
dupCloseLogEnable = holder.getDataSource().isDupCloseLogEnable();
|
||||
@@ -140,11 +140,15 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql.
|
||||
if (holder == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (holder.isPoolPreparedStatements()) {
|
||||
try {
|
||||
rawStatement.clearParameters();
|
||||
} catch (SQLException ex) {
|
||||
if (rawStatement.getConnection().isClosed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG.error("clear parameter error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.benckmark.sql;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
public class MySqlPerfMain_visitor {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println(System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
|
||||
List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
|
||||
System.out.println(arguments);
|
||||
|
||||
String sql = "SELECT ID, NAME, AGE FROM USER WHERE ID = ?";
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
perfMySql(sql);
|
||||
}
|
||||
}
|
||||
|
||||
static long perfMySql(String sql) {
|
||||
long startYGC = TestUtils.getYoungGC();
|
||||
long startYGCTime = TestUtils.getYoungGCTime();
|
||||
long startFGC = TestUtils.getFullGC();
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
|
||||
long startMillis = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000 * 1000 * 1; ++i) {
|
||||
execMySql(statementList);
|
||||
}
|
||||
long millis = System.currentTimeMillis() - startMillis;
|
||||
|
||||
long ygc = TestUtils.getYoungGC() - startYGC;
|
||||
long ygct = TestUtils.getYoungGCTime() - startYGCTime;
|
||||
long fgc = TestUtils.getFullGC() - startFGC;
|
||||
|
||||
System.out.println("MySql\t" + millis + ", ygc " + ygc + ", ygct " + ygct + ", fgc " + fgc);
|
||||
return millis;
|
||||
}
|
||||
|
||||
static void execMySql(List<SQLStatement> statementList) {
|
||||
MySqlASTVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
|
||||
for (SQLStatement statement : statementList) {
|
||||
statement.accept(visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.alibaba.druid.bvt.filter;
|
||||
import java.sql.Clob;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -27,7 +28,9 @@ import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.mock.MockClob;
|
||||
import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxyImpl;
|
||||
@@ -43,7 +46,9 @@ public class FilterChainTest_Clob extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
statement = new StatementProxyImpl(null, null, 1);
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
ConnectionProxyImpl conn = new ConnectionProxyImpl(dataSource, null, new Properties(), 0);
|
||||
statement = new StatementProxyImpl(conn, null, 1);
|
||||
|
||||
mockResultSet = new MockResultSet(null) {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.alibaba.druid.bvt.filter;
|
||||
import java.sql.Clob;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -27,6 +28,7 @@ import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.mock.MockNClob;
|
||||
import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.NClobProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
@@ -43,7 +45,8 @@ public class FilterChainTest_NClob extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
statement = new StatementProxyImpl(null, null, 1);
|
||||
ConnectionProxyImpl conn = new ConnectionProxyImpl(dataSource, null, new Properties(), 0);
|
||||
statement = new StatementProxyImpl(conn, null, 1);
|
||||
|
||||
mockResultSet = new MockResultSet(null) {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.alibaba.druid.bvt.filter;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -29,6 +30,7 @@ import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
@@ -41,7 +43,7 @@ public class FilterChainTest_ResultSet_2 extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
ConnectionProxyImpl conn = new ConnectionProxyImpl(dataSource, null, new Properties(), 0);
|
||||
MockCallableStatement mockStmt = new MockCallableStatement(null, "") {
|
||||
|
||||
@Override
|
||||
@@ -51,7 +53,7 @@ public class FilterChainTest_ResultSet_2 extends TestCase {
|
||||
}
|
||||
};
|
||||
|
||||
statement = new CallableStatementProxyImpl(null, mockStmt, "", 1);
|
||||
statement = new CallableStatementProxyImpl(conn, mockStmt, "", 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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'))"));
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.wall.WallUtils;
|
||||
|
||||
/**
|
||||
* SQLServerWallTest
|
||||
*
|
||||
* @author RaymondXiu
|
||||
* @version 1.0, 2012-3-18
|
||||
* @see
|
||||
*/
|
||||
public class MySqlWallTest2 extends TestCase {
|
||||
|
||||
public void test_stuff() throws Exception {
|
||||
Assert.assertTrue(WallUtils.isValidateMySql(//
|
||||
"select * from person_qingjia " + //
|
||||
"where isxiao=1 " + //
|
||||
"and ((starttime between 2013-01-15 and 2013-01-15)" + //
|
||||
" or (endtime between 2013-01- 15 and 2013-01-15)" + //
|
||||
") " + //
|
||||
"order by xiaojiatime desc"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.vendor.MockExceptionSorter;
|
||||
|
||||
public class ExceptionSorterTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(true);
|
||||
dataSource.setDbType("mysql");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_exceptionSorter() throws Exception {
|
||||
Assert.assertTrue(dataSource.getExceptionSorterClassName(),
|
||||
dataSource.getExceptionSorter() instanceof MockExceptionSorter);
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("select 1");
|
||||
|
||||
stmt.execute();
|
||||
|
||||
mockConn.close();
|
||||
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user