use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getAllLeCreated.
@Override
public List<T> getAllLeCreated(Date created) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.lessThanOrEqualTo(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 getByUniqueAttributeValue.
@Override
public T getByUniqueAttributeValue(Attribute attribute, String value, User user) {
if (attribute == null || StringUtils.isEmpty(value) || !attribute.isUnique()) {
return null;
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder, user)).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) {
if (uids == null || uids.isEmpty()) {
return new ArrayList<>();
}
// TODO Include paging to avoid exceeding max query length
CriteriaBuilder builder = getCriteriaBuilder();
List<List<String>> uidPartitions = Lists.partition(new ArrayList<>(uids), 20000);
List<Function<Root<T>, Predicate>> sharingPredicates = getSharingPredicates(builder);
List<T> returnList = new ArrayList<>();
for (List<String> partition : uidPartitions) {
JpaQueryParameters<T> jpaQueryParameters = new JpaQueryParameters<T>().addPredicates(sharingPredicates).addPredicate(root -> root.get("uid").in(partition));
returnList.addAll(getList(builder, jpaQueryParameters));
}
return returnList;
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateEventVisualizationStore method countEventVisualizationCreated.
private int countEventVisualizationCreated(final Date startingAt, final EventVisualizationSet eventVisualizationSet) {
final CriteriaBuilder builder = getCriteriaBuilder();
final JpaQueryParameters<EventVisualization> params = new JpaQueryParameters<EventVisualization>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.greaterThanOrEqualTo(root.get("created"), startingAt)).count(root -> builder.countDistinct(root.get("id")));
setCorrectPredicates(eventVisualizationSet, builder, params);
return getCount(builder, params).intValue();
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateDataElementStore method getDataElement.
@Override
public DataElement getDataElement(String uid, User user) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<DataElement> param = new JpaQueryParameters<DataElement>().addPredicates(getSharingPredicates(builder, user, AclService.LIKE_READ_METADATA)).addPredicate(root -> builder.equal(root.get("uid"), uid));
return getSingleResult(builder, param);
}
Aggregations