Example usage for javax.persistence.criteria CriteriaBuilder disjunction

List of usage examples for javax.persistence.criteria CriteriaBuilder disjunction

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder disjunction.

Prototype

Predicate disjunction();

Source Link

Document

Create a disjunction (with zero disjuncts).

Usage

From source file:com.github.lothar.security.acl.jpa.spec.DenyAllSpecification.java

@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    return cb.disjunction();
}

From source file:org.openlmis.fulfillment.repository.custom.impl.OrderRepositoryImpl.java

/**
 * Retrieves the distinct UUIDs of the available requesting facilities.
 *///w  w w  .  jav  a  2s .co  m
@Override
public List<UUID> getRequestingFacilities(List<UUID> supplyingFacilityIds) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UUID> query = builder.createQuery(UUID.class);
    Root<Order> root = query.from(Order.class);

    if (!isEmpty(supplyingFacilityIds)) {
        Predicate predicate = builder.disjunction();
        for (Object elem : supplyingFacilityIds) {
            predicate = builder.or(predicate, builder.equal(root.get(SUPPLYING_FACILITY_ID), elem));
        }
        query.where(predicate);
    }

    query.select(root.get(REQUESTING_FACILITY_ID)).distinct(true);

    return entityManager.createQuery(query).getResultList();
}

From source file:com.goodhuddle.huddle.repository.MemberSpecification.java

public static Specification<Member> search(final Huddle huddle, final SearchMembersRequest request) {
    return new Specification<Member>() {
        @Override//  w  ww  .  j  a  va 2 s. c o m
        public Predicate toPredicate(Root<Member> member, CriteriaQuery<?> query, CriteriaBuilder builder) {

            Predicate conjunction = builder.conjunction();

            // huddle
            conjunction.getExpressions().add(builder.equal(member.get("huddle"), huddle));

            // keywords

            if (StringUtils.isNotBlank(request.getKeywords())) {
                String[] terms = StringUtils.split(request.getKeywords());
                for (String keyword : terms) {
                    if (keyword != null && keyword.length() > 0) {

                        String matchTerm = "%" + keyword.toLowerCase() + "%";
                        conjunction.getExpressions().add(builder.or(
                                builder.like(builder.lower(member.<String>get("username")), matchTerm),
                                builder.like(builder.lower(member.<String>get("email")), matchTerm),
                                builder.like(builder.lower(member.<String>get("firstName")), matchTerm),
                                builder.like(builder.lower(member.<String>get("lastName")), matchTerm)));
                    }
                }
            }

            // security groups

            if (CollectionUtils.isNotEmpty(request.getSecurityGroupIds())) {

                Join<Object, Object> securityGroup = member.join("securityGroup",
                        request.isIncludeNoAccess() ? JoinType.LEFT : JoinType.INNER);

                Predicate disjunction = builder.disjunction();
                for (Long id : request.getSecurityGroupIds()) {
                    disjunction.getExpressions().add(builder.equal(securityGroup.get("id"), id));
                }
                if (request.isIncludeNoAccess()) {
                    disjunction.getExpressions().add(builder.isNull(securityGroup.get("id")));
                }
                conjunction.getExpressions().add(disjunction);

            } else if (request.isIncludeNoAccess()) {

                conjunction.getExpressions().add(builder.isNull(member.get("securityGroup")));

            }

            // tags

            MemberTagFilter tagFilter = request.getTags();
            if (tagFilter != null) {

                if (tagFilter.getIncluded() != null) {

                    if (CollectionUtils.isNotEmpty(tagFilter.getIncluded().getTagIds())) {

                        MemberTagFilter.TagSet included = request.getTags().getIncluded();
                        MatchType matchType = included.getMatchType();
                        Predicate tagPredicate = matchType.equals(MatchType.all) ? builder.conjunction()
                                : builder.disjunction();

                        for (Long tagId : included.getTagIds()) {
                            Subquery<Member> sq = query.subquery(Member.class);
                            Root<Member> subMember = sq.from(Member.class);
                            Join<Member, Tag> tag = subMember.join("tags");
                            sq.select(subMember).where(builder.equal(tag.get("id"), tagId));
                            tagPredicate.getExpressions().add(builder.in(member).value(sq));
                        }

                        conjunction.getExpressions().add(tagPredicate);
                    }
                }

                if (tagFilter.getExcluded() != null) {

                    if (CollectionUtils.isNotEmpty(tagFilter.getExcluded().getTagIds())) {

                        MemberTagFilter.TagSet excluded = request.getTags().getExcluded();
                        MatchType matchType = excluded.getMatchType();
                        Predicate tagPredicate = matchType.equals(MatchType.all) ? builder.disjunction()
                                : builder.conjunction();

                        for (Long tagId : excluded.getTagIds()) {
                            Subquery<Member> sq = query.subquery(Member.class);
                            Root<Member> subMember = sq.from(Member.class);
                            Join<Member, Tag> tag = subMember.join("tags");
                            sq.select(subMember).where(builder.equal(tag.get("id"), tagId));
                            tagPredicate.getExpressions().add(builder.in(member).value(sq).not());
                        }

                        conjunction.getExpressions().add(tagPredicate);
                    }
                }

            }

            return conjunction;
        }
    };
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link DataType} with the ids.
 *
 * @param modelVersion//  w  w w. j av  a2s.  com
 *            the model version.
 * @param ids
 *            the list of ids to return.
 * @return the list of {@link DataType}.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<DataType> getDataTypesById(final String modelVersion, final List<String> ids) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<DataType> q = cb.createQuery(DataType.class);
    final Root<DataType> f = q.from(DataType.class);
    final Predicate orIds = cb.disjunction();
    ids.stream().forEach(id -> orIds.getExpressions().add(cb.equal(f.<String>get(DataType_.id), id)));
    q.where(cb.equal(f.<String>get(DataType_.modelVersion), modelVersion), orIds);
    q.orderBy(cb.asc(f.<String>get(DataType_.name)), cb.asc(f.<String>get(DataType_.id)));
    final TypedQuery<DataType> typedQuery = this.em.createQuery(q);
    final List<DataType> value = typedQuery.getResultList();
    value.stream().forEach(dt -> EagerLoader.load(dt));
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link FlowType}s matching the name pattern.
 *
 * @param modelVersion/*from w  w  w .  j  av a  2s.c o m*/
 *            the model version.
 * @param namePattern
 *            the name pattern.
 * @return the list of {@link FlowType}s matching the name pattern.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<FlowType> getFlowByNamePattern(final String modelVersion, final Collection<String> namePattern) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<FlowType> q = cb.createQuery(FlowType.class);
    final Root<FlowType> f = q.from(FlowType.class);

    final Predicate or = cb.disjunction();
    namePattern.stream()
            .forEach(id -> or.getExpressions().add(cb.like(f.<String>get(FlowType_.name), "%" + id + "%")));
    final Predicate and = cb.conjunction();
    and.getExpressions().add(cb.equal(f.<String>get(FlowType_.modelVersion), modelVersion));
    and.getExpressions().add(or);
    q.where(and);
    final TypedQuery<FlowType> typedQuery = this.em.createQuery(q);
    final List<FlowType> value = typedQuery.getResultList();
    value.stream().forEach(ft -> EagerLoader.load(ft));
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

private List<String> getInterfaceMappingFieldDefinitionIds(final String modelVersion,
        final List<String> interfaceMappingIds) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<String> q = cb.createQuery(String.class);
    final Root<FieldType> f = q.from(FieldType.class);

    final Predicate orParentIds = cb.disjunction();
    interfaceMappingIds.stream()/*from  ww  w.j a v a 2 s.co m*/
            .forEach(id -> orParentIds.getExpressions().add(cb.equal(f.<String>get(FieldType_.parentId), id)));

    q.select(f.<String>get(FieldType_.fieldTypeDefinitionId));
    q.where(cb.equal(f.<String>get(FieldType_.modelVersion), modelVersion), orParentIds);
    final TypedQuery<String> typedQuery = this.em.createQuery(q);
    final List<String> value = typedQuery.getResultList();
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link ComplexType} with the ids.
 *
 * @param modelVersion//from   w w w .j a va  2s. com
 *            the model version.
 * @param ids
 *            the list of ids to return.
 * @return the list of {@link ComplexType}.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<ComplexType> getComplexTypesById(final String modelVersion, final List<String> ids) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<ComplexType> q = cb.createQuery(ComplexType.class);
    final Root<ComplexType> f = q.from(ComplexType.class);
    final Predicate orIds = cb.disjunction();
    ids.stream().forEach(id -> orIds.getExpressions().add(cb.equal(f.<String>get(ComplexType_.id), id)));
    q.where(cb.equal(f.<String>get(ComplexType_.modelVersion), modelVersion), orIds);
    final TypedQuery<ComplexType> typedQuery = this.em.createQuery(q);
    final List<ComplexType> value = typedQuery.getResultList();
    value.stream().forEach(ct -> EagerLoader.load(ct));
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link ElementType} with the ids.
 *
 * @param modelVersion//from  w  w  w . j a v  a  2 s  .  c  om
 *            the model version.
 * @param ids
 *            the list of ids to return.
 * @return the list of {@link ElementType}.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<ElementType> getElementTypesById(final String modelVersion, final List<String> ids) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<ElementType> q = cb.createQuery(ElementType.class);
    final Root<ElementType> f = q.from(ElementType.class);
    final Predicate orIds = cb.disjunction();
    ids.stream().forEach(id -> orIds.getExpressions().add(cb.equal(f.<String>get(ElementType_.id), id)));
    q.where(cb.equal(f.<String>get(ElementType_.modelVersion), modelVersion), orIds);
    final TypedQuery<ElementType> typedQuery = this.em.createQuery(q);
    final List<ElementType> value = typedQuery.getResultList();
    value.stream().forEach(ct -> EagerLoader.load(ct));
    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

private List<String> getFlowMappingInterfaceMappingTypeIds(final String modelVersion,
        final List<String> flowProcessTypeIds) {
    final List<String> value = new ArrayList<String>();
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<Long> q = cb.createQuery(Long.class);
    final Root<FlowMapInOutType> f = q.from(FlowMapInOutType.class);

    final Predicate orParentIds = cb.disjunction();
    flowProcessTypeIds.stream().forEach(
            id -> orParentIds.getExpressions().add(cb.equal(f.<String>get(FlowMapInOutType_.parentId), id)));

    q.select(f.<Long>get(FlowMapInOutType_.hjid));
    q.where(cb.equal(f.<String>get(FlowMapInOutType_.modelVersion), modelVersion), orParentIds);

    final TypedQuery<Long> typedQuery = this.em.createQuery(q);
    typedQuery.getResultList().stream().forEach(hjid -> {
        value.addAll(this.em.getReference(FlowMapInOutType.class, hjid).getInterfaceMappingId());
    });//from   w  w w  .jav a 2  s  .c  om

    return value;
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link FieldMappingType} with the ids.
 *
 * @param modelVersion/*from   w  w  w .  ja  v a2 s.  co  m*/
 *            the model version.
 * @param ids
 *            the list of ids to return.
 * @return the list of {@link FieldMappingType}.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<FieldMappingType> getFieldMappingTypesById(final String modelVersion, final List<String> ids) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<FieldMappingType> q = cb.createQuery(FieldMappingType.class);
    final Root<FieldMappingType> f = q.from(FieldMappingType.class);
    final Predicate orIds = cb.disjunction();
    ids.stream().forEach(id -> orIds.getExpressions().add(cb.equal(f.<String>get(FieldMappingType_.id), id)));
    q.where(cb.equal(f.<String>get(FieldMappingType_.modelVersion), modelVersion), orIds);
    final TypedQuery<FieldMappingType> typedQuery = this.em.createQuery(q);
    final List<FieldMappingType> value = typedQuery.getResultList();
    value.stream().forEach(ct -> EagerLoader.load(ct));
    return value;
}