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

net.ttddyy.dsproxy.proxy.jdk.StatementResultSetResultInvocationHandler Maven / Gradle / Ivy

There is a newer version: 1.10
Show newest version
package net.ttddyy.dsproxy.proxy.jdk;

import net.ttddyy.dsproxy.proxy.ProxyJdbcObject;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * This proxies any {@link java.sql.ResultSet} results so that they can be consumed more than once.
 *
 * @param  The {@link java.sql.Statement} type the proxy is for.
 * @author Liam Williams
 * @since 1.4
 */
class StatementResultSetResultInvocationHandler implements InvocationHandler {

    private final T target;

    private StatementResultSetResultInvocationHandler(T target) {
        this.target = target;
    }

    public static  T statementResultSetResultProxy(T target, Class interfaceToProxy) {
        return interfaceToProxy.cast(Proxy.newProxyInstance(ProxyJdbcObject.class.getClassLoader(), new Class[]{ProxyJdbcObject.class, interfaceToProxy}, new StatementResultSetResultInvocationHandler(target)));
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(target, args);
        if (result instanceof ResultSet) {
            return ResultSetInvocationHandler.proxy((ResultSet) result);
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy