Search in sources :

Example 36 with StoredProcedureQuery

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

the class JpaTckUsageTest method testResultClassHandling.

@Test
public void testResultClassHandling() {
    EntityManager em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    try {
        StoredProcedureQuery query = em.createStoredProcedureQuery("findOneUser", User.class);
        boolean isResult = query.execute();
        assertTrue(isResult);
        int updateCount = query.getUpdateCount();
        boolean results = false;
        do {
            List list = query.getResultList();
            assertEquals(1, list.size());
            assertTyping(User.class, list.get(0));
            results = query.hasMoreResults();
        // and it only sets the updateCount once lol
        } while (results || updateCount != -1);
    } finally {
        em.getTransaction().commit();
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) List(java.util.List) Test(org.junit.Test)

Example 37 with StoredProcedureQuery

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

the class JpaTckUsageTest method testHasMoreResultsHandlingTckChallenge.

@Test
@FailureExpected(jiraKey = "HHH-8416", message = "JPA TCK challenge")
public void testHasMoreResultsHandlingTckChallenge() {
    EntityManager em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    try {
        StoredProcedureQuery query = em.createStoredProcedureQuery("findOneUser", User.class);
        assertTrue(query.execute());
        assertTrue(query.hasMoreResults());
        query.getResultList();
        assertFalse(query.hasMoreResults());
    } finally {
        em.getTransaction().commit();
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 38 with StoredProcedureQuery

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

the class JpaTckUsageTest method testHasMoreResultsHandling.

@Test
public void testHasMoreResultsHandling() {
    EntityManager em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    try {
        StoredProcedureQuery query = em.createStoredProcedureQuery("findOneUser", User.class);
        assertTrue(query.execute());
        query.getResultList();
        assertFalse(query.hasMoreResults());
    } finally {
        em.getTransaction().commit();
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) Test(org.junit.Test)

Example 39 with StoredProcedureQuery

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

the class JpaTckUsageTest method testSettingInParamDefinedOnNamedStoredProcedureQuery.

@Test
public void testSettingInParamDefinedOnNamedStoredProcedureQuery() {
    EntityManager em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    try {
        StoredProcedureQuery query = em.createNamedStoredProcedureQuery("positional-param");
        query.setParameter(1, 1);
    } finally {
        em.getTransaction().commit();
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) Test(org.junit.Test)

Example 40 with StoredProcedureQuery

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

the class StoreProcedureOutParameterByNameTest method testOneBasicOutParameter.

@Test
public void testOneBasicOutParameter() {
    EntityManager em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    User user = new User();
    user.id = 1;
    user.name = "aName";
    em.persist(user);
    em.getTransaction().commit();
    em.clear();
    try {
        StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.findNameById");
        query.setParameter("ID_PARAM", 1);
        assertEquals("aName", query.getOutputParameterValue("NAME_PARAM"));
    } finally {
        em.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