Search in sources :

Example 91 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project OpenAttestation by OpenAttestation.

the class TblRequestQueueJpaController method findTblRequestQueueEntities.

private List<TblRequestQueue> findTblRequestQueueEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblRequestQueue.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : TblRequestQueue(com.intel.mtwilson.as.data.TblRequestQueue) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 92 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project OpenAttestation by OpenAttestation.

the class TblRequestQueueJpaController method getTblRequestQueueCount.

public int getTblRequestQueueCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblRequestQueue> rt = cq.from(TblRequestQueue.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
Also used : TblRequestQueue(com.intel.mtwilson.as.data.TblRequestQueue) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 93 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project OpenAttestation by OpenAttestation.

the class TblSamlAssertionJpaController method findTblSamlAssertionEntities.

private List<TblSamlAssertion> findTblSamlAssertionEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblSamlAssertion.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion)

Example 94 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project robo4j by Robo4J.

the class DefaultRepository method findAllByClass.

@SuppressWarnings("unchecked")
@Override
public <T> List<T> findAllByClass(Class<T> clazz) {
    EntityManager em = dataSourceContext.getEntityManager(clazz);
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery(clazz);
    Root<T> rs = cq.from(clazz);
    CriteriaQuery<T> cq2 = cq.select(rs);
    TypedQuery<T> tq = em.createQuery(cq2);
    return tq.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 95 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project aries by apache.

the class AbstractSimpleTransactionTest method testSuspendedTx.

@Test
public void testSuspendedTx() {
    Message message = new Message();
    message.message = "Hello World!";
    txControl.required(() -> {
        em.persist(message);
        assertEquals(Long.valueOf(0), txControl.notSupported(() -> {
            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
            countQuery.select(cb.count(countQuery.from(Message.class)));
            return em.createQuery(countQuery).getSingleResult();
        }));
        return null;
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Message(org.apache.aries.tx.control.itests.entity.Message) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Test(org.junit.Test)

Aggregations

CriteriaQuery (javax.persistence.criteria.CriteriaQuery)155 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)112 EntityManager (javax.persistence.EntityManager)109 Query (javax.persistence.Query)109 TypedQuery (javax.persistence.TypedQuery)69 Predicate (javax.persistence.criteria.Predicate)51 EntityTransaction (javax.persistence.EntityTransaction)45 Root (javax.persistence.criteria.Root)40 List (java.util.List)22 Path (javax.persistence.criteria.Path)18 Test (org.testng.annotations.Test)16 UserTransaction (javax.transaction.UserTransaction)15 Person (org.datanucleus.samples.annotations.models.company.Person)15 Manager (org.datanucleus.samples.jpa.query.Manager)14 Specification (org.springframework.data.jpa.domain.Specification)14 Item (org.jpwh.model.querying.Item)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 Join (javax.persistence.criteria.Join)10 Session (org.hibernate.Session)9