net.ttddyy.dsproxy.proxy.NativeJdbcExtractUtils 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;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
/**
* @author Tadaya Tsuyukubo
*/
public class NativeJdbcExtractUtils {
public static Connection getConnection(Connection connection) {
return getNativeJdbcObject(connection);
}
public static Statement getStatement(Statement statement) {
return getNativeJdbcObject(statement);
}
public static PreparedStatement getPreparedStatement(PreparedStatement preparedStatement) {
return getNativeJdbcObject(preparedStatement);
}
public static CallableStatement getCallableStatement(CallableStatement callableStatement) {
return getNativeJdbcObject(callableStatement);
}
@SuppressWarnings("unchecked")
private static T getNativeJdbcObject(T obj) {
T objToUse = obj;
while (objToUse instanceof ProxyJdbcObject) {
objToUse = (T) ((ProxyJdbcObject) objToUse).getTarget();
}
return objToUse;
}
}