@Override public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path<Character> explicitPath, List<Character> directValues) { return builder.isNotNull(explicitPath); } })
@Override public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) { Path<Long> path; if (explicitPath != null) { path = explicitPath; } else { path = fieldPathBuilder.getPath(root, fullPropertyName, builder); } return builder.isNotNull(path); } }
private CriteriaQuery<SearchRedirect> buildFindSearchRedirectBySearchTermCriteria(String searchTerm) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<SearchRedirect> criteria = builder.createQuery(SearchRedirect.class); Root<SearchRedirectImpl> redirect = criteria.from(SearchRedirectImpl.class); List<Predicate> restrictions = new ArrayList<>(); restrictions.add(builder.equal(builder.upper(redirect.<String>get("searchTerm")), searchTerm.toUpperCase())); // Add the active start/end date restrictions Date currentDate = getCurrentDateAfterFactoringInDateResolution(); if (isNullActiveStartDateActive) { restrictions.add(builder.or(builder.isNull(redirect.get("activeStartDate")), builder.lessThanOrEqualTo(redirect.get("activeStartDate").as(Date.class), currentDate))); } else { restrictions.add(builder.and(builder.isNotNull(redirect.get("activeStartDate")), builder.lessThanOrEqualTo(redirect.get("activeStartDate").as(Date.class), currentDate))); } restrictions.add(builder.or(builder.isNull(redirect.get("activeEndDate")), builder.greaterThan(redirect.get("activeEndDate").as(Date.class), currentDate))); // Add the restrictions to the criteria query criteria.select(redirect); criteria.where(restrictions.toArray(new Predicate[restrictions.size()])); return criteria.orderBy(builder.asc(redirect.get("searchPriority"))); }
@Override public List<SandBox> retrieveSandBoxesForAuthor(Long authorId, SandBoxType sandBoxType) { CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder(); CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class); Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class); criteria.select(sandbox.get("sandBox").as(SandBox.class)); List<Predicate> restrictions = new ArrayList<Predicate>(); restrictions.add(builder.equal(sandbox.get("sandBox").get("author"), authorId)); restrictions.add( builder.or( builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")) ); if (sandBoxType != null) { restrictions.add(builder.equal(sandbox.get("sandBox").get("sandboxType"), sandBoxType.getType())); } restrictions.add( builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y')) ); criteria.where(restrictions.toArray(new Predicate[restrictions.size()])); TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria); return query.getResultList(); }
/** * given a list of AND-ed query restrictions, adds to the list the restrictions necessary for effective-dating * The rules used are: * <ul> * <li>The "activeStart" effective date has to exist (otherwise, inactive)</li> * <li>The "activeStart" effective date has be prior or equal to today</li> * <li>For the record to remain active, the "activeEnd" date can be either left unspecified, or be after today</li> * <ul> * @param builder the Criteria builder * @param restrictions the list of AND-ed restrictions * @param datesPath the Path expression that can be used to retrieve the date fields * @param startDateFieldName the name of the start date field, for example, "activeStartDate" * @param endDateFieldName the name of the end date field, for example, "activeEndDate" */ public static void effectiveDate(CriteriaBuilder builder, List<Predicate> restrictions, Path datesPath, String startDateFieldName, String endDateFieldName) { Date now = new Date(); Path<Date> activeStartDate = datesPath.<Date>get(startDateFieldName); Path<Date> activeEndDate = datesPath.<Date>get(endDateFieldName); restrictions.add(builder.isNotNull(activeStartDate)); restrictions.add(builder.lessThanOrEqualTo(activeStartDate, now)); Predicate notExpired = builder.or(builder.isNull(activeEndDate), builder.greaterThan(activeEndDate, now)); restrictions.add(notExpired); }
@Override public List<SandBox> retrieveAllSandBoxes() { CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder(); CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class); Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class); criteria.select(sandbox.get("sandBox").as(SandBox.class)); criteria.where( builder.and(builder.or( builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")), builder.or( builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y'))) ); TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria); return query.getResultList(); }
@Override public List<SandBox> retrieveChildSandBoxesByParentId(Long parentSandBoxId) { CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder(); CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class); Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class); criteria.select(sandbox.get("sandBox").as(SandBox.class)); criteria.where( builder.and(sandbox.get("sandBox").get("parentSandBox").in(parentSandBoxId), builder.or(builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")), builder.or(builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y'))) ); TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria); return query.getResultList(); }
@Override public List<SandBox> retrieveSandBoxesByType(SandBoxType sandboxType) { CriteriaBuilder builder = sandBoxEntityManager.getCriteriaBuilder(); CriteriaQuery<SandBox> criteria = builder.createQuery(SandBox.class); Root<SandBoxManagementImpl> sandbox = criteria.from(SandBoxManagementImpl.class); criteria.select(sandbox.get("sandBox").as(SandBox.class)); criteria.where( builder.and(builder.equal(sandbox.get("sandBox").get("sandboxType"), sandboxType.getType()), builder.or( builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")), builder.or( builder.isNull(sandbox.get("sandBox").get("archiveStatus").get("archived").as(String.class)), builder.notEqual(sandbox.get("sandBox").get("archiveStatus").get("archived").as(Character.class), 'Y'))) ); TypedQuery<SandBox> query = sandBoxEntityManager.createQuery(criteria); return query.getResultList(); }
restrictions.add( builder.or( builder.isNotNull(sandbox.get("sandBox").get("name")), builder.notEqual(sandbox.get("sandBox").get("name").as(String.class), "")) );
protected Predicate buildCompositePredicate(CriteriaBuilder builder, Path targetPropertyPath, Path productPath, Predicate propertyExpression, Predicate defaultSkuExpression) { return builder.or( builder.or( builder.and(builder.isNotNull(targetPropertyPath), propertyExpression), builder.and( builder.and( builder.isNull(targetPropertyPath), builder.isNotNull(productPath) ), defaultSkuExpression ) ), builder.and(builder.isNull(productPath), propertyExpression) ); }
@Override public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) { Date currentTime = SystemTime.asDate(true); if (isActive) { return builder.and( builder.isNotNull(root.get("startDate")), builder.lessThan(root.get("startDate"), currentTime), builder.or( builder.isNull(root.get("endDate")), builder.greaterThan(root.get("endDate"), currentTime) ) ); } else { return builder.or( builder.isNull(root.get("startDate")), builder.greaterThan(root.get("startDate"), currentTime), builder.and( builder.isNotNull(root.get("endDate")), builder.lessThan(root.get("endDate"), currentTime) ) ); } } }
preds.add(_builder.notEqual(p, vals[0])); } else if (op == Op.NOT_NULL) { preds.add(_builder.isNotNull(p)); } else if (op == Op.IN) {
/** * {@link Specification} for retrieving {@link JpaTargetFilterQuery}s based * on is {@link JpaTargetFilterQuery#getName()}. * * @return the {@link JpaTargetFilterQuery} {@link Specification} */ public static Specification<JpaTargetFilterQuery> withAutoAssignDS() { return (targetFilterQueryRoot, query, cb) -> cb .isNotNull(targetFilterQueryRoot.get(JpaTargetFilterQuery_.autoAssignDistributionSet)); } }
public List<Predicate> createFilterCondition(CriteriaBuilder criteriaBuilder, Root<SLASummaryBean> root) { return Collections.singletonList(criteriaBuilder.and( criteriaBuilder.isNotNull(root.get(DBFIELD_EXPECTED_END_TS)), criteriaBuilder.isNotNull(root.get(DBFIELD_ACTUAL_END_TS)), criteriaBuilder.greaterThanOrEqualTo(root.get(DBFIELD_EXPECTED_END_TS), root.get(DBFIELD_ACTUAL_END_TS)))); }}, END_MISS_FILTER {
public List<Predicate> createFilterCondition(CriteriaBuilder criteriaBuilder, Root<SLASummaryBean> root) { return Collections.singletonList(criteriaBuilder.and( criteriaBuilder.isNotNull(root.get(DBFIELD_EXPECTED_START_TS)), criteriaBuilder.isNotNull(root.get(DBFIELD_ACTUAL_START_TS)), criteriaBuilder.ge(root.get(DBFIELD_EXPECTED_START_TS), root.get(DBFIELD_ACTUAL_START_TS)))); }}, START_MISS_FILTER {
protected <X> Specification<ENTITY> byFieldSpecified(Function<Root<ENTITY>, Expression<X>> metaclassFunction, final boolean specified) { return specified ? (root, query, builder) -> builder.isNotNull(metaclassFunction.apply(root)) : (root, query, builder) -> builder.isNull(metaclassFunction.apply(root)); }
public List<Predicate> createFilterCondition(CriteriaBuilder criteriaBuilder, Root<SLASummaryBean> root) { return Collections.singletonList(criteriaBuilder.and( criteriaBuilder.isNotNull(root.get(DBFIELD_EXPECTED_START_TS)), criteriaBuilder.isNotNull(root.get(DBFIELD_ACTUAL_START_TS)), criteriaBuilder.ge(root.get(DBFIELD_EXPECTED_START_TS), root.get(DBFIELD_ACTUAL_START_TS)))); }}, START_MISS_FILTER {
@Override public List<Predicate> build(CriteriaBuilder builder, Path<E> path) { return Arrays.asList(builder.isNotNull(path.get(getAtt()))); }
@Override public List<EPerson> findWithPasswordWithoutDigestAlgorithm(Context context) throws SQLException { CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context); CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, EPerson.class); Root<EPerson> ePersonRoot = criteriaQuery.from(EPerson.class); criteriaQuery.select(ePersonRoot); criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.isNotNull(ePersonRoot.get(EPerson_.password)), criteriaBuilder.isNull(ePersonRoot.get(EPerson_.digestAlgorithm)) ) ); return list(context, criteriaQuery, false, EPerson.class, -1, -1); }
@Override public Predicate getNotMatchingLocaleString(final String locale) { if (locale == null) return null; final String defaultLocale = ApplicationConfig.getInstance().getDefaultLocale(); final CriteriaBuilder criteriaBuilder = getCriteriaBuilder(); final Predicate localePredicate = criteriaBuilder.notEqual(getRootPath().get("locale").get("value"), locale); if (defaultLocale != null && defaultLocale.toLowerCase().equals(locale.toLowerCase())) return criteriaBuilder.and(localePredicate, criteriaBuilder.isNotNull(getRootPath().get("locale").get("value"))); return localePredicate; }