Java Code Examples for javax.persistence.criteria.Join#isNotNull()

The following examples show how to use javax.persistence.criteria.Join#isNotNull() . 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: OwnedByCriteria.java    From onedev with MIT License 6 votes vote down vote up
@Override
public Predicate getPredicate(Root<Project> root, CriteriaBuilder builder) {
	Join<?, ?> userAuthorizationJoin = root.join(Project.PROP_USER_AUTHORIZATIONS, JoinType.LEFT);

	userAuthorizationJoin.on(builder.and(
			builder.equal(userAuthorizationJoin.get(UserAuthorization.PROP_ROLE), Role.OWNER_ID), 
			builder.equal(userAuthorizationJoin.get(UserAuthorization.PROP_USER), user)));
	
	if (user.getGroups().isEmpty()) {
		return userAuthorizationJoin.isNotNull();
	} else {
		Join<?, ?> groupAuthorizationJoin = root.join(Project.PROP_GROUP_AUTHORIZATIONS, JoinType.LEFT);
		groupAuthorizationJoin.on(builder.and(
				builder.equal(groupAuthorizationJoin.get(GroupAuthorization.PROP_ROLE), Role.OWNER_ID), 
				groupAuthorizationJoin.get(GroupAuthorization.PROP_GROUP).in(user.getGroups())));
		return builder.or(userAuthorizationJoin.isNotNull(), groupAuthorizationJoin.isNotNull());
	}
}
 
Example 2
Source File: FieldCriteria.java    From onedev with MIT License 6 votes vote down vote up
@Override
public final Predicate getPredicate(Root<Issue> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(Issue.PROP_FIELDS, JoinType.LEFT);
	Predicate valuePredicate = getValuePredicate(join, builder);
	if (valuePredicate != null) {
		join.on(builder.and(
				builder.equal(join.get(IssueField.PROP_NAME), getFieldName()), 
				getValuePredicate(join, builder)));
		return join.isNotNull();
	} else {
		join.on(builder.and(
				builder.equal(join.get(IssueField.PROP_NAME), getFieldName()), 
				builder.or(builder.isNull(join.get(IssueField.PROP_VALUE)))));
		Join<?, ?> join2 = root.join(Issue.PROP_FIELDS, JoinType.LEFT);
		join2.on(builder.equal(join2.get(IssueField.PROP_NAME), getFieldName()));
		return builder.or(join.isNotNull(), join2.isNull());
	}
}
 
Example 3
Source File: ReplyCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<CodeComment> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(CodeComment.PROP_REPLIES, JoinType.LEFT);
	Path<String> attribute = join.get(CodeCommentReply.PROP_CONTENT);
	join.on(builder.like(builder.lower(attribute), "%" + value.toLowerCase().replace('*', '%') + "%"));
	return join.isNotNull();
}
 
Example 4
Source File: CommentCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<Issue> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(Issue.PROP_COMMENTS, JoinType.LEFT);
	Path<String> attribute = join.get(IssueComment.PATH_CONTENT);
	join.on(builder.like(builder.lower(attribute), "%" + value.toLowerCase() + "%"));
	return join.isNotNull();
}
 
Example 5
Source File: RequestedForChangesByMeCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	if (User.get() != null) {
		Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
		Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
		Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
		join.on(builder.and(
				builder.equal(userPath, User.get()), 
				builder.equal(approvedPath, false)));
		return join.isNotNull();
	} else {
		throw new OneException("Please login to perform this query");
	}
}
 
Example 6
Source File: ToBeReviewedByMeCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	if (User.get() != null) {
		Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
		Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
		Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
		join.on(builder.and(
				builder.equal(userPath, User.get()), 
				builder.isNull(approvedPath)));
		return join.isNotNull();
	} else {
		throw new OneException("Please login to perform this query");
	}
}
 
Example 7
Source File: HasFailedBuildsCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root
			.join(PullRequest.PROP_VERIFICATIONS, JoinType.LEFT)
			.join(PullRequestVerification.PROP_BUILD, JoinType.INNER);
	Path<?> status = join.get(Build.STATUS);
	
	join.on(builder.or(
			builder.equal(status, Build.Status.FAILED), 
			builder.equal(status, Build.Status.CANCELLED), 
			builder.equal(status, Build.Status.TIMED_OUT)));
	return join.isNotNull();
}
 
