Search in sources :

Example 6 with FilterAdapter

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

the class StatFilterOpenBlobCountTest2 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 Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException {
            return new MockBlob();
        }

        @Override
        public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException {
            return new MockBlob();
        }

        @Override
        public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, java.util.Map<String, Class<?>> map) throws SQLException {
            return new MockBlob();
        }

        @Override
        public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnIndex, java.util.Map<String, Class<?>> map) throws SQLException {
            return new MockBlob();
        }
    });
    dataSource.init();
}
Also used : SQLException(java.sql.SQLException) MockBlob(com.alibaba.druid.mock.MockBlob) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy)

Example 7 with FilterAdapter

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

the class StatFilterOpenClobCountTest2 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 Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException {
            return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(), result.getStatementProxy().getConnectionProxy(), new MockClob());
        }

        @Override
        public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException {
            return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(), result.getStatementProxy().getConnectionProxy(), new MockClob());
        }

        @Override
        public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, java.util.Map<String, Class<?>> map) throws SQLException {
            return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(), result.getStatementProxy().getConnectionProxy(), new MockClob());
        }

        @Override
        public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnIndex, java.util.Map<String, Class<?>> map) throws SQLException {
            return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(), result.getStatementProxy().getConnectionProxy(), new MockClob());
        }
    });
    dataSource.init();
}
Also used : ClobProxyImpl(com.alibaba.druid.proxy.jdbc.ClobProxyImpl) SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) MockClob(com.alibaba.druid.mock.MockClob) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy)

Example 8 with FilterAdapter

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

the class StatFilterOpenBlobCountTest 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 Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException {
            return new MockBlob();
        }

        @Override
        public Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException {
            return new MockBlob();
        }
    });
    dataSource.init();
}
Also used : MockBlob(com.alibaba.druid.mock.MockBlob) Blob(java.sql.Blob) SQLException(java.sql.SQLException) MockBlob(com.alibaba.druid.mock.MockBlob) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 9 with FilterAdapter

use of com.alibaba.druid.filter.FilterAdapter 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 10 with FilterAdapter

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

the class DruidDataSourceTest_closeError 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() {

        public void connection_close(FilterChain chain, ConnectionProxy connection) throws SQLException {
            throw new SQLException();
        }
    });
    dataSource.init();
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Aggregations

FilterAdapter (com.alibaba.druid.filter.FilterAdapter)35 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)35 FilterChain (com.alibaba.druid.filter.FilterChain)32 SQLException (java.sql.SQLException)32 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)17 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)12 Properties (java.util.Properties)9 StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)5 PreparedStatementProxy (com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)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 Log (com.alibaba.druid.support.logging.Log)2 Log4jImpl (com.alibaba.druid.support.logging.Log4jImpl)2 NoLoggingImpl (com.alibaba.druid.support.logging.NoLoggingImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Field (java.lang.reflect.Field)2 Filter (com.alibaba.druid.filter.Filter)1 MockConnection (com.alibaba.druid.mock.MockConnection)1