Search in sources :

Example 36 with FilterChain

use of com.alibaba.druid.filter.FilterChain in project druid by alibaba.

the class AsyncCloseTest3 method setUp.

protected void setUp() throws Exception {
    // m;
    xmx = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() / (1000 * 1000);
    System.gc();
    Field logField = DruidDataSource.class.getDeclaredField("LOG");
    logField.setAccessible(true);
    Log dataSourceLog = (Log) logField.get(null);
    if (dataSourceLog instanceof Log4jImpl) {
        this.log4jLog = ((Log4jImpl) dataSourceLog).getLog();
        this.log4jOldLevel = this.log4jLog.getLevel();
        this.log4jLog.setLevel(Level.FATAL);
    } else if (dataSourceLog instanceof NoLoggingImpl) {
        noLoggingImpl = (NoLoggingImpl) dataSourceLog;
        noLoggingImpl.setErrorEnabled(false);
    }
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:");
    // dataSource.setAsyncCloseConnectionEnable(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setMaxActive(16);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        @Override
        public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
            throw new SQLException();
        }
    });
    dataSource.setExceptionSorter(new MyExceptionSorter());
    dataSource.init();
    connExecutor = Executors.newFixedThreadPool(2);
    closeExecutor = Executors.newFixedThreadPool(2);
}
Also used : Field(java.lang.reflect.Field) Log4jImpl(com.alibaba.druid.support.logging.Log4jImpl) Log(com.alibaba.druid.support.logging.Log) SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) NoLoggingImpl(com.alibaba.druid.support.logging.NoLoggingImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

FilterChain (com.alibaba.druid.filter.FilterChain)36 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)33 SQLException (java.sql.SQLException)33 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)32 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)18 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)13 Properties (java.util.Properties)12 StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)6 PreparedStatementProxy (com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)4 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)3 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)3 MockBlob (com.alibaba.druid.mock.MockBlob)2 MockClob (com.alibaba.druid.mock.MockClob)2 CallableStatementProxy (com.alibaba.druid.proxy.jdbc.CallableStatementProxy)2 ClobProxyImpl (com.alibaba.druid.proxy.jdbc.ClobProxyImpl)2 ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)2 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)2 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)2 Log (com.alibaba.druid.support.logging.Log)2 Log4jImpl (com.alibaba.druid.support.logging.Log4jImpl)2