Search in sources :

Example 1 with ResultSetOutput

use of org.hibernate.result.ResultSetOutput 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 ResultSetOutput

use of org.hibernate.result.ResultSetOutput 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) Output(org.hibernate.result.Output) ResultSetOutput(org.hibernate.result.ResultSetOutput) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject) Session(org.hibernate.Session) Test(org.junit.Test)

Example 3 with ResultSetOutput

use of org.hibernate.result.ResultSetOutput 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) Output(org.hibernate.result.Output) ResultSetOutput(org.hibernate.result.ResultSetOutput) Session(org.hibernate.Session) Test(org.junit.Test)

Example 4 with ResultSetOutput

use of org.hibernate.result.ResultSetOutput in project hibernate-orm by hibernate.

the class OracleStoredProcedureTest method testHibernateProcedureCallRefCursor.

@Test
public void testHibernateProcedureCallRefCursor() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        Session session = entityManager.unwrap(Session.class);
        ProcedureCall call = session.createStoredProcedureCall("sp_person_phones");
        call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L);
        call.registerParameter(2, Class.class, ParameterMode.REF_CURSOR);
        Output output = call.getOutputs().getCurrent();
        List<Object[]> postComments = ((ResultSetOutput) output).getResultList();
        assertEquals(2, postComments.size());
    });
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) ProcedureCall(org.hibernate.procedure.ProcedureCall) Output(org.hibernate.result.Output) ResultSetOutput(org.hibernate.result.ResultSetOutput) Session(org.hibernate.Session) Test(org.junit.Test)

Example 5 with ResultSetOutput

use of org.hibernate.result.ResultSetOutput in project hibernate-orm by hibernate.

the class OracleStoredProcedureTest method testHibernateProcedureCallRefCursor.

@Test
public void testHibernateProcedureCallRefCursor() {
    EntityManager entityManager = createEntityManager();
    entityManager.getTransaction().begin();
    try {
        Session session = entityManager.unwrap(Session.class);
        ProcedureCall call = session.createStoredProcedureCall("sp_person_phones");
        call.registerParameter(1, Long.class, ParameterMode.IN).bindValue(1L);
        call.registerParameter(2, Class.class, ParameterMode.REF_CURSOR);
        Output output = call.getOutputs().getCurrent();
        List<Object[]> postComments = ((ResultSetOutput) output).getResultList();
        assertEquals(2, postComments.size());
    } finally {
        entityManager.getTransaction().rollback();
        entityManager.close();
    }
}
Also used : ResultSetOutput(org.hibernate.result.ResultSetOutput) EntityManager(javax.persistence.EntityManager) ProcedureCall(org.hibernate.procedure.ProcedureCall) Output(org.hibernate.result.Output) ResultSetOutput(org.hibernate.result.ResultSetOutput) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)11 ProcedureCall (org.hibernate.procedure.ProcedureCall)11 ResultSetOutput (org.hibernate.result.ResultSetOutput)11 Test (org.junit.Test)11 Output (org.hibernate.result.Output)9 ProcedureOutputs (org.hibernate.procedure.ProcedureOutputs)7 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)4 List (java.util.List)3 EntityManager (javax.persistence.EntityManager)2 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1