Example 8
Source File: CommentCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_COMMENTS, JoinType.LEFT);
	Path<String> attribute = join.get(PullRequestComment.PROP_CONTENT);
	join.on(builder.like(builder.lower(attribute), "%" + value.toLowerCase() + "%"));
	return join.isNotNull();
}
 
Example 9
Source File: ParamCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<Build> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(Build.PROP_PARAMS, JoinType.LEFT);
	join.on(builder.and(
			builder.equal(join.get(BuildParam.PROP_NAME), name)),
			builder.equal(join.get(BuildParam.PROP_VALUE), value));
	return join.isNotNull();
}
 
Example 10
Source File: ToBeVerifiedByBuildsCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root
			.join(PullRequest.PROP_VERIFICATIONS, JoinType.LEFT)
			.join(PullRequestVerification.PROP_BUILD, JoinType.INNER);
	Path<?> status = join.get(Build.STATUS);
	join.on(builder.or(
			builder.equal(status, Build.Status.RUNNING), 
			builder.equal(status, Build.Status.PENDING), 
			builder.equal(status, Build.Status.WAITING)));
	
	return join.isNotNull();
}
 
Example 11
Source File: AssignedToCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_ASSIGNMENTS, JoinType.LEFT);
	Path<?> userPath = EntityQuery.getPath(join, PullRequestAssignment.PROP_USER);
	join.on(builder.equal(userPath, user));
	return join.isNotNull();
}
 
Example 12
Source File: ApprovedByCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
	Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
	Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
	join.on(builder.and(
			builder.equal(userPath, user), 
			builder.equal(approvedPath, true)));
	return join.isNotNull();
}
 
Example 13
Source File: AssignedToMeCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	if (User.get() != null) {
		Join<?, ?> join = root.join(PullRequest.PROP_ASSIGNMENTS, JoinType.LEFT);
		Path<?> userPath = EntityQuery.getPath(join, PullRequestAssignment.PROP_USER);
		join.on(builder.equal(userPath, User.get())); 
		return join.isNotNull();
	} else {
		throw new OneException("Please login to perform this query");
	}
}
 
Example 14
Source File: ToBeReviewedByCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
	Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
	Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
	join.on(builder.and(
			builder.equal(userPath, user), 
			builder.isNull(approvedPath)));
	return join.isNotNull();
}
 
Example 15
Source File: SomeoneRequestedForChangesCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
	Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
	Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
	join.on(builder.and(
			builder.isNotNull(userPath), 
			builder.equal(approvedPath, false)));
	return join.isNotNull();
}
 
Example 16
Source File: HasPendingReviewsCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
	Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
	Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
	join.on(builder.and(
			builder.isNotNull(userPath), 
			builder.isNull(approvedPath)));
	return join.isNotNull();
}
 
Example 17
Source File: RequestedForChangesByCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_REVIEWS, JoinType.LEFT);
	Path<?> userPath = EntityQuery.getPath(join, PullRequestReview.PROP_USER);
	Path<?> approvedPath = EntityQuery.getPath(join, PullRequestReview.PROP_RESULT + "." + ReviewResult.PROP_APPROVED);
	join.on(builder.and(
			builder.equal(userPath, user), 
			builder.equal(approvedPath, false)));
	return join.isNotNull();
}
 
Example 18
Source File: DependenciesOfCriteria.java    From onedev with MIT License 4 votes vote down vote up
@Override
public Predicate getPredicate(Root<Build> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(Build.PROP_DEPENDENTS, JoinType.LEFT);
	join.on(builder.equal(join.get(BuildDependence.PROP_DEPENDENT), build));
	return join.isNotNull();
}
 
Example 19
Source File: RequiredByPullRequestsCriteria.java    From onedev with MIT License 4 votes vote down vote up
@Override
public Predicate getPredicate(Root<Build> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(Build.PROP_VERIFICATIONS, JoinType.LEFT);
	join.on(builder.equal(join.get(PullRequestVerification.PROP_REQUIRED), true)); 
	return join.isNotNull();
}
 
Example 20
Source File: DependsOnCriteria.java    From onedev with MIT License 4 votes vote down vote up
@Override
public Predicate getPredicate(Root<Build> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(Build.PROP_DEPENDENCIES, JoinType.LEFT);
	join.on(builder.equal(join.get(BuildDependence.PROP_DEPENDENCY), build));
	return join.isNotNull();
}