Example usage for org.hibernate.engine.jdbc.spi JdbcServices getBootstrapJdbcConnectionAccess

List of usage examples for org.hibernate.engine.jdbc.spi JdbcServices getBootstrapJdbcConnectionAccess

Introduction

In this page you can find the example usage for org.hibernate.engine.jdbc.spi JdbcServices getBootstrapJdbcConnectionAccess.

Prototype

JdbcConnectionAccess getBootstrapJdbcConnectionAccess();

Source Link

Document

Obtain a JdbcConnectionAccess usable from bootstrap actions (hbm2ddl.auto, Dialect resolution, etc).

Usage

From source file:org.jadira.usertype.spi.shared.AbstractUserTypeHibernateIntegrator.java

License:Apache License

private boolean use42Api(String jdbc42Apis, SessionFactoryImplementor sessionFactory) {

    boolean use42Api;
    if (jdbc42Apis == null) {

        if (JavaVersion.getMajorVersion() >= 1 && JavaVersion.getMinorVersion() >= 8) {

            Connection conn = null;
            try {
                JdbcServices jdbcServices = sessionFactory.getServiceRegistry().getService(JdbcServices.class);
                conn = jdbcServices.getBootstrapJdbcConnectionAccess().obtainConnection();

                DatabaseMetaData dmd = conn.getMetaData();
                int driverMajorVersion = dmd.getDriverMajorVersion();
                int driverMinorVersion = dmd.getDriverMinorVersion();

                if (driverMajorVersion >= 5) {
                    use42Api = true;//from  ww  w  .  j ava 2s.com
                } else if (driverMajorVersion >= 4 && driverMinorVersion >= 2) {
                    use42Api = true;
                } else {
                    use42Api = false;
                }
            } catch (SQLException e) {
                use42Api = false;
            } catch (NoSuchMethodError e) {
                // Occurs in Hibernate 4.2.12
                use42Api = false;
            } finally {

                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        // Ignore
                    }
                }
            }
        } else {
            use42Api = false;
        }
    } else {
        use42Api = Boolean.parseBoolean(jdbc42Apis);
    }
    return use42Api;
}