use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateEventVisualizationStore method getEventVisualizationsLikeName.
private List<EventVisualization> getEventVisualizationsLikeName(final Set<String> words, final int first, final int max, final EventVisualizationSet eventVisualizationSet) {
final CriteriaBuilder builder = getCriteriaBuilder();
final JpaQueryParameters<EventVisualization> params = new JpaQueryParameters<EventVisualization>().addPredicates(getSharingPredicates(builder)).addOrder(root -> builder.asc(root.get("name"))).setFirstResult(first).setMaxResults(max);
if (words.isEmpty()) {
return getList(builder, params);
}
final List<Function<Root<EventVisualization>, Predicate>> conjunction = new ArrayList<>(1);
for (final String word : words) {
conjunction.add(root -> builder.like(builder.lower(root.get("name")), "%" + word.toLowerCase() + "%"));
}
params.addPredicate(root -> builder.and(conjunction.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[0])));
setCorrectPredicates(eventVisualizationSet, builder, params);
return getList(builder, params);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateEventVisualizationStore method getEventVisualizations.
private List<EventVisualization> getEventVisualizations(final int first, final int max, final EventVisualizationSet eventVisualizationSet) {
final CriteriaBuilder builder = getCriteriaBuilder();
final JpaQueryParameters<EventVisualization> params = new JpaQueryParameters<EventVisualization>().addPredicates(getSharingPredicates(builder)).addOrder(root -> builder.asc(root.get("name"))).setFirstResult(first).setMaxResults(max);
setCorrectPredicates(eventVisualizationSet, builder, params);
return getList(builder, params);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getAllGeCreated.
@Override
public List<T> getAllGeCreated(Date created) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.greaterThanOrEqualTo(root.get("created"), created)).addOrder(root -> builder.desc(root.get("created")));
return getList(builder, param);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getCount.
@Override
public int getCount() {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).count(root -> builder.countDistinct(root.get("id")));
return getCount(builder, param).intValue();
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getByName.
@Override
public List<T> getByName(Collection<String> names) {
if (names == null || names.isEmpty()) {
return new ArrayList<>();
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> jpaQueryParameters = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> root.get("name").in(names));
return getList(builder, jpaQueryParameters);
}
Aggregations