/** * Returns an object that implements the given interface to allow access to non-standard methods, * or standard methods not exposed by the proxy. The result may be either the object found to * implement the interface or a proxy for that object. If the receiver implements the interface * then that is the object. If the receiver is a wrapper and the wrapped object implements the * interface then that is the object. Otherwise the object is the result of calling <code>unwrap * </code> recursively on the wrapped object. If the receiver is not a wrapper and does not * implement the interface, then an <code>SQLException</code> is thrown. * * @param iface A Class defining an interface that the result must implement. * @return an object that implements the interface. May be a proxy for the actual implementing * object. * @throws java.sql.SQLException If no object found that implements the interface * @since 1.6 */ public synchronized <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException { try { if ("java.sql.Statement".equals(iface.getName()) || "java.sql.PreparedStatement".equals(iface.getName()) || "java.sql.Wrapper.class".equals(iface.getName())) { return iface.cast(this); } if (unwrappedInterfaces == null) { unwrappedInterfaces = new HashMap(); } Object cachedUnwrapped = unwrappedInterfaces.get(iface); if (cachedUnwrapped == null) { if (cachedUnwrapped == null) { cachedUnwrapped = Proxy.newProxyInstance( this.wrappedStmt.getClass().getClassLoader(), new Class[] {iface}, new ConnectionErrorFiringInvocationHandler(this.wrappedStmt)); unwrappedInterfaces.put(iface, cachedUnwrapped); } unwrappedInterfaces.put(iface, cachedUnwrapped); } return iface.cast(cachedUnwrapped); } catch (ClassCastException cce) { throw SQLError.createSQLException( "Unable to unwrap to " + iface.toString(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor); } }
/** * Returns <code>this</code> if this class implements the interface * * @param interfaces a Class defining an interface * @return an object that implements the interface * @throws java.sql.SQLException if no object if found that implements the interface */ public <T> T unwrap(java.lang.Class<T> interfaces) throws SQLException { try { return interfaces.cast(this); } catch (ClassCastException cce) { throw new SqlException(null, new ClientMessageId(SQLState.UNABLE_TO_UNWRAP), interfaces) .getSQLException(); } }
/** * Returns <code>this</code> if this class implements the interface * * @param interfaces a Class defining an interface * @return an object that implements the interface * @throws java.sql.SQLExption if no object if found that implements the interface */ public <T> T unwrap(java.lang.Class<T> interfaces) throws SQLException { checkStatus(); try { return interfaces.cast(this); } catch (ClassCastException cce) { throw newSQLException(SQLState.UNABLE_TO_UNWRAP, interfaces); } }
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException { try { // This works for classes that aren't actually wrapping anything return iface.cast(this); } catch (ClassCastException cce) { throw SQLError.createSQLException("Unable to unwrap to " + iface.toString(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } }
/** * Returns <code>this</code> if this class implements the interface * * @param interfaces a Class defining an interface * @return an object that implements the interface * @throws java.sql.SQLExption if no object if found that implements the interface */ public final <T> T unwrap(java.lang.Class<T> interfaces) throws SQLException { try { if (getRealConnection().isClosed()) throw Util.noCurrentConnection(); // Derby does not implement non-standard methods on // JDBC objects try { return interfaces.cast(this); } catch (ClassCastException cce) { throw Util.generateCsSQLException(SQLState.UNABLE_TO_UNWRAP, interfaces); } } catch (SQLException sqle) { notifyException(sqle); throw sqle; } }
private static <T> T __check_arg__(java.lang.Class<T> expectedClass, Object argument) { T result = null; if (java.lang.Integer.class.equals(expectedClass) && argument instanceof Double) { result = (T) new java.lang.Integer(((Double) argument).intValue()); } else if (java.lang.Float.class.equals(expectedClass) && argument instanceof Double) { result = (T) new java.lang.Float(((Double) argument).floatValue()); } else { try { result = expectedClass.cast(argument); } catch (Throwable ex) { throw new IllegalArgumentException( String.format( "Bad parameter type in call to %s. Found '%s' when expected '%s'.", "nbActions", argument.getClass().getName(), expectedClass.getName())); } } return result; }