Java Code Examples for javax.persistence.criteria.CriteriaBuilder#disjunction()

The following examples show how to use javax.persistence.criteria.CriteriaBuilder#disjunction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessPlatformPlan.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private Predicate workPredicate_creator(CriteriaBuilder cb, Root<Work> root) throws Exception {
	List<String> _creatorUnits = ListTools.extractField(this.creatorUnitList, "name", String.class, true, true);
	List<String> _creatorPersons = ListTools.extractField(this.creatorPersonList, "name", String.class, true,
			true);
	List<String> _creatorIdentitys = ListTools.extractField(this.creatorIdentityList, "name", String.class,
			true, true);
	if (_creatorUnits.isEmpty() && _creatorPersons.isEmpty() && _creatorIdentitys.isEmpty()) {
		return null;
	}
	Predicate p = cb.disjunction();
	if (!_creatorUnits.isEmpty()) {
		p = cb.or(p, root.get(Work_.creatorUnit).in(_creatorUnits));
	}
	if (!_creatorPersons.isEmpty()) {
		p = cb.or(p, root.get(Work_.creatorPerson).in(_creatorPersons));
	}
	if (!_creatorIdentitys.isEmpty()) {
		p = cb.or(p, root.get(Work_.creatorIdentity).in(_creatorIdentitys));
	}
	return p;
}
 
Example 2
Source File: ProcessPlatformPlan.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private Predicate workPredicate_application(CriteriaBuilder cb, Root<Work> root) throws Exception {
	List<String> _application_ids = ListTools.extractField(this.applicationList, Application.id_FIELDNAME,
			String.class, true, true);
	List<String> _process_ids = ListTools.extractField(this.processList, Process.id_FIELDNAME, String.class,
			true, true);
	_application_ids = _application_ids.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	_process_ids = _process_ids.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	if (_application_ids.isEmpty() && _process_ids.isEmpty()) {
		return null;
	}
	Predicate p = cb.disjunction();
	if (!_application_ids.isEmpty()) {
		p = cb.or(p, root.get(Work_.application).in(_application_ids));
	}
	if (!_process_ids.isEmpty()) {
		p = cb.or(p, root.get(Work_.process).in(_process_ids));
	}
	return p;
}
 
Example 3
Source File: ActionClean.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<String> list(Business business, Boolean cleanWork, Boolean cleanWorkCompleted, Boolean cleanCms)
		throws Exception {
	EntityManager em = business.entityManagerContainer().get(Entry.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Entry> root = cq.from(Entry.class);
	Predicate p = cb.disjunction();
	if (BooleanUtils.isTrue(cleanWork)) {
		p = cb.or(p, cb.equal(root.get(Entry_.type), Entry.TYPE_WORK));
	}
	if (BooleanUtils.isTrue(cleanWorkCompleted)) {
		p = cb.or(p, cb.equal(root.get(Entry_.type), Entry.TYPE_WORKCOMPLETED));
	}
	if (BooleanUtils.isTrue(cleanCms)) {
		p = cb.or(p, cb.equal(root.get(Entry_.type), Entry.TYPE_CMS));
	}
	cq.select(root.get(Entry_.id)).where(p);
	List<String> os = em.createQuery(cq).setMaxResults(BATCHSIZE).getResultList();
	return os;
}
 
Example 4
Source File: EntityManagerContainer.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public <T extends JpaObject> boolean duplicateWithRestrictFlags(Class<T> clz, String restrictSingularAttribute,
		Object restrictValue, String excludeId, List<String> values) throws Exception {
	values = ListTools.trim(values, true, true);
	EntityManager em = this.get(clz);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<T> root = cq.from(clz);
	Predicate p = cb.disjunction();
	for (Field field : this.entityManagerContainerFactory.getFlagFields(clz)) {
		p = cb.or(p, root.get(field.getName()).in(StringTools.filterLessThanOrEqualToUtf8Length(values,
				JpaObjectTools.definedLength(clz, field.getName()))));
	}
	if (StringUtils.isNotEmpty(excludeId)) {
		p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	}
	return em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult() > 0;
}
 
Example 5
Source File: ProcessPlatformPlan.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private Predicate workCompletedPredicate_creator(CriteriaBuilder cb, Root<WorkCompleted> root)
		throws Exception {
	List<String> _creatorUnits = ListTools.extractField(this.creatorUnitList, "name", String.class, true, true);
	List<String> _creatorPersons = ListTools.extractField(this.creatorPersonList, "name", String.class, true,
			true);
	List<String> _creatorIdentitys = ListTools.extractField(this.creatorIdentityList, "name", String.class,
			true, true);
	if (_creatorUnits.isEmpty() && _creatorPersons.isEmpty() && _creatorIdentitys.isEmpty()) {
		return null;
	}
	Predicate p = cb.disjunction();
	if (!_creatorUnits.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.creatorUnit).in(_creatorUnits));
	}
	if (!_creatorPersons.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.creatorPerson).in(_creatorPersons));
	}
	if (!_creatorIdentitys.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.creatorIdentity).in(_creatorIdentitys));
	}
	return p;
}
 
