Search in sources :

Example 11 with CriteriaQuery

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

the class TblSamlAssertionJpaController method getTblSamlAssertionCount.

public int getTblSamlAssertionCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblSamlAssertion> rt = cq.from(TblSamlAssertion.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) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion)

Example 12 with CriteriaQuery

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

the class TblEventTypeJpaController method findTblEventTypeEntities.

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

Example 13 with CriteriaQuery

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

the class MwAssetTagCertificateJpaController method findMwAssetTagCertificateEntities.

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

Example 14 with CriteriaQuery

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

the class MwAssetTagCertificateJpaController method getMwAssetTagCertificateCount.

public int getMwAssetTagCertificateCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<MwAssetTagCertificate> rt = cq.from(MwAssetTagCertificate.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) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate)

Example 15 with CriteriaQuery

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

the class ExpressionsTest method testParameterReuse.

@Test
public void testParameterReuse() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaQuery<Product> criteria = em.getCriteriaBuilder().createQuery(Product.class);
    Root<Product> from = criteria.from(Product.class);
    ParameterExpression<String> param = em.getCriteriaBuilder().parameter(String.class);
    Predicate predicate = em.getCriteriaBuilder().equal(from.get(Product_.id), param);
    Predicate predicate2 = em.getCriteriaBuilder().equal(from.get(Product_.name), param);
    criteria.where(em.getCriteriaBuilder().or(predicate, predicate2));
    assertEquals(1, criteria.getParameters().size());
    TypedQuery<Product> query = em.createQuery(criteria);
    int hqlParamCount = countGeneratedParameters(query.unwrap(Query.class));
    assertEquals(1, hqlParamCount);
    query.setParameter(param, "abc").getResultList();
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(org.hibernate.Query) Product(org.hibernate.jpa.test.metamodel.Product) Predicate(javax.persistence.criteria.Predicate) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

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