All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javasimon.jdbc4.WrapperSupport Maven / Gradle / Ivy

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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy