Search in sources :

Example 21 with CriteriaQuery

use of javax.persistence.criteria.CriteriaQuery in project hibernate-orm by hibernate.

the class PredicateTest method testExplicitBuilderBooleanHandling.

@Test
public void testExplicitBuilderBooleanHandling() {
    // just checking syntax of the resulting query
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    // note : these may fail on various matrix db jobs depending on how the dialect handles booleans
    {
        CriteriaQuery<CreditCard> criteriaQuery = builder.createQuery(CreditCard.class);
        Root<CreditCard> root = criteriaQuery.from(CreditCard.class);
        criteriaQuery.where(builder.isFalse(root.get(CreditCard_.approved)));
        em.createQuery(criteriaQuery).getResultList();
    }
    {
        CriteriaQuery<Order> criteriaQuery = builder.createQuery(Order.class);
        Root<Order> root = criteriaQuery.from(Order.class);
        criteriaQuery.where(builder.isFalse(root.get(Order_.creditCard).get(CreditCard_.approved)));
        em.createQuery(criteriaQuery).getResultList();
    }
    em.getTransaction().commit();
    em.close();
}
Also used : Order(org.hibernate.jpa.test.metamodel.Order) EntityManager(javax.persistence.EntityManager) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CreditCard(org.hibernate.jpa.test.metamodel.CreditCard) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 22 with CriteriaQuery

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

the class TblMleJpaController method findTblMleEntities.

private List<TblMle> findTblMleEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblMle.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) TblMle(com.intel.mtwilson.as.data.TblMle) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 23 with CriteriaQuery

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

the class TblModuleManifestJpaController method findTblModuleManifestEntities.

private List<TblModuleManifest> findTblModuleManifestEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblModuleManifest.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) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest)

Example 24 with CriteriaQuery

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

the class MwMleSourceJpaController method findMwMleSourceEntities.

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

Example 25 with CriteriaQuery

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

the class TblEventTypeJpaController method getTblEventTypeCount.

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

Aggregations

CriteriaQuery (javax.persistence.criteria.CriteriaQuery)47 EntityManager (javax.persistence.EntityManager)41 Query (javax.persistence.Query)36 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)9 Test (org.junit.Test)9 List (java.util.List)3 TypedQuery (javax.persistence.TypedQuery)3 Root (javax.persistence.criteria.Root)3 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)3 MwAssetTagCertificate (com.intel.mtwilson.as.data.MwAssetTagCertificate)2 MwCertificateX509 (com.intel.mtwilson.as.data.MwCertificateX509)2 MwKeystore (com.intel.mtwilson.as.data.MwKeystore)2 MwMleSource (com.intel.mtwilson.as.data.MwMleSource)2 TblEventType (com.intel.mtwilson.as.data.TblEventType)2 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)2 TblHosts (com.intel.mtwilson.as.data.TblHosts)2 TblLocationPcr (com.intel.mtwilson.as.data.TblLocationPcr)2 TblMle (com.intel.mtwilson.as.data.TblMle)2 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)2 TblModuleManifestLog (com.intel.mtwilson.as.data.TblModuleManifestLog)2