Search in sources :

Example 6 with JdbcConnectionAccess

use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.

the class DateTimeParameterTest method dropProcedures.

private void dropProcedures(HibernateEntityManagerFactory emf) {
    final SessionFactoryImplementor sf = emf.unwrap(SessionFactoryImplementor.class);
    final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService(JdbcServices.class).getBootstrapJdbcConnectionAccess();
    final Connection conn;
    try {
        conn = connectionAccess.obtainConnection();
        conn.setAutoCommit(false);
        try {
            Statement statement = conn.createStatement();
            dropProcedures(statement);
            try {
                statement.close();
            } catch (SQLException ignore) {
            }
        } finally {
            try {
                conn.commit();
            } catch (SQLException e) {
                System.out.println("Unable to commit transaction afterQuery creating dropping procedures");
            }
            try {
                connectionAccess.releaseConnection(conn);
            } catch (SQLException ignore) {
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException("Unable to drop stored procedures", e);
    }
}
Also used : SQLException(java.sql.SQLException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) Connection(java.sql.Connection) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices)

Example 7 with JdbcConnectionAccess

use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.

the class MasterDetailTest method isSerializableIsolationEnforced.

protected boolean isSerializableIsolationEnforced() throws Exception {
    JdbcConnectionAccess connectionAccess = sessionFactory().getServiceRegistry().getService(JdbcServices.class).getBootstrapJdbcConnectionAccess();
    Connection conn = null;
    try {
        conn = connectionAccess.obtainConnection();
        return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
    } finally {
        if (conn != null) {
            try {
                connectionAccess.releaseConnection(conn);
            } catch (Throwable ignore) {
            // ignore...
            }
        }
    }
}
Also used : JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) Connection(java.sql.Connection) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices)

Example 8 with JdbcConnectionAccess

use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.

the class JpaTckUsageTest method createProcedures.

private void createProcedures(HibernateEntityManagerFactory emf) {
    final SessionFactoryImplementor sf = emf.unwrap(SessionFactoryImplementor.class);
    final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService(JdbcServices.class).getBootstrapJdbcConnectionAccess();
    final Connection conn;
    try {
        conn = connectionAccess.obtainConnection();
        conn.setAutoCommit(false);
        try {
            Statement statement = conn.createStatement();
            // drop them, just to be sure
            try {
                dropProcedures(statement);
            } catch (SQLException ignore) {
            }
            createProcedureFindOneUser(statement);
            createProcedureDeleteAllUsers(statement);
            try {
                statement.close();
            } catch (SQLException ignore) {
            }
        } finally {
            try {
                conn.commit();
            } catch (SQLException e) {
                System.out.println("Unable to commit transaction afterQuery creating creating procedures");
            }
            try {
                connectionAccess.releaseConnection(conn);
            } catch (SQLException ignore) {
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException("Unable to create stored procedures", e);
    }
}
Also used : SQLException(java.sql.SQLException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) Connection(java.sql.Connection) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices)

Example 9 with JdbcConnectionAccess

use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.

the class JpaTckUsageTest method dropProcedures.

private void dropProcedures(HibernateEntityManagerFactory emf) {
    final SessionFactoryImplementor sf = emf.unwrap(SessionFactoryImplementor.class);
    final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService(JdbcServices.class).getBootstrapJdbcConnectionAccess();
    final Connection conn;
    try {
        conn = connectionAccess.obtainConnection();
        conn.setAutoCommit(false);
        try {
            Statement statement = conn.createStatement();
            dropProcedures(statement);
            try {
                statement.close();
            } catch (SQLException ignore) {
            }
        } finally {
            try {
                conn.commit();
            } catch (SQLException e) {
                System.out.println("Unable to commit transaction afterQuery creating dropping procedures");
            }
            try {
                connectionAccess.releaseConnection(conn);
            } catch (SQLException ignore) {
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException("Unable to drop stored procedures", e);
    }
}
Also used : SQLException(java.sql.SQLException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) Connection(java.sql.Connection) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices)

Example 10 with JdbcConnectionAccess

use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.

the class StoreProcedureOutParameterByNameTest method createProcedure.

private void createProcedure(EntityManagerFactory emf, String storedProc) {
    final SessionFactoryImplementor sf = emf.unwrap(SessionFactoryImplementor.class);
    final JdbcConnectionAccess connectionAccess = sf.getServiceRegistry().getService(JdbcServices.class).getBootstrapJdbcConnectionAccess();
    final Connection conn;
    try {
        conn = connectionAccess.obtainConnection();
        conn.setAutoCommit(false);
        try {
            Statement statement = conn.createStatement();
            statement.execute(storedProc);
            try {
                statement.close();
            } catch (SQLException ignore) {
                fail();
            }
        } finally {
            try {
                conn.commit();
            } catch (SQLException e) {
                System.out.println("Unable to commit transaction after creating creating procedures");
                fail();
            }
            try {
                connectionAccess.releaseConnection(conn);
            } catch (SQLException ignore) {
                fail();
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException("Unable to create stored procedures", e);
    }
}
Also used : SQLException(java.sql.SQLException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Statement(java.sql.Statement) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) Connection(java.sql.Connection) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices)

Aggregations

Connection (java.sql.Connection)15 JdbcConnectionAccess (org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess)15 SQLException (java.sql.SQLException)14 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)13 Statement (java.sql.Statement)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)10 PreparedStatement (java.sql.PreparedStatement)4 SqlExceptionHelper (org.hibernate.engine.jdbc.spi.SqlExceptionHelper)3 JdbcSessionContext (org.hibernate.resource.jdbc.spi.JdbcSessionContext)2 JdbcSessionOwner (org.hibernate.resource.jdbc.spi.JdbcSessionOwner)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 Predicate (java.util.function.Predicate)1