Example 6
Source File: IncludesIssueCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Collection<Long> pullRequestIds = getPullRequestIds(issue.getProject());
	if (!pullRequestIds.isEmpty()) {
		return builder.and(
				builder.equal(root.get(PullRequest.PROP_TARGET_PROJECT), issue.getProject()),
				root.get(PullRequest.PROP_ID).in(pullRequestIds));
	} else {
		return builder.disjunction();
	}
}
 
Example 7
Source File: CmsPlan.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private Predicate documentPredicate_creator(CriteriaBuilder cb, Root<Document> root) throws Exception {
	List<String> _creatorUnits = ListTools.trim(this.creatorUnitList, true, true);
	List<String> _creatorPersons = ListTools.trim(this.creatorPersonList, true, true);
	List<String> _creatorIdentitys = ListTools.trim(this.creatorIdentityList, true, true);
	if (_creatorUnits.isEmpty() && _creatorPersons.isEmpty() && _creatorIdentitys.isEmpty()) {
		return null;
	}
	Predicate p = cb.disjunction();
	if ( ListTools.isNotEmpty( _creatorUnits) ) {
		if( _creatorUnits.size() == 1) {
			p = cb.or(p, cb.equal( root.get(Document_.creatorUnitName), _creatorUnits.get( 0 )));
		}else {
			p = cb.or(p, root.get(Document_.creatorUnitName).in(_creatorUnits));
		}
	}
	if ( ListTools.isNotEmpty( _creatorPersons) ) {
		if( _creatorPersons.size() == 1) {
			p = cb.or(p, cb.equal( root.get(Document_.creatorPerson), _creatorPersons.get( 0 )));
		}else {
			p = cb.or(p, root.get(Document_.creatorPerson).in(_creatorPersons));
		}
	}
	if ( ListTools.isNotEmpty( _creatorIdentitys) ) {
		if( _creatorIdentitys.size() == 1) {
			p = cb.or(p, cb.equal( root.get(Document_.creatorIdentity), _creatorIdentitys.get( 0 )));
		}else {
			p = cb.or(p, root.get(Document_.creatorIdentity).in(_creatorIdentitys));
		}
	}
	return p;
}
 
Example 8
Source File: ByFullTextUtil.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
private <T> Predicate onSimplePrimaryKey(Root<T> root, CriteriaBuilder builder, SearchParameters sp, List<SingularAttribute<?, ?>> properties) {
    List<Serializable> ids = hibernateSearchUtil.findId(root.getJavaType(), sp, properties);
    if (ids == null) {
        return null;
    } else if (ids.isEmpty()) {
        return builder.disjunction();
    }

    return jpaUtil.concatPredicate(sp, builder, root.get("id").in(ids));
}
 
Example 9
Source File: EntityManagerContainer.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public <T extends JpaObject> boolean duplicateWithFlags(List<String> excludeIds, Class<T> clz, String... value)
		throws Exception {
	List<String> list = Arrays.asList(value);
	EntityManager em = this.get(clz);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<T> root = cq.from(clz);
	Predicate p = cb.disjunction();
	for (Field field : this.entityManagerContainerFactory.getFlagFields(clz)) {
		p = cb.or(p, root.get(field.getName())
				.in(StringTools.filterLessThanOrEqualToUtf8Length(list, JpaObjectTools.definedLength(clz, field))));
	}
	p = cb.and(p, cb.not(root.get(JpaObject.id_FIELDNAME).in(excludeIds)));
	return em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult() > 0;
}
 
Example 10
Source File: EntityManagerContainer.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public <T extends JpaObject> boolean duplicateWithFlags(String excludeId, Class<T> clz, String... value)
		throws Exception {
	List<String> list = Arrays.asList(value);
	EntityManager em = this.get(clz);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<T> root = cq.from(clz);
	Predicate p = cb.disjunction();
	for (Field field : this.entityManagerContainerFactory.getFlagFields(clz)) {
		p = cb.or(p, root.get(field.getName())
				.in(StringTools.filterLessThanOrEqualToUtf8Length(list, JpaObjectTools.definedLength(clz, field))));
	}
	p = cb.and(p, cb.notEqual(root.get(JpaObject.id_FIELDNAME), excludeId));
	return em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult() > 0;
}
 
Example 11
Source File: WhereEntryTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Predicate documentPredicateIdentity(CriteriaBuilder cb, Root<Document> root,
		List<NameIdPair> identities) throws Exception {
	if (ListTools.isEmpty(identities)) {
		return cb.disjunction();
	}
	return root.get(Document.creatorIdentity_FIELDNAME)
			.in(ListTools.extractProperty(identities, "name", String.class, true, true));
}
 
Example 12
Source File: WhereEntryTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Predicate documentPredicatePerson(CriteriaBuilder cb, Root<Document> root, List<NameIdPair> people)
		throws Exception {
	if (ListTools.isEmpty(people)) {
		return cb.disjunction();
	}
	return root.get(Document.creatorPerson_FIELDNAME)
			.in(ListTools.extractProperty(people, "name", String.class, true, true));
}
 
Example 13
Source File: WhereEntryTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Predicate documentPredicateUnit(CriteriaBuilder cb, Root<Document> root, List<NameIdPair> Units)
		throws Exception {
	if (ListTools.isEmpty(Units)) {
		return cb.disjunction();
	}
	return root.get(Document.creatorUnitName_FIELDNAME)
			.in(ListTools.extractProperty(Units, "name", String.class, true, true));
}
 
Example 14
Source File: WhereEntryTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Predicate documentPredicateAppInfo(CriteriaBuilder cb, Root<Document> root, List<NameIdPair> appIds)
		throws Exception {
	if (ListTools.isEmpty(appIds)) {
		return cb.disjunction();
	}
	return root.get(Document.appId_FIELDNAME)
			.in(ListTools.extractProperty(appIds, JpaObject.id_FIELDNAME, String.class, true, true));
}
 
Example 15
Source File: FixedInBuildCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<Issue> root, CriteriaBuilder builder) {
	Collection<Long> fixedIssueNumbers = build.getFixedIssueNumbers();
	if (!fixedIssueNumbers.isEmpty()) {
		return builder.and(
				builder.equal(root.get(Issue.PROP_PROJECT), build.getProject()),
				root.get(Issue.PROP_NUMBER).in(fixedIssueNumbers));
	} else {
		return builder.disjunction();
	}
}
 
Example 16
Source File: FixedInCommitCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<Issue> root, CriteriaBuilder builder) {
	if (!commit.getFixedIssueNumbers().isEmpty()) {
		return builder.and(
				builder.equal(root.get(Issue.PROP_PROJECT), commit.getProject()),
				root.get(Issue.PROP_NUMBER).in(commit.getFixedIssueNumbers()));
	} else {
		return builder.disjunction();
	}
}
 
Example 17
Source File: FixedInPullRequestCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<Issue> root, CriteriaBuilder builder) {
	Collection<Long> fixedIssueNumbers = request.getFixedIssueNumbers();
	if (!fixedIssueNumbers.isEmpty()) {
		return builder.and(
				builder.equal(root.get(Issue.PROP_PROJECT), request.getTargetProject()),
				root.get(Issue.PROP_NUMBER).in(fixedIssueNumbers));
	} else {
		return builder.disjunction();
	}
}
 
Example 18
Source File: IncludesCommitCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Collection<Long> pullRequestIds = getPullRequestIds();
	if (!pullRequestIds.isEmpty()) {
		return builder.and(
				builder.equal(root.get(PullRequest.PROP_TARGET_PROJECT), project),
				root.get(PullRequest.PROP_ID).in(pullRequestIds));
	} else {
		return builder.disjunction();
	}
}
 
Example 19
Source File: DenyAllSpecification.java    From strategy-spring-security-acl with Apache License 2.0 4 votes vote down vote up
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
  return cb.disjunction();
}
 
Example 20
Source File: ProcessPlatformPlan.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private Predicate workCompletedPredicate_application(CriteriaBuilder cb, Root<WorkCompleted> root)
		throws Exception {
	List<String> _application_ids = ListTools.extractField(this.applicationList, Application.id_FIELDNAME,
			String.class, true, true);
	List<String> _application_names = ListTools.extractField(this.applicationList, Application.name_FIELDNAME,
			String.class, true, true);
	List<String> _application_alias = ListTools.extractField(this.applicationList, Application.alias_FIELDNAME,
			String.class, true, true);
	List<String> _process_ids = ListTools.extractField(this.processList, Process.id_FIELDNAME, String.class,
			true, true);
	List<String> _process_names = ListTools.extractField(this.processList, Process.name_FIELDNAME, String.class,
			true, true);
	List<String> _process_alias = ListTools.extractField(this.processList, Process.alias_FIELDNAME,
			String.class, true, true);
	_application_ids = _application_ids.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	_application_names = _application_names.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	_application_alias = _application_alias.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	_process_ids = _process_ids.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	_process_names = _process_names.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	_process_alias = _process_alias.stream().filter(o -> {
		return StringUtils.isNotEmpty(o);
	}).collect(Collectors.toList());
	if (_application_ids.isEmpty() && _application_names.isEmpty() && _application_alias.isEmpty()
			&& _process_ids.isEmpty() && _process_names.isEmpty() && _process_alias.isEmpty()) {
		return null;
	}
	Predicate p = cb.disjunction();
	if (!_application_ids.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.application).in(_application_ids));
	}
	if (!_application_names.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.applicationName).in(_application_names));
	}
	if (!_application_alias.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.applicationAlias).in(_application_alias));
	}
	if (!_process_ids.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.process).in(_process_ids));
	}
	if (!_process_names.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.processName).in(_process_names));
	}
	if (!_process_alias.isEmpty()) {
		p = cb.or(p, root.get(WorkCompleted_.processAlias).in(_process_alias));
	}
	return p;
}