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);
}
}
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);
}
}
use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.
the class DateTimeParameterTest 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) {
}
statement.execute("CREATE PROCEDURE findMessagesByDate(IN chkDt DATE) " + "language java " + "dynamic result sets 1 " + "external name 'org.hibernate.jpa.test.procedure.DateTimeParameterTest.findMessagesByDate' " + "parameter style java");
statement.execute("CREATE PROCEDURE findMessagesByTime(IN chkTime TIME) " + "language java " + "dynamic result sets 1 " + "external name 'org.hibernate.jpa.test.procedure.DateTimeParameterTest.findMessagesByTime' " + "parameter style java");
statement.execute("CREATE PROCEDURE findMessagesByTimestampRange(IN startDt TIMESTAMP, IN endDt TIMESTAMP) " + "language java " + "dynamic result sets 1 " + "external name 'org.hibernate.jpa.test.procedure.DateTimeParameterTest.findMessagesByTimestampRange' " + "parameter style java");
statement.execute("CREATE PROCEDURE retrieveTimestamp(IN ts1 TIMESTAMP, OUT ts2 TIMESTAMP) " + "language java " + "dynamic result sets 0 " + "external name 'org.hibernate.jpa.test.procedure.DateTimeParameterTest.retrieveTimestamp' " + "parameter style java");
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);
}
}
use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.
the class HSQLStoreProcedureTest method executeStatement.
public void executeStatement(EntityManagerFactory emf, String toExecute) {
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(toExecute);
try {
statement.close();
} catch (SQLException e) {
fail(e.getMessage());
}
} finally {
try {
conn.commit();
} catch (SQLException e) {
fail(e.getMessage());
}
try {
connectionAccess.releaseConnection(conn);
} catch (SQLException e) {
fail(e.getMessage());
}
}
} catch (SQLException e) {
throw new RuntimeException("Unable to create stored procedures", e);
}
}
use of org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess in project hibernate-orm by hibernate.
the class StoreProcedureOutParameterByPositionTest 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);
}
}
Aggregations