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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
Aggregations