org.javasimon.jdbc4.WrapperSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javasimon-jdbc41 Show documentation
Show all versions of javasimon-jdbc41 Show documentation
Java Simon JDBC 4.1 (Java SE 7) proxy driver - must be compiled with JDK 1.7
package org.javasimon.jdbc4;
import java.sql.SQLException;
import java.sql.Wrapper;
/**
* Helper class for implementing {@link Wrapper} on wrappers.
*
* @param delegate type
* @author gquintana
*/
public final class WrapperSupport implements Wrapper {
/**
* Delegate instance.
*/
private final D delegate;
/**
* Interface implemented by delegate.
*/
private final Class delegateType;
public WrapperSupport(D delegate, Class delegateType) {
this.delegate = delegate;
this.delegateType = delegateType;
}
public boolean isWrapperFor(Class> iface) throws SQLException {
return delegateType.equals(iface) || delegate.isWrapperFor(iface);
}
public T unwrap(Class iface) throws SQLException {
if (delegateType.equals(iface)) {
return delegate.isWrapperFor(iface) ? delegate.unwrap(iface) : iface.cast(delegate);
} else {
return delegate.unwrap(iface);
}
}
}