本文整理匯總了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;
};
}
示例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);
}
示例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;
}
}
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
}
示例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;
}
示例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);
});
}
示例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);
}
示例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;
}
示例15: isWrapperFor
import java.sql.Wrapper; //導入依賴的package包/類
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return ((Wrapper) realDataSource).isWrapperFor(iface);
}