Search in sources :

Example 1 with FilterChain

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

the class DruidConnectionHolderTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    driver = new Driver();
    if (driver.getMajorVersion() == 5) {
        exceptionClass = Class.forName("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException");
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setTestOnBorrow(false);
        dataSource.setInitialSize(1);
        dataSource.getProxyFilters().add(new FilterAdapter() {

            public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection) throws SQLException {
                throw createSyntaxException();
            }
        });
    }
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) Driver(com.mysql.jdbc.Driver) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Example 2 with FilterChain

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

the class DruidConnectionHolderTest3 method setUp.

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

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

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

the class DataSourceProxyImpl method connect.

public ConnectionProxy connect(Properties info) throws SQLException {
    this.properties = info;
    PasswordCallback passwordCallback = this.config.getPasswordCallback();
    if (passwordCallback != null) {
        char[] chars = passwordCallback.getPassword();
        String password = new String(chars);
        info.put("password", password);
    }
    NameCallback userCallback = this.config.getUserCallback();
    if (userCallback != null) {
        String user = userCallback.getName();
        info.put("user", user);
    }
    FilterChain chain = new FilterChainImpl(this);
    return chain.connection_connect(info);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) NameCallback(javax.security.auth.callback.NameCallback) FilterChain(com.alibaba.druid.filter.FilterChain) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 4 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 5 with FilterChain

use of com.alibaba.druid.filter.FilterChain 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)

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