微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.sql.Wrapper的实例源码

项目:org.ops4j.pax.transx    文件Wrappers.java   
private static InvocationHandler wrapperIh(Object h) {
    return (proxy,method,args) -> {
        if (method.getDeclaringClass() == Wrapper.class) {
            switch (method.getName()) {
                case "unwrap":
                    if (((Class) args[0]).isinstance(h)) {
                        return ((Class) args[0]).cast(h);
                    } else {
                        return method.invoke(h,args);
                    }
                case "isWrapperFor":
                    if (((Class) args[0]).isinstance(h)) {
                        return true;
                    } else {
                        return method.invoke(h,args);
                    }
            }
        }
        return UNHANLED;
    };

}
项目:lodsve-framework    文件AbstractWrapper.java   
@Override
public <T> T unwrap(Class<T> iface) throws sqlException {
    final Object result;
    if (iface.isAssignableFrom(getClass())) {
        // if the proxy directly implements the interface or extends it,return the proxy
        result = this;
    } else if (iface.isAssignableFrom(delegate.getClass())) {
        // if the proxied object directly implements the interface or extends it,return
        // the proxied object
        result = unwrapP6SpyProxy();
    } else if (Wrapper.class.isAssignableFrom(delegate.getClass())) {
        // if the proxied object implements the wrapper interface,then
        // return the result of it's unwrap method.
        result = ((Wrapper) unwrapP6SpyProxy()).unwrap(iface);
    } else {
  /*
     This line of code can only be reached when the underlying object does not implement the wrapper
     interface.  This would mean that either the JDBC driver or the wrapper of the underlying object
     does not implement the JDBC 4.0 API.
   */
        throw new sqlException("Can not unwrap to " + iface.getName());
    }
    return iface.cast(result);
}
项目:platypus-js    文件OraclesqlDriver.java   
@Override
public String readGeometry(Wrapper aRs,int aColumnIndex,Connection aConnection) throws sqlException {
    Object read = aRs instanceof ResultSet ? ((ResultSet) aRs).getobject(aColumnIndex) : ((CallableStatement) aRs).getobject(aColumnIndex);
    boolean wasNull = aRs instanceof ResultSet ? ((ResultSet) aRs).wasNull() : ((CallableStatement) aRs).wasNull();
    if (wasNull) {
        return null;
    } else {
        if (read instanceof STRUCT) {
            STRUCT struct = (STRUCT) read;
            GeometryConverter reader = new GeometryConverter(struct.getInternalConnection());
            Geometry geometry = reader.asGeometry(struct);
            WKTWriter writer = new WKTWriter();
            return writer.write(geometry);
        } else {
            return null;
        }
    }
}
项目:platypus-js    文件PostgresqlDriver.java   
@Override
public String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException {
    Object read = aRs instanceof ResultSet ? ((ResultSet) aRs).getobject(aColumnIndex) : ((CallableStatement) aRs).getobject(aColumnIndex);
    boolean wasNull = aRs instanceof ResultSet ? ((ResultSet) aRs).wasNull() : ((CallableStatement) aRs).wasNull();
    if (wasNull) {
        return null;
    } else {
        if (read instanceof PGgeometry) {
            PGgeometry pgg = (PGgeometry) read;
            read = pgg.getGeometry();
        }else if(read.getClass().getName().equals(PGgeometry.class.getName())){// Crazy netbeans designer!
            return read.toString();
        }
        if (read instanceof org.postgis.Geometry) {
            org.postgis.Geometry g = (org.postgis.Geometry) read;
            StringBuffer sb = new StringBuffer();
            g.outerWKT(sb);
            return sb.toString();
        } else {
            return null;
        }
    }
}
项目:funjava    文件Connections.java   
/**
 * Given a {@link java.lang.reflect.InvocationHandler},generate a proxy for a {@link java.sql.Connection}.
 * This performs the actual {@link java.lang.reflect.Proxy} logic,along with wrapping the proxy in a
 * {@link funjava.lang.reflect.WrapperInvocationHandler} proxy.
 *
 * @param connection     the connection to proxy
 * @param handlerFactory the function that will generate a handler for connection method calls.
 * @return A {@link java.sql.Connection} proxy that delegates to the handler; never {@code null}
 */
