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

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

Introduction

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

Prototype

@Override
public boolean isClosed() throws SQLException 

Source Link

Document

This method should not be used by a client to determine whether or not a connection should be return to the connection pool (by calling #close() ).

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  w w. j  a  va 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 ww.ja  v a 2s  .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);
}