net.ttddyy.dsproxy.proxy.jdk.StatementInvocationHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datasource-proxy Show documentation
Show all versions of datasource-proxy Show documentation
Provide a datasource proxy that can inject your own logic into all queries.
package net.ttddyy.dsproxy.proxy.jdk;
import net.ttddyy.dsproxy.ConnectionInfo;
import net.ttddyy.dsproxy.proxy.ProxyConfig;
import net.ttddyy.dsproxy.proxy.StatementProxyLogic;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.Statement;
/**
* Proxy InvocationHandler for {@link java.sql.Statement}.
*
* @author Tadaya Tsuyukubo
*/
public class StatementInvocationHandler implements InvocationHandler {
private StatementProxyLogic delegate;
public StatementInvocationHandler(
Statement stmt, ConnectionInfo connectionInfo,
Connection proxyConnection, ProxyConfig proxyConfig) {
this.delegate = StatementProxyLogic.Builder.create()
.statement(stmt)
.connectionInfo(connectionInfo)
.proxyConnection(proxyConnection)
.proxyConfig(proxyConfig)
.build();
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return delegate.invoke(method, args);
}
}