當前位置: 首頁>>代碼示例>>Java>>正文


Java Wrapper類代碼示例

本文整理匯總了Java中java.sql.Wrapper的典型用法代碼示例。如果您正苦於以下問題:Java Wrapper類的具體用法?Java Wrapper怎麽用?Java Wrapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Wrapper類屬於java.sql包,在下文中一共展示了Wrapper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wrapperIh

import java.sql.Wrapper; //導入依賴的package包/類
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;
    };

}
 
開發者ID:ops4j,項目名稱:org.ops4j.pax.transx,代碼行數:23,代碼來源:Wrappers.java

示例2: unwrap

import java.sql.Wrapper; //導入依賴的package包/類
@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);
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:25,代碼來源:AbstractWrapper.java

示例3: readGeometry

import java.sql.Wrapper; //導入依賴的package包/類
@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;
        }
    }
}
 
開發者ID:marat-gainullin,項目名稱:platypus-js,代碼行數:19,代碼來源:OracleSqlDriver.java

示例4: readGeometry

import java.sql.Wrapper; //導入依賴的package包/類
@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 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;
        }
    }
}
 
開發者ID:marat-gainullin,項目名稱:platypus-js,代碼行數:24,代碼來源:PostgreSqlDriver.java

示例5: createProxy

import java.sql.Wrapper; //導入依賴的package包/類
/**
 * 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,
                                                          new Class[]{Connection.class, Wrapper.class},
                                                          handlerFactory.apply(proxy)
      )
  );
  return proxy;
}
 
開發者ID:webonise,項目名稱:funjava,代碼行數:28,代碼來源:Connections.java

示例6: isWrapperFor

import java.sql.Wrapper; //導入依賴的package包/類
@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;
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:16,代碼來源:AbstractWrapper.java

示例7: unwrap

import java.sql.Wrapper; //導入依賴的package包/類
/** {@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);
}
 
開發者ID:openbouquet,項目名稱:HikariCP,代碼行數:15,代碼來源:ConnectionProxy.java

示例8: unwrap

import java.sql.Wrapper; //導入依賴的package包/類
/** {@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);
}
 
開發者ID:openbouquet,項目名稱:HikariCP,代碼行數:15,代碼來源:ResultSetProxy.java

示例9: unwrap

import java.sql.Wrapper; //導入依賴的package包/類
/** {@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);
}
 
開發者ID:openbouquet,項目名稱:HikariCP,代碼行數:15,代碼來源:StatementProxy.java

示例10: unwrap

import java.sql.Wrapper; //導入依賴的package包/類
@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");
    }
}
 
開發者ID:kumuluz,項目名稱:kumuluzee,代碼行數:14,代碼來源:NonJtaXADataSourceWrapper.java

示例11: isWrapperFor

import java.sql.Wrapper; //導入依賴的package包/類
@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;
}
 
開發者ID:kumuluz,項目名稱:kumuluzee,代碼行數:14,代碼來源:NonJtaXADataSourceWrapper.java

示例12: obtainJdbcReader

import java.sql.Wrapper; //導入依賴的package包/類
@Override
protected JdbcReader obtainJdbcReader() {
    return new JdbcReader(expectedFields, (Wrapper aRsultSetOrCallableStatement, int aColumnIndex, Connection aConnection) -> {
        return sqlDriver.readGeometry(aRsultSetOrCallableStatement, aColumnIndex, aConnection);
    }, (int aJdbcType, String aRDBMSType) -> {
        return sqlDriver.getTypesResolver().toApplicationType(aJdbcType, aRDBMSType);
    });
}
 
開發者ID:marat-gainullin,項目名稱:platypus-js,代碼行數:9,代碼來源:PlatypusJdbcFlowProvider.java

示例13: unwrapTo

import java.sql.Wrapper; //導入依賴的package包/類
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);
}
 
開發者ID:webonise,項目名稱:funjava,代碼行數:14,代碼來源:WrapperInvocationHandler.java

示例14: unwrap

import java.sql.Wrapper; //導入依賴的package包/類
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;
}
 
開發者ID:gquintana,項目名稱:metrics-sql,代碼行數:12,代碼來源:JdbcProxyHandler.java

示例15: isWrapperFor

import java.sql.Wrapper; //導入依賴的package包/類
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
    return ((Wrapper) realDataSource).isWrapperFor(iface);
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:5,代碼來源:P6DataSource.java


注:本文中的java.sql.Wrapper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。