use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getByName.
/**
* Uses query since name property might not be unique.
*/
@Override
public final T getByName(String name) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.equal(root.get("name"), name));
List<T> list = getList(builder, param);
T object = list != null && !list.isEmpty() ? list.get(0) : null;
if (!isReadAllowed(object, currentUserService.getCurrentUser())) {
AuditLogUtil.infoWrapper(log, currentUserService.getCurrentUsername(), object, AuditLogUtil.ACTION_READ_DENIED);
throw new ReadAccessDeniedException(String.valueOf(object));
}
return object;
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getAllOrderedName.
@Override
public List<T> getAllOrderedName(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);
return getList(builder, param);
}
use of org.hisp.dhis.hibernate.JpaQueryParameters in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStore method getCountLikeName.
@Override
public int getCountLikeName(String name) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.like(builder.lower(root.get("name")), "%" + name.toLowerCase() + "%")).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 getByCode.
@Override
public List<T> getByCode(Collection<String> codes) {
if (codes == null || codes.isEmpty()) {
return new ArrayList<>();
}
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> jpaQueryParameters = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).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 getCountGeLastUpdated.
@Override
public int getCountGeLastUpdated(Date lastUpdated) {
CriteriaBuilder builder = getCriteriaBuilder();
JpaQueryParameters<T> param = new JpaQueryParameters<T>().addPredicates(getSharingPredicates(builder)).addPredicate(root -> builder.greaterThanOrEqualTo(root.get("lastUpdated"), lastUpdated)).count(root -> builder.countDistinct(root.get("id")));
return getCount(builder, param).intValue();
}
Aggregations