Example usage for org.apache.commons.dbcp2 PoolableConnection validate

List of usage examples for org.apache.commons.dbcp2 PoolableConnection validate

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 PoolableConnection validate.

Prototype

public void validate(String sql, int timeout) throws SQLException 

Source Link

Document

Validates the connection, using the following algorithm:
  1. If fastFailValidation (constructor argument) is true and this connection has previously thrown a fatal disconnection exception, a SQLException is thrown.

    Usage

    From source file:JDBCPool.dbcp.demo.sourcecode.PoolableConnectionFactory.java

    public void validateConnection(PoolableConnection conn) throws SQLException {
        if (conn.isClosed()) {
            throw new SQLException("validateConnection: connection closed");
        }/*from   w  ww  . j  av a  2s  .c o m*/
        conn.validate(_validationQuery, _validationQueryTimeout);
    }
    

    From source file:org.ops4j.pax.jdbc.pool.dbcp2.impl.BeanConfigTest.java

    @Test
    public void testPoolableConnectionFactory() throws Exception {
        Map<String, String> props = new HashMap<String, String>();
        props.put("validationQuery", "dummyQuery");
        props.put("validationQueryTimeout", "1");
        PoolableConnectionFactory pcf = new PoolableConnectionFactory(null, null);
        BeanConfig.configure(pcf, props);/* w  w w. ja v  a 2  s .c  o m*/
    
        PoolableConnection connection = EasyMock.createMock(PoolableConnection.class);
        connection.validate(EasyMock.eq("dummyQuery"), EasyMock.eq(1));
        EasyMock.expectLastCall();
        EasyMock.expect(connection.isClosed()).andReturn(false);
        EasyMock.replay(connection);
    
        pcf.validateConnection(connection);
    
        EasyMock.verify(connection);
    }