Search in sources :

Example 1 with DruidPasswordCallback

use of com.alibaba.druid.util.DruidPasswordCallback 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)

Aggregations

FilterAdapter (com.alibaba.druid.filter.FilterAdapter)1 FilterChain (com.alibaba.druid.filter.FilterChain)1 MockResultSet (com.alibaba.druid.mock.MockResultSet)1 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)1 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)1 StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)1 DruidPasswordCallback (com.alibaba.druid.util.DruidPasswordCallback)1 SQLException (java.sql.SQLException)1 NameCallback (javax.security.auth.callback.NameCallback)1