Search in sources :

Example 1 with ProcedureCall

use of org.hibernate.procedure.ProcedureCall 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 ProcedureCall

use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.

the class MySQLStoredProcedureTest method testHibernateProcedureCallOutParameter.

@Test
public void testHibernateProcedureCallOutParameter() {
    EntityManager entityManager = createEntityManager();
    entityManager.getTransaction().begin();
    try {
        Session session = entityManager.unwrap(Session.class);
        ProcedureCall call = session.createStoredProcedureCall("sp_count_phones");
        call.registerParameter("personId", Long.class, ParameterMode.IN).bindValue(1L);
        call.registerParameter("phoneCount", Long.class, ParameterMode.OUT);
        Long phoneCount = (Long) call.getOutputs().getOutputParameterValue("phoneCount");
        assertEquals(Long.valueOf(2), phoneCount);
    } finally {
        entityManager.getTransaction().rollback();
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ProcedureCall(org.hibernate.procedure.ProcedureCall) Session(org.hibernate.Session) Test(org.junit.Test)

Example 3 with ProcedureCall

use of org.hibernate.procedure.ProcedureCall 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)

Example 4 with ProcedureCall

use of org.hibernate.procedure.ProcedureCall in project hibernate-orm by hibernate.

the class AbstractSharedSessionContract method getNamedProcedureCall.

@Override
@SuppressWarnings("UnnecessaryLocalVariable")
public ProcedureCall getNamedProcedureCall(String name) {
    checkOpen();
    final ProcedureCallMemento memento = factory.getNamedQueryRepository().getNamedProcedureCallMemento(name);
    if (memento == null) {
        throw new IllegalArgumentException("Could not find named stored procedure call with that registration name : " + name);
    }
    final ProcedureCall procedureCall = memento.makeProcedureCall(this);
    // procedureCall.setComment( "Named stored procedure call [" + name + "]" );
    return procedureCall;
}
Also used : ProcedureCallMemento(org.hibernate.procedure.ProcedureCallMemento) ProcedureCall(org.hibernate.procedure.ProcedureCall)

Example 5 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, String... resultSetMappings) {
    checkOpen();
    final ProcedureCall procedureCall = new ProcedureCallImpl(this, procedureName, resultSetMappings);
    // call.setComment( "Dynamic stored procedure call" );
    return procedureCall;
}
Also used : ProcedureCall(org.hibernate.procedure.ProcedureCall) ProcedureCallImpl(org.hibernate.procedure.internal.ProcedureCallImpl)

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