java proxy
package jdbc.test;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Connection;
public class ProxyConnection {
public static Connection getConnection(final Connection conn) {
return (Connection) Proxy.newProxyInstance(conn.getClass()
.getClassLoader(), new Class[] { Connection.class },
new InvocationHandler() {
@Override
public Object invoke(Object arg0, Method arg1, Object[] arg2)
throws Throwable {
if (arg1.getName().equalsIgnoreCase("close")) {
System.out.println("close method is invoked!");
}
return arg1.invoke(conn, arg2);
}
});
}
}
浙公网安备 33010602011771号