Search in sources :

Example 1 with StatementProxy

use of com.alibaba.druid.proxy.jdbc.StatementProxy in project druid by alibaba.

the class DruidPooledPreparedStatementTest1 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setInitialSize(1);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        @Override
        public boolean preparedStatement_execute(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        @Override
        public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        public void preparedStatement_clearParameters(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        @Override
        public int[] statement_executeBatch(FilterChain chain, StatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        @Override
        public ParameterMetaData preparedStatement_getParameterMetaData(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }
    });
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy) ParameterMetaData(java.sql.ParameterMetaData)

Example 2 with StatementProxy

use of com.alibaba.druid.proxy.jdbc.StatementProxy in project druid by alibaba.

the class StatFilterExecErrorTest method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setFilters("stat");
    dataSource.setTestOnBorrow(false);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        @Override
        public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
            throw new SQLException();
        }

        @Override
        public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }
    });
    dataSource.init();
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)

Example 3 with StatementProxy

use of com.alibaba.druid.proxy.jdbc.StatementProxy in project druid by alibaba.

the class DruidDataSourceTest6 method setUp.

protected void setUp() throws Exception {
    returnEmptyCount.set(0);
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(true);
    dataSource.setInitialSize(1);
    dataSource.setValidationQuery("select 1");
    dataSource.setValidationQueryTimeout(10);
    dataSource.setQueryTimeout(100);
    dataSource.setUserCallback(new NameCallback("xx") {
    });
    dataSource.setPasswordCallback(new DruidPasswordCallback() {

        @Override
        public char[] getPassword() {
            return "xx".toCharArray();
        }
    });
    dataSource.getProxyFilters().add(new FilterAdapter() {

        public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
            if (errorCount.get() > 0) {
                errorCount.decrementAndGet();
                throw new RuntimeException();
            }
            if (returnEmptyCount.get() > 0) {
                returnEmptyCount.decrementAndGet();
                return new ResultSetProxyImpl(statement, new MockResultSet(statement), 0, sql);
            }
            return chain.statement_executeQuery(statement, sql);
        }
    });
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) MockResultSet(com.alibaba.druid.mock.MockResultSet) ResultSetProxyImpl(com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) NameCallback(javax.security.auth.callback.NameCallback) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) DruidPasswordCallback(com.alibaba.druid.util.DruidPasswordCallback) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy)

Example 4 with StatementProxy

use of com.alibaba.druid.proxy.jdbc.StatementProxy 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)

Example 5 with StatementProxy

use of com.alibaba.druid.proxy.jdbc.StatementProxy in project druid by alibaba.

the class AsyncCloseTest2 method setUp.

protected void setUp() throws Exception {
    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(128);
    closeExecutor = Executors.newFixedThreadPool(128);
}
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

StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)9 SQLException (java.sql.SQLException)7 FilterChain (com.alibaba.druid.filter.FilterChain)6 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)6 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)5 PreparedStatementProxy (com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)5 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)4 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)3 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)2 MockResultSet (com.alibaba.druid.mock.MockResultSet)2 CallableStatementProxy (com.alibaba.druid.proxy.jdbc.CallableStatementProxy)2 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)2 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)2 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)2 Log (com.alibaba.druid.support.logging.Log)2 Log4jImpl (com.alibaba.druid.support.logging.Log4jImpl)2 NoLoggingImpl (com.alibaba.druid.support.logging.NoLoggingImpl)2 Field (java.lang.reflect.Field)2 Properties (java.util.Properties)2 FilterEventAdapter (com.alibaba.druid.filter.FilterEventAdapter)1