Search in sources :

Example 21 with StoredProcedureQuery

use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.

the class PostgreSQLStoredProcedureTest method testStoredProcedureRefCursor.

@Test
public void testStoredProcedureRefCursor() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        StoredProcedureQuery query = entityManager.createStoredProcedureQuery("fn_phones");
        query.registerStoredProcedureParameter(1, void.class, ParameterMode.REF_CURSOR);
        query.registerStoredProcedureParameter(2, Long.class, ParameterMode.IN);
        query.setParameter(2, 1L);
        List<Object[]> phones = query.getResultList();
        assertEquals(2, phones.size());
    });
}
Also used : StoredProcedureQuery(javax.persistence.StoredProcedureQuery) Test(org.junit.Test)

Example 22 with StoredProcedureQuery

use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.

the class HANAStoredProcedureTest method testStoredProcedureRefCursor.

@Test
@TestForIssue(jiraKey = "HHH-12138")
public void testStoredProcedureRefCursor() {
    EntityManager entityManager = createEntityManager();
    entityManager.getTransaction().begin();
    try {
        StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_person_phones");
        query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
        query.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR);
        query.setParameter(1, 1L);
        query.execute();
        List<Object[]> postComments = query.getResultList();
        assertNotNull(postComments);
    } finally {
        entityManager.getTransaction().rollback();
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 23 with StoredProcedureQuery

use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.

the class HANAStoredProcedureTest method testStoredProcedureOutParameter.

@Test
@TestForIssue(jiraKey = "HHH-12138")
public void testStoredProcedureOutParameter() {
    EntityManager entityManager = createEntityManager();
    entityManager.getTransaction().begin();
    try {
        StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_count_phones");
        query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
        query.registerStoredProcedureParameter(2, Long.class, ParameterMode.OUT);
        query.setParameter(1, 1L);
        query.execute();
        Long phoneCount = (Long) query.getOutputParameterValue(2);
        assertEquals(Long.valueOf(2), phoneCount);
    } finally {
        entityManager.getTransaction().rollback();
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 24 with StoredProcedureQuery

use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.

the class HANAStoredProcedureTest method testSysRefCursorAsOutParameter.

@Test
@TestForIssue(jiraKey = "HHH-12138")
public void testSysRefCursorAsOutParameter() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        StoredProcedureQuery function = entityManager.createNamedStoredProcedureQuery("singleRefCursor");
        function.execute();
        Integer value = (Integer) function.getSingleResult();
        assertFalse(function.hasMoreResults());
        assertEquals(Integer.valueOf(1), value);
    });
}
Also used : StoredProcedureQuery(javax.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 25 with StoredProcedureQuery

use of javax.persistence.StoredProcedureQuery in project hibernate-orm by hibernate.

the class OracleStoredProcedureTest method testStoredProcedureOutParameter.

@Test
public void testStoredProcedureOutParameter() {
    EntityManager entityManager = createEntityManager();
    entityManager.getTransaction().begin();
    try {
        StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_count_phones");
        query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
        query.registerStoredProcedureParameter(2, Long.class, ParameterMode.OUT);
        query.setParameter(1, 1L);
        query.execute();
        Long phoneCount = (Long) query.getOutputParameterValue(2);
        assertEquals(Long.valueOf(2), phoneCount);
    } finally {
        entityManager.getTransaction().rollback();
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery) Test(org.junit.Test)

Aggregations

StoredProcedureQuery (javax.persistence.StoredProcedureQuery)60 Test (org.junit.Test)47 EntityManager (javax.persistence.EntityManager)38 NamedStoredProcedureQuery (javax.persistence.NamedStoredProcedureQuery)19 SQLException (java.sql.SQLException)12 List (java.util.List)11 TestForIssue (org.hibernate.testing.TestForIssue)11 Connection (java.sql.Connection)6 Statement (java.sql.Statement)6 EntityTransaction (javax.persistence.EntityTransaction)6 JPAEntityManager (org.datanucleus.api.jpa.JPAEntityManager)6 Person (org.datanucleus.samples.annotations.models.company.Person)6 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)6 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)6 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)6 Parameter (javax.persistence.Parameter)5 Query (javax.persistence.Query)5 UserTransaction (javax.transaction.UserTransaction)5 QueryingTest (org.jpwh.test.querying.QueryingTest)5 Test (org.testng.annotations.Test)5