List of usage examples for org.apache.commons.dbcp DelegatingConnection DelegatingConnection
public DelegatingConnection(Connection c)
From source file:com.p6spy.engine.common.P6WrapperIsWrapperDelegateTest.java
@Test public void testProxyOfWrappedConnection() throws SQLException { // this will be the actual connection Connection con = new TestConnectionImpl(); // use a wrapper from DBCP to create a proxy of a proxy // Note: DBCP implements with JDBC 4.0 API so the Wrapper interface // is implemented here. DelegatingConnection underlying = new DelegatingConnection(con); Connection proxy = ProxyFactory.createProxy(underlying, new GenericInvocationHandler<Connection>(underlying)); // TestConnection is an interface of the wrapped underlying object. assertTrue(proxy.isWrapperFor(TestConnection.class)); // ResultSet is not implemented at all - false should be returned assertFalse(proxy.isWrapperFor(ResultSet.class)); }
From source file:com.p6spy.engine.common.P6WrapperUnwrapDelegateTest.java
@Test public void testProxyOfWrappedConnection() throws SQLException { // this will be the actual connection Connection con = new TestConnectionImpl(); // use a wrapper from DBCP to create a proxy of a proxy // Note: DBCP implements with JDBC 4.0 API so the Wrapper interface // is implemented here. DelegatingConnection underlying = new DelegatingConnection(con); Connection proxy = ProxyFactory.createProxy(underlying, new GenericInvocationHandler<Connection>(underlying)); // TestConnection is an interface of the actual connection but not of the proxy. Unwrapping works // but a proxy is not returned {/*from w w w. ja v a 2s.co m*/ TestConnection unwrapped = proxy.unwrap(TestConnection.class); assertFalse(ProxyFactory.isProxy(unwrapped)); } // ResultSet is not implemented at all - an exception will be thrown try { proxy.unwrap(ResultSet.class); fail("Expected exception not thrown"); } catch (SQLException e) { } }