List of usage examples for java.sql Wrapper unwrap
<T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException;
From source file:org.nuclos.server.dblayer.impl.SQLUtils2.java
public static <T> T unwrap(Object obj, Class<T> iface) throws SQLException { if (obj.getClass().getName() .equals("org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper")) { Method method;//from w w w . ja v a2 s.com try { method = obj.getClass().getMethod("getInnermostDelegate"); method.setAccessible(true); return unwrap(method.invoke(obj), iface); } catch (Exception e) { throw new CommonFatalException( "Error calling org.jboss.resource.adapter.jdbc.WrappedConnection#getUnderlyingConnection()", e); } } if (iface.isInstance(obj)) { return iface.cast(obj); } if (obj instanceof Wrapper) { try { Wrapper wrapper = (Wrapper) obj; if (wrapper.isWrapperFor(iface)) { obj = wrapper.unwrap(iface); } } catch (AbstractMethodError e) { // this class didn't implement the interface completely (pre JDBC 4.0 implementation) } } return null; }