/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package org.hibernate.engine.jdbc;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JdbcSupportLoader {
private static final Logger log = LoggerFactory
.getLogger(JdbcSupportLoader.class);
private static final Class[] NO_ARG_SIG = new Class[0];
private static final Object[] NO_ARGS = new Object[0];
public static JdbcSupport loadJdbcSupport(Connection jdbcConnection) {
return new JdbcSupportImpl(useContextualLobCreation(jdbcConnection));
}
private static boolean useContextualLobCreation(Connection jdbcConnection)
{
if (jdbcConnection == null) {
log.info("Disabling contextual LOB creation as connection was null");
return false;
}
Method createClobMethod;
try
{
DatabaseMetaData meta = jdbcConnection.getMetaData();
if (meta.getJDBCMajorVersion() < 4) {
log.info("Disabling contextual LOB creation as JDBC driver reported JDBC version [" + meta.getJDBCMajorVersion() + "] less than 4");
return false;
}
}
catch (SQLException connectionClass)
{
Class connectionClass = Connection.class;
createClobMethod = connectionClass.getMethod("createClob", NO_ARG_SIG);
if (!(createClobMethod.getDeclaringClass().equals(Connection.class)));
}
catch (NoSuchMethodException ignore)
{
try
{
Object clob = createClobMethod.invoke(jdbcConnection, NO_ARGS);
try {
Method freeMethod = clob.getClass().getMethod("free", NO_ARG_SIG);
freeMethod.invoke(clob, NO_ARGS);
}
catch (Throwable ignore) {
log.trace("Unable to free CLOB created to test createClob() implementation : " + ignore);
}
return true;
}
catch (Throwable t) {
log.info("Disabling contextual LOB creation as createClob() method threw error : " + t);
break label203:
ignore =
ignore; }
}
label203: return false;
}
}