Search in sources :

Example 11 with ProcedureCall

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) {
        }
    });
}
Also used : ProcedureCall(org.hibernate.procedure.ProcedureCall) QueryParameter(org.hibernate.query.QueryParameter) Parameter(javax.persistence.Parameter) Test(org.junit.Test) StoredProcedureResultSetMappingTest(org.hibernate.test.sql.storedproc.StoredProcedureResultSetMappingTest)

Example 12 with ProcedureCall

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);
    });
}
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 13 with ProcedureCall

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();
}
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) Session(org.hibernate.Session) Test(org.junit.Test)

Example 14 with ProcedureCall

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();
}
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) Session(org.hibernate.Session) Test(org.junit.Test)

Example 15 with ProcedureCall

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