Search in sources :

Example 21 with ProcedureCall

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;
}
Also used : ProcedureCall(org.hibernate.procedure.ProcedureCall) ProcedureCallImpl(org.hibernate.procedure.internal.ProcedureCallImpl)

Example 22 with 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);
    });
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) ProcedureCall(org.hibernate.procedure.ProcedureCall) ProcedureOutputs(org.hibernate.procedure.ProcedureOutputs) ResultSetOutput(org.hibernate.result.ResultSetOutput) Output(org.hibernate.result.Output) Test(org.junit.Test)

Example 23 with ProcedureCall

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);
    });
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) ProcedureCall(org.hibernate.procedure.ProcedureCall) ProcedureOutputs(org.hibernate.procedure.ProcedureOutputs) ResultSetOutput(org.hibernate.result.ResultSetOutput) Output(org.hibernate.result.Output) Test(org.junit.Test)

Example 24 with ProcedureCall

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);
    });
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) ProcedureCall(org.hibernate.procedure.ProcedureCall) ProcedureOutputs(org.hibernate.procedure.ProcedureOutputs) ResultSetOutput(org.hibernate.result.ResultSetOutput) Output(org.hibernate.result.Output) Test(org.junit.Test)

Example 25 with ProcedureCall

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();
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) ProcedureCall(org.hibernate.procedure.ProcedureCall) ProcedureOutputs(org.hibernate.procedure.ProcedureOutputs) ResultSetOutput(org.hibernate.result.ResultSetOutput) Output(org.hibernate.result.Output) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

ProcedureCall (org.hibernate.procedure.ProcedureCall)28 Test (org.junit.Test)24 Session (org.hibernate.Session)18 ResultSetOutput (org.hibernate.result.ResultSetOutput)16 Output (org.hibernate.result.Output)14 ProcedureOutputs (org.hibernate.procedure.ProcedureOutputs)11 EntityManager (javax.persistence.EntityManager)4 List (java.util.List)3 StoredProcedureResultSetMappingTest (org.hibernate.test.sql.storedproc.StoredProcedureResultSetMappingTest)3 JDBCException (org.hibernate.JDBCException)2 ProcedureCallImpl (org.hibernate.procedure.internal.ProcedureCallImpl)2 DaoException (gov.ca.cwds.data.DaoException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Parameter (javax.persistence.Parameter)1 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1 ProcedureCallMemento (org.hibernate.procedure.ProcedureCallMemento)1 QueryParameter (org.hibernate.query.QueryParameter)1 TestForIssue (org.hibernate.testing.TestForIssue)1