use of org.hibernate.procedure.ProcedureOutputs in project hibernate-orm by hibernate.
the class PostgresRefCursorSupportTest method testExplicitClassReturn.
@Test
public void testExplicitClassReturn() {
Session session = sf.openSession();
session.beginTransaction();
ProcedureCall call = session.createStoredProcedureCall("all_items", Item.class);
call.registerParameter(1, void.class, ParameterMode.REF_CURSOR);
ProcedureOutputs outputs = call.getOutputs();
ResultSetOutput results = assertTyping(ResultSetOutput.class, outputs.getCurrent());
session.getTransaction().commit();
session.close();
}
use of org.hibernate.procedure.ProcedureOutputs in project hibernate-orm by hibernate.
the class ResultMappingTest method testMappingSomeFields.
@Test
public void testMappingSomeFields() {
inTransaction(session -> {
final ProcedureCall call = session.createStoredProcedureCall("findOneUser", "some-fields");
final ProcedureOutputs procedureResult = call.getOutputs();
final Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
final ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
final Object result = resultSetReturn.getSingleResult();
assertTyping(H2ProcTesting.MyEntity.class, result);
assertEquals("Steve", ((H2ProcTesting.MyEntity) result).name);
});
}
use of org.hibernate.procedure.ProcedureOutputs in project hibernate-orm by hibernate.
the class StoredProcedureTest method baseTest.
@Test
public void baseTest() {
Session session = openSession();
session.beginTransaction();
ProcedureCall procedureCall = session.createStoredProcedureCall("user");
ProcedureOutputs procedureOutputs = procedureCall.getOutputs();
Output currentOutput = procedureOutputs.getCurrent();
assertNotNull(currentOutput);
ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
String name = (String) resultSetReturn.getSingleResult();
assertEquals("SA", name);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.procedure.ProcedureOutputs in project hibernate-orm by hibernate.
the class StoredProcedureTest method testGetSingleResultTuple.
@Test
public void testGetSingleResultTuple() {
Session session = openSession();
session.beginTransaction();
ProcedureCall query = session.createStoredProcedureCall("findOneUser");
ProcedureOutputs procedureResult = query.getOutputs();
Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
Object result = resultSetReturn.getSingleResult();
assertTyping(Object[].class, result);
String name = (String) ((Object[]) result)[1];
assertEquals("Steve", name);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.procedure.ProcedureOutputs in project hibernate-orm by hibernate.
the class StoredProcedureResultSetMappingTest method testPartialResults.
@Test
public void testPartialResults() {
Configuration cfg = new Configuration().addAnnotatedClass(Employee.class).setProperty(AvailableSettings.HBM2DDL_AUTO, "create-drop");
cfg.addAuxiliaryDatabaseObject(new ProcedureDefinition());
SessionFactory sf = cfg.buildSessionFactory();
try {
Session session = sf.openSession();
session.beginTransaction();
ProcedureCall call = session.createStoredProcedureCall("allEmployeeNames", "id-fname-lname");
ProcedureOutputs outputs = call.getOutputs();
ResultSetOutput output = assertTyping(ResultSetOutput.class, outputs.getCurrent());
assertEquals(3, output.getResultList().size());
assertTyping(Employee.class, output.getResultList().get(0));
session.getTransaction().commit();
session.close();
} finally {
sf.close();
}
}
Aggregations