public static Connection createProxy(Connection connection,Function<Connection,InvocationHandler> handlerFactory) {
  Objects.requireNonNull(connection,"the connection to create");
  Objects.requireNonNull(handlerFactory,"the handler for connection method calls");
  ClassLoader classLoader = connection.getClass().getClassLoader();
  Connection proxy = Connection.class.cast(Proxy.newProxyInstance(
                                                                     classLoader,new Class[]{Connection.class,Wrapper.class},new WrapperInvocationHandler(connection)
      )
  );
  proxy = Connection.class.cast(Proxy.newProxyInstance(
                                                          classLoader,handlerFactory.apply(proxy)
      )
  );
  return proxy;
}
项目:lodsve-framework    文件AbstractWrapper.java   
@Override
public boolean isWrapperFor(Class<?> iface) throws sqlException {
    if (iface.isAssignableFrom(getClass())) {
        // if the proxy directly proxy the interface or extends it,return true
        return true;
    } else if (iface.isAssignableFrom(delegate.getClass())) {
        // if the proxied object directly implements the interface or extends it,return true
        return true;
    } else if (Wrapper.class.isAssignableFrom(delegate.getClass())) {
        // if the proxied object implements the wrapper interface,then
        // return the result of it's isWrapperFor method.
        return ((Wrapper) unwrapP6SpyProxy()).isWrapperFor(iface);
    }
    return false;
}
项目:HikariCP    文件ConnectionProxy.java   
/** {@inheritDoc} */
@Override
@SuppressWarnings("unchecked")
public final <T> T unwrap(Class<T> iface) throws sqlException
{
   if (iface.isinstance(delegate)) {
      return (T) delegate;
   }
   else if (delegate instanceof Wrapper) {
       return (T) delegate.unwrap(iface);
   }

   throw new sqlException("Wrapped connection is not an instance of " + iface);
}
项目:HikariCP    文件ResultSetProxy.java   
/** {@inheritDoc} */
@Override
@SuppressWarnings("unchecked")
public final <T> T unwrap(Class<T> iface) throws sqlException
{
   if (iface.isinstance(delegate)) {
      return (T) delegate;
   }
   else if (delegate instanceof Wrapper) {
       return (T) delegate.unwrap(iface);
   }

   throw new sqlException("Wrapped ResultSet is not an instance of " + iface);
}
项目:HikariCP    文件StatementProxy.java   
/** {@inheritDoc} */
@Override
@SuppressWarnings("unchecked")
public final <T> T unwrap(Class<T> iface) throws sqlException
{
   if (iface.isinstance(delegate)) {
      return (T) delegate;
   }
   else if (delegate instanceof Wrapper) {
       return (T) delegate.unwrap(iface);
   }

   throw new sqlException("Wrapped statement is not an instance of " + iface);
}
项目:kumuluzee    文件NonJtaXADataSourceWrapper.java   
@Override
public <T> T unwrap(Class<T> iface) throws sqlException {

    if (xaDataSource == null) {
        throw new sqlException("The underlying XADataSource is invalid or cannot be found");
    } else if (iface.isinstance(xaDataSource)) {
        return iface.cast(xaDataSource);
    } else if (xaDataSource instanceof Wrapper) {
        return ((java.sql.Wrapper) xaDataSource).unwrap(iface);
    } else {
        throw new sqlException("The requested interface cannot be unwrapped");
    }
}
项目:kumuluzee    文件NonJtaXADataSourceWrapper.java   
@Override
public boolean isWrapperFor(Class<?> iface) throws sqlException {

    if (xaDataSource == null) {
        throw new sqlException("The underlying XADataSource is invalid or cannot be found");
    } else if (iface.isinstance(xaDataSource)) {
        return true;
    } else if (xaDataSource instanceof Wrapper) {
        return ((java.sql.Wrapper) xaDataSource).isWrapperFor(iface);
    }

    return false;
}
项目:platypus-js    文件PlatypusJdbcFlowProvider.java   
@Override
protected JdbcReader obtainJdbcReader() {
    return new JdbcReader(expectedFields,(Wrapper aRsultSetorCallableStatement,Connection aConnection) -> {
        return sqlDriver.readGeometry(aRsultSetorCallableStatement,aColumnIndex,aConnection);
    },(int aJdbcType,String aRDBMSType) -> {
        return sqlDriver.getTypesResolver().toApplicationType(aJdbcType,aRDBMSType);
    });
}
项目:funjava    文件WrapperInvocationHandler.java   
private <A> A unwrapTo(Class<A> clazz) throws sqlException {
  Objects.requireNonNull(clazz,"class to unwrap to");
  if (wrappedisWrapper) {
    Wrapper w = ((Wrapper) wrapped);
    try {
      if (w.isWrapperFor(clazz)) return w.unwrap(clazz);
    } catch(sqlException | UndeclaredThrowableException e) {
      // Driver doesn't implement the wrapper functionality
    }
  }
  if (clazz.isAssignableFrom(wrapped.getClass())) return clazz.cast(wrapped);
  throw new sqlException("Could not unwrap " + wrapped + " to " + clazz);
}
项目:metrics-sql    文件JdbcProxyHandler.java   
protected Object unwrap(MethodInvocation<T> methodInvocation) throws sqlException {
    final Class iface = getClassArg(methodInvocation);
    final Wrapper delegateWrapper = (Wrapper) delegate;
    Object result;
    if (isDelegateType(iface)) {
        result = delegateWrapper.isWrapperFor(iface) ? delegateWrapper.unwrap(iface) : iface.cast(delegateWrapper);
    } else {
        result = delegateWrapper.unwrap(iface);
    }
    return result;
}
项目:lodsve-framework    文件P6DataSource.java   
@Override
public boolean isWrapperFor(Class<?> iface) throws sqlException {
    return ((Wrapper) realDataSource).isWrapperFor(iface);
}
项目:HikariCP    文件ConnectionProxy.java   
/** {@inheritDoc} */
@Override
public final boolean isWrapperFor(Class<?> iface) throws sqlException
{
   return iface.isinstance(delegate) || (delegate instanceof Wrapper && delegate.isWrapperFor(iface));
}
项目:platypus-js    文件MysqLsqlDriver.java   
@Override
public String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException {
    return null;
}
项目:platypus-js    文件Db2sqlDriver.java   
@Override
public String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException {
    return null;
}
项目:platypus-js    文件H2sqlDriver.java   
@Override
public String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException {
    return null;
}
项目:platypus-js    文件GenericsqlDriver.java   
@Override
public String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException {
    return null;
}
项目:platypus-js    文件MssqlsqlDriver.java   
@Override
public String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException {
    return null;
}
项目:funjava    文件WrapperInvocationHandler.java   
public WrapperInvocationHandler(final T wrapped) {
  Objects.requireNonNull(wrapped,"object to be wrapped");
  this.wrapped = wrapped;
  this.wrappedisWrapper = this.wrapped instanceof Wrapper;
}
项目:funjava    文件WrapperInvocationHandler.java   
private boolean isWrapped(Class<?> clazz) throws sqlException {
  Objects.requireNonNull(clazz,"class to check for wrapping");
  if (clazz.isAssignableFrom(wrapped.getClass())) return true;
  if (wrappedisWrapper) return ((Wrapper) wrapped).isWrapperFor(clazz);
  return false;
}
项目:paradoxdriver    文件Utils.java   
/**
 * Returns an object that implements the given interface to allow access to
 * non-standard methods,or standard methods not exposed by the proxy.
 *
 * @param <T>
 *            the type of the class modeled by this Class object.
 * @param wrapper
 *            the wrapper class.
 * @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.2
 */
@SuppressWarnings("unchecked")
public static <T> T unwrap(final Wrapper wrapper,final Class<T> iFace) throws sqlException {
    if (wrapper.isWrapperFor(iFace)) {
        return (T) wrapper;
    }
    throw new sqlException("Type not found.",sqlStates.TYPE_NOT_FOUND.getValue());
}
项目:paradoxdriver    文件Utils.java   
/**
 * Returns true if this either implements the interface argument or is
 * directly or indirectly a wrapper for an object that does. Returns false
 * otherwise..
 *
 * @param wrapper
 *            wrapper to test for.
 * @param iFace
 *            a Class defining an interface.
 * @return true if this implements the interface or directly or indirectly
 *         wraps an object that does.
 * @since 1.2
 */
public static boolean isWrapperFor(final Wrapper wrapper,final Class<?> iFace) {
    return wrapper.getClass().isAssignableFrom(iFace);
}
项目:platypus-js    文件JdbcReader.java   
public String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException;
项目:platypus-js    文件sqlDriver.java   
public abstract String readGeometry(Wrapper aRs,Connection aConnection) throws sqlException;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。