use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getAllLikeNameAndEqualsAttribute.
public List<T> getAllLikeNameAndEqualsAttribute(Set<String> nameWords, String attribute, String attributeValue, int first, int max) {
if (StringUtils.isEmpty(attribute) || StringUtils.isEmpty(attributeValue)) {
return new ArrayList<>();
}
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() + "%"));
}
conjunction.add(root -> builder.equal(builder.lower(root.get(attribute)), attributeValue));
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 getByUniqueAttributeValue.
@Override
public T getByUniqueAttributeValue(Attribute attribute, String value) {
if (attribute == null || StringUtils.isEmpty(value) || !attribute.isUnique()) {
return null;
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.equal(builder.function(FUNCTION_JSONB_EXTRACT_PATH_TEXT, String.class, root.get("attributeValues"), builder.literal(attribute.getUid()), builder.literal("value")), value));
return getSingleResult(builder, param);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getByUid.
@Override
public List<T> getByUid(Collection<String> uids, User user) {
if (uids == null || uids.isEmpty()) {
return new ArrayList<>();
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> jpaQueryParameters = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder, user)).addPredicate(root -> root.get("uid").in(uids));
return getList(builder, jpaQueryParameters);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getByUid.
@Override
public final T getByUid(String uid) {
if (isTransientIdentifiableProperties()) {
return null;
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.equal(root.get("uid"), uid));
return getSingleResult(builder, param);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getAllGeLastUpdated.
@Override
public List<T> getAllGeLastUpdated(Date lastUpdated) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.greaterThanOrEqualTo(root.get("lastUpdated"), lastUpdated)).addOrder(root -> builder.desc(root.get("lastUpdated")));
return getList(builder, param);
}
Aggregations