use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.
the class StoredProcedureApiTests method testInvalidParameterReference.
@Test
public void testInvalidParameterReference() {
inTransaction(session -> {
final ProcedureCall call1 = session.createStoredProcedureCall("test");
call1.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN);
final Parameter<Integer> p1_1 = (Parameter<Integer>) call1.getParameter(1);
call1.setParameter(1, 1);
final ProcedureCall call2 = session.createStoredProcedureCall("test");
call2.registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN);
call2.setParameter(1, 1);
try {
call2.getParameterValue(p1_1);
fail("Expecting failure");
} catch (IllegalArgumentException expected) {
}
});
}
use of org.hibernate.procedure.ProcedureCall 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.ProcedureCall 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.ProcedureCall 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.ProcedureCall in project hibernate-orm by hibernate.
the class StoredProcedureTest method testInParametersNotSetPass.
@Test
public void testInParametersNotSetPass() {
Session session = openSession();
session.beginTransaction();
// unlike #testInParametersNotSet here we are asking that the NULL be passed
// so these executions should succeed
ProcedureCall query = session.createStoredProcedureCall("findUserRange");
query.registerParameter(1, Integer.class, ParameterMode.IN).enablePassingNulls(true);
query.registerParameter(2, Integer.class, ParameterMode.IN).bindValue(2);
query.getOutputs();
// H2 does not support named parameters
// {
// ProcedureCall query = session.createStoredProcedureCall( "findUserRange" );
// query.registerParameter( "start", Integer.class, ParameterMode.IN );
// query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 );
// try {
// query.getOutputs();
// fail( "Expecting failure due to missing parameter bind" );
// }
// catch (JDBCException expected) {
// }
// }
session.getTransaction().commit();
session.close();
}
Aggregations