use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getAllLikeName.
@Override
public List<T> getAllLikeName(Set<String> nameWords, int first, int max) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addOrder(root -> builder.asc(root.get("name"))).setFirstResult(first).setMaxResults(max);
if (nameWords.isEmpty()) {
return getList(builder, param);
}
List<Function<Root<T>, Predicate>> conjunction = new ArrayList<>();
for (String word : nameWords) {
conjunction.add(root -> builder.like(builder.lower(root.get("name")), "%" + word.toLowerCase() + "%"));
}
param.addPredicate(root -> builder.and(conjunction.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[0])));
return getList(builder, param);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getAllEqName.
@Override
public List<T> getAllEqName(String name) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.equal(root.get("name"), name)).addOrder(root -> builder.asc(root.get("name")));
return getList(builder, param);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getById.
@Override
public List<T> getById(Collection<Long> ids) {
if (ids == null || ids.isEmpty()) {
return new ArrayList<>();
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> jpaQueryParameters = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> root.get("id").in(ids));
return getList(builder, jpaQueryParameters);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getByCode.
@Override
public List<T> getByCode(Collection<String> codes, User user) {
if (codes == null || codes.isEmpty()) {
return new ArrayList<>();
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> jpaQueryParameters = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder, user)).addPredicate(root -> root.get("code").in(codes));
return getList(builder, jpaQueryParameters);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getByCode.
@Override
public final T getByCode(String code) {
if (isTransientIdentifiableProperties()) {
return null;
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.equal(root.get("code"), code));
return getSingleResult(builder, param);
}
Aggregations