Search in sources :

Example 1 with ProcedureOutputs

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

Example 2 with ProcedureOutputs

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);
    });
}
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 3 with ProcedureOutputs

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();
}
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 4 with ProcedureOutputs

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();
}
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 5 with ProcedureOutputs

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

Aggregations

ProcedureCall (org.hibernate.procedure.ProcedureCall)11 ProcedureOutputs (org.hibernate.procedure.ProcedureOutputs)11 ResultSetOutput (org.hibernate.result.ResultSetOutput)11 Test (org.junit.Test)11 Output (org.hibernate.result.Output)9 Session (org.hibernate.Session)7 List (java.util.List)3 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1