Search in sources :

Example 41 with StoredProcedureQuery

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

the class DateTimeParameterTest method testBindingCalendarAsTime.

@Test
public void testBindingCalendarAsTime() {
    EntityManager em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    try {
        StoredProcedureQuery query = em.createStoredProcedureQuery("findMessagesByTime");
        query.registerStoredProcedureParameter(1, Calendar.class, ParameterMode.IN);
        query.setParameter(1, nowCal, TemporalType.TIME);
        List list = query.getResultList();
        assertEquals(1, list.size());
    } finally {
        em.getTransaction().rollback();
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) List(java.util.List) Test(org.junit.Test)

Example 42 with StoredProcedureQuery

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

the class H2StoreProcedureTest method testStoreProcedureGetParameters.

@Test
public void testStoreProcedureGetParameters() {
    final EntityManager entityManager = getOrCreateEntityManager();
    try {
        StoredProcedureQuery query = entityManager.createStoredProcedureQuery("get_all_entities", MyEntity.class);
        final Set<Parameter<?>> parameters = query.getParameters();
        assertThat(parameters.size(), is(0));
        final List resultList = query.getResultList();
        assertThat(resultList.size(), is(1));
    } finally {
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) Parameter(javax.persistence.Parameter) List(java.util.List) Test(org.junit.Test)

Example 43 with StoredProcedureQuery

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

the class StoreProcedureRefCursorOutParameterByPositionTest method testNamedStoredProcedureExecution.

@Test
public void testNamedStoredProcedureExecution() {
    EntityManager em = entityManagerFactory.createEntityManager();
    try {
        StoredProcedureQuery query = em.createNamedStoredProcedureQuery("User.findByName");
        query.setParameter(1, "my_name");
        query.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery) Test(org.junit.Test)

Example 44 with StoredProcedureQuery

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

the class StoredProcedureResultSetMappingTest method testPartialResults.

@Test
public void testPartialResults() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    StoredProcedureQuery query = em.createStoredProcedureQuery("allEmployeeNames", "id-fname-lname");
    List results = query.getResultList();
    assertEquals(3, results.size());
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) StoredProcedureQuery(javax.persistence.StoredProcedureQuery) List(java.util.List) Test(org.junit.Test)

Example 45 with StoredProcedureQuery

use of javax.persistence.StoredProcedureQuery in project kylo by Teradata.

the class NifiFeedProcessorStatisticsRepositoryImpl method compactFeedProcessorStats.

@Override
public String compactFeedProcessorStats() {
    StoredProcedureQuery query = em.createStoredProcedureQuery("compact_feed_processor_stats");
    query.registerStoredProcedureParameter("res", String.class, ParameterMode.OUT);
    query.execute();
    String result = (String) query.getOutputParameterValue("res");
    return result;
}
Also used : StoredProcedureQuery(javax.persistence.StoredProcedureQuery)

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