use of javax.persistence.criteria.CriteriaQuery in project jbpm by kiegroup.
the class AuditQueryCriteriaUtil method createQueryAndCallApplyMetaCriteriaAndGetResult.
@Override
protected <T> List<T> createQueryAndCallApplyMetaCriteriaAndGetResult(QueryWhere queryWhere, CriteriaQuery<T> criteriaQuery, CriteriaBuilder builder) {
EntityManager em = getEntityManager();
Object newTx = joinTransaction(em);
Query query = em.createQuery(criteriaQuery);
applyMetaCriteriaToQuery(query, queryWhere);
// execute query
List<T> result = query.getResultList();
closeEntityManager(em, newTx);
return result;
}
use of javax.persistence.criteria.CriteriaQuery in project jbpm by kiegroup.
the class AbstractTaskQueryCriteriaUtil method createQueryAndCallApplyMetaCriteriaAndGetResult.
@Override
protected <T> List<T> createQueryAndCallApplyMetaCriteriaAndGetResult(QueryWhere queryWhere, CriteriaQuery<T> criteriaQuery, CriteriaBuilder builder) {
EntityManager em = getEntityManager();
Object newTx = joinTransaction(em);
Query query = em.createQuery(criteriaQuery);
applyMetaCriteriaToQuery(query, queryWhere);
// execute query
List<T> result = query.getResultList();
// depending on the context, this is done
// 1. here
// 1. *outside* of this class (this method is a no-op)
closeEntityManager(em, newTx);
return result;
}
use of javax.persistence.criteria.CriteriaQuery in project dhis2-core by dhis2.
the class HibernateGenericStore method getAllByAttributes.
@Override
public List<T> getAllByAttributes(List<Attribute> attributes) {
CriteriaBuilder builder = getCriteriaBuilder();
CriteriaQuery<T> query = builder.createQuery(getClazz());
Root<T> root = query.from(getClazz());
query.select(root).distinct(true);
List<Predicate> predicates = attributes.stream().map(attribute -> builder.isNotNull(builder.function(FUNCTION_JSONB_EXTRACT_PATH, String.class, root.get("attributeValues"), builder.literal(attribute.getUid())))).collect(Collectors.toList());
query.where(builder.or(predicates.toArray(new Predicate[predicates.size()])));
return getSession().createQuery(query).list();
}
use of javax.persistence.criteria.CriteriaQuery in project dhis2-core by dhis2.
the class HibernateGenericStore method countAllValuesByAttributes.
@Override
public long countAllValuesByAttributes(List<Attribute> attributes) {
CriteriaBuilder builder = getCriteriaBuilder();
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<T> root = query.from(getClazz());
query.select(builder.countDistinct(root));
List<Predicate> predicates = attributes.stream().map(attribute -> builder.isNotNull(builder.function(FUNCTION_JSONB_EXTRACT_PATH, String.class, root.get("attributeValues"), builder.literal(attribute.getUid())))).collect(Collectors.toList());
query.where(builder.or(predicates.toArray(new Predicate[predicates.size()])));
return getSession().createQuery(query).getSingleResult();
}
use of javax.persistence.criteria.CriteriaQuery in project mycore by MyCoRe-Org.
the class MCRIFSCommands method checkDerivatesWithProjectIDInMCRFSNODES.
@MCRCommand(syntax = "check mcrfsnodes of derivates with project id {0}", help = "check the entries of MCRFSNODES with project ID {0} that the derivate exists")
public static void checkDerivatesWithProjectIDInMCRFSNODES(String project_id) {
LOGGER.info("Start check of MCRFSNODES for derivates with project ID {}", project_id);
if (project_id == null || project_id.length() == 0) {
LOGGER.error("Project ID missed for check MCRFSNODES entries of derivates with project ID {0}");
return;
}
MCRXMLMetadataManager mgr = MCRXMLMetadataManager.instance();
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> query = cb.createQuery(String.class);
Root<MCRFSNODES> nodes = query.from(MCRFSNODES.class);
AtomicInteger counter = new AtomicInteger();
em.createQuery(query.distinct(true).select(nodes.get(MCRFSNODES_.owner)).where(cb.like(nodes.get(MCRFSNODES_.owner), project_id + "\\_%"))).getResultList().stream().peek(ignore -> counter.incrementAndGet()).map(MCRObjectID::getInstance).filter(derID -> {
try {
return !mgr.exists(derID);
} catch (IOException e) {
LOGGER.error("Error while checking existence of {}", derID, e);
return true;
}
}).forEach(missingDerivate -> LOGGER.error(" !!!! Can't find MCRFSNODES entry {} as existing derivate", missingDerivate));
LOGGER.info("Check done for {} entries", counter.get());
}
Aggregations