Search in sources :

Example 16 with FilterChain

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

the class DruidDataSourceTest_recycle2 method setUp.

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

        public void connection_rollback(FilterChain chain, ConnectionProxy connection) throws SQLException {
            throw new SQLException();
        }
    });
}
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)

Example 17 with FilterChain

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

the class DruidDataSourceTest_lastError method setUp.

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

        public void connection_setAutoCommit(FilterChain chain, ConnectionProxy connection, boolean autoCommit) throws SQLException {
            throw new SQLException();
        }
    });
}
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)

Example 18 with FilterChain

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

the class DruidPooledConnectionTest_prepareError method setUp.

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

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int autoGeneratedKeys) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int[] columnIndexes) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, String[] columnNames) throws SQLException {
            throw new SQLException();
        }

        @Override
        public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
            throw new SQLException();
        }

        @Override
        public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
            throw new SQLException();
        }

        @Override
        public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
            throw new SQLException();
        }
    });
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) CallableStatementProxy(com.alibaba.druid.proxy.jdbc.CallableStatementProxy) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)

Example 19 with FilterChain

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

the class WrapImplTest method test_clone.

public void test_clone() throws Exception {
    Class.forName("com.alibaba.druid.proxy.DruidDriver");
    DruidDriver driver = (DruidDriver) DriverManager.getDriver(url);
    ConnectionProxyImpl connection = (ConnectionProxyImpl) driver.connect(url, new Properties());
    connection.getRawObject();
    FilterChain filterChain = (FilterChain) connection.createChain();
    filterChain.cloneChain();
    DataSourceProxyImpl dataSource = (DataSourceProxyImpl) connection.getDirectDataSource();
    dataSource.getId();
    Assert.assertEquals(4, dataSource.getProxyFilters().size());
    Assert.assertEquals(4, dataSource.getFilterClasses().length);
    Assert.assertNotNull(dataSource.getCreatedTime());
    Assert.assertTrue(dataSource.getCreatedTime().getTime() != 0);
    Assert.assertEquals("org.apache.derby.jdbc.EmbeddedDriver", dataSource.getRawDriverClassName());
    Assert.assertEquals(url, dataSource.getUrl());
    Assert.assertEquals("jdbc:derby:classpath:petstore-db", dataSource.getRawUrl());
    Assert.assertEquals(10, dataSource.getRawDriverMajorVersion());
    Assert.assertEquals(12, dataSource.getRawDriverMinorVersion());
    Class<?> mysql5ConnectionClass = Utils.loadClass("com.mysql.jdbc.Connection");
    if (mysql5ConnectionClass != null) {
        Assert.assertFalse(connection.isWrapperFor(mysql5ConnectionClass));
    }
    Assert.assertTrue(connection.isWrapperFor(ConnectionProxyImpl.class));
    Assert.assertTrue(connection.isWrapperFor(org.apache.derby.impl.jdbc.EmbedConnection.class));
    Assert.assertNotNull(connection.unwrap(ConnectionProxyImpl.class));
    Assert.assertNull(connection.unwrap(null));
    org.apache.derby.impl.jdbc.EmbedConnection derbyConnection = connection.unwrap(org.apache.derby.impl.jdbc.EmbedConnection.class);
    Assert.assertNotNull(derbyConnection);
    Statement statement = connection.createStatement();
    if (mysql5ConnectionClass != null) {
        Assert.assertFalse(statement.isWrapperFor(Class.forName("com.mysql.jdbc.Statement")));
    }
    Assert.assertFalse(statement.isWrapperFor(null));
    Assert.assertTrue(statement.isWrapperFor(org.apache.derby.impl.jdbc.EmbedStatement.class));
    org.apache.derby.impl.jdbc.EmbedStatement rayStatement = statement.unwrap(org.apache.derby.impl.jdbc.EmbedStatement.class);
    Assert.assertNotNull(rayStatement);
    statement.close();
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Statement(java.sql.Statement) FilterChain(com.alibaba.druid.filter.FilterChain) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) DruidDriver(com.alibaba.druid.proxy.DruidDriver) Properties(java.util.Properties)

Example 20 with FilterChain

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

the class DruidConnectionHolderTest2 method setUp.

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

        public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection) throws SQLException {
            throw new SQLException();
        }
    });
}
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

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