use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method createStoredProcedureCall.
@Override
@SuppressWarnings("UnnecessaryLocalVariable")
public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
checkOpen();
final ProcedureCall procedureCall = new ProcedureCallImpl(this, procedureName, resultClasses);
// call.setComment( "Dynamic stored procedure call" );
return procedureCall;
}
use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class ResultMappingTest method testResultClass.
@Test
public void testResultClass() {
inTransaction(session -> {
final ProcedureCall call = session.createStoredProcedureCall("findOneUser", H2ProcTesting.MyEntity.class);
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.ProcedureCall in project hibernate-orm by hibernate.
the class ResultMappingTest method testMappingNoFields.
@Test
public void testMappingNoFields() {
inTransaction(session -> {
final ProcedureCall call = session.createStoredProcedureCall("findOneUser", "no-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.ProcedureCall in project hibernate-orm by hibernate.
the class ResultMappingTest method testMappingAllFields.
@Test
public void testMappingAllFields() {
inTransaction(session -> {
final ProcedureCall call = session.createStoredProcedureCall("findOneUser", "all-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.ProcedureCall in project hibernate-orm by hibernate.
the class StoredProcedureTest method testInParametersByPosition.
@Test
public void testInParametersByPosition() {
Session session = openSession();
session.beginTransaction();
ProcedureCall query = session.createStoredProcedureCall("findUserRange");
query.registerParameter(1, Integer.class, ParameterMode.IN).bindValue(1);
query.registerParameter(2, Integer.class, ParameterMode.IN).bindValue(2);
ProcedureOutputs procedureResult = query.getOutputs();
Output currentOutput = procedureResult.getCurrent();
assertNotNull(currentOutput);
ResultSetOutput resultSetReturn = assertTyping(ResultSetOutput.class, currentOutput);
List results = resultSetReturn.getResultList();
assertEquals(1, results.size());
Object result = results.get(0);
assertTyping(Object[].class, result);
Integer id = (Integer) ((Object[]) result)[0];
String name = (String) ((Object[]) result)[1];
assertEquals(1, (int) id);
assertEquals("User 1", name);
session.getTransaction().commit();
session.close();
}
Aggregations