javax.persistence.criteria.JoinType Java Examples
The following examples show how to use
javax.persistence.criteria.JoinType.
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: HibernateCategoryOptionComboStore.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 8 votes |
@Override public List<CategoryOptionCombo> getCategoryOptionCombosByGroupUid( String groupUid ) { CriteriaBuilder builder = getCriteriaBuilder(); CriteriaQuery<CategoryOptionCombo> query = builder.createQuery( CategoryOptionCombo.class ); Root<CategoryOptionCombo> root = query.from( CategoryOptionCombo.class ); Join<Object, Object> joinCatOption = root.join( "categoryOptions", JoinType.INNER ); Join<Object, Object> joinCatOptionGroup = joinCatOption.join( "groups", JoinType.INNER ); query.where( builder.equal( joinCatOptionGroup.get( "uid" ), groupUid ) ); return getSession().createQuery( query ).list(); }
Example #2
Source File: MinionServerFactory.java From uyuni with GNU General Public License v2.0 | 7 votes |
/** * Find empty profiles with a HW address matching some of given HW addresses. * * @param hwAddrs the set of HW addresses * @return the List of MinionServer with a HW address matching some of given HW addresses */ public static List<MinionServer> findEmptyProfilesByHwAddrs(Set<String> hwAddrs) { if (hwAddrs.isEmpty()) { return emptyList(); } CriteriaBuilder builder = getSession().getCriteriaBuilder(); CriteriaQuery<MinionServer> query = builder.createQuery(MinionServer.class); Root<MinionServer> root = query.distinct(true).from(MinionServer.class); Join<MinionServer, NetworkInterface> nicJoin = root.join("networkInterfaces", JoinType.INNER); Predicate hwAddrPredicate = nicJoin.get("hwaddr").in(hwAddrs); query.where(hwAddrPredicate); return getSession().createQuery(query).stream() .filter(s -> s.hasEntitlement(EntitlementManager.BOOTSTRAP)) .collect(toList()); }
Example #3
Source File: JoinFetchTest.java From specification-arg-resolver with Apache License 2.0 | 6 votes |
@Test public void performsTwoFetches() { JoinFetch<Customer> spec1 = new JoinFetch<Customer>(new String[] { "orders" }, JoinType.LEFT); JoinFetch<Customer> spec2 = new JoinFetch<Customer>(new String[] { "orders2" }, JoinType.INNER); Conjunction<Customer> spec = new Conjunction<Customer>(spec1, spec2); List<Customer> customers = customerRepo.findAll(spec); assertThat(customers).isNotEmpty(); for (Customer customer : customers) { assertTrue(Hibernate.isInitialized(customer.getOrders())); assertTrue(Hibernate.isInitialized(customer.getOrders2())); } }
Example #4
Source File: BasicQueryTestBase.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test public void testOneRelatedEntityOrder() { // per default will do left join assertEquals(5, builder() .addSortBy(Arrays.asList(TestEntity.ATTR_oneRelatedValue), Direction.DESC).buildExecutor().getResultList() .size()); assertEquals((Long) 0L, builder().setJoinType(Arrays.asList(TestEntity.ATTR_oneRelatedValue), JoinType.INNER) .addSortBy(Arrays.asList(TestEntity.ATTR_oneRelatedValue), Direction.ASC).buildExecutor() .getResultList() .get(0).getId()); assertEquals((Long) 3L, builder() .setJoinType(Arrays.asList(TestEntity.ATTR_oneRelatedValue), JoinType.INNER) .addSortBy(Arrays.asList(TestEntity.ATTR_oneRelatedValue), Direction.DESC).buildExecutor() .getResultList().get(0).getId()); }
Example #5
Source File: QuerydslQueryBackend.java From crnk-framework with Apache License 2.0 | 6 votes |
@Override public Expression<?> doJoin(MetaAttribute targetAttr, JoinType joinType, Expression<?> parent) { if (targetAttr instanceof MetaComputedAttribute) { MetaComputedAttribute computedAttr = (MetaComputedAttribute) targetAttr; QuerydslExpressionFactory expressionFactory = (QuerydslExpressionFactory<?>) queryImpl.getComputedAttrs() .get(computedAttr); return expressionFactory.getExpression(parent, getQuery()); } else { Expression<Object> expression = QuerydslUtils.get(parent, targetAttr.getName()); querydslQuery.getMetadata().addJoin(QuerydslUtils.convertJoinType(joinType), expression); return expression; } }
Example #6
Source File: RequiredByPullRequestCriteria.java From onedev with MIT License | 6 votes |
@Override public Predicate getPredicate(Root<Build> root, CriteriaBuilder builder) { Join<?, ?> join = root.join(Build.PROP_VERIFICATIONS, JoinType.LEFT); join.on(builder.and( builder.equal(join.get(PullRequestVerification.PROP_REQUEST), request), builder.equal(join.get(PullRequestVerification.PROP_REQUIRED), true))); return builder.equal(root.get(Build.PROP_PROJECT), request.getTargetProject()); }
Example #7
Source File: QuerydslQueryBackend.java From katharsis-framework with Apache License 2.0 | 6 votes |
@Override public Expression<?> doJoin(MetaAttribute targetAttr, JoinType joinType, Expression<?> parent) { if (targetAttr instanceof MetaComputedAttribute) { MetaComputedAttribute computedAttr = (MetaComputedAttribute) targetAttr; QuerydslExpressionFactory expressionFactory = (QuerydslExpressionFactory<?>) queryImpl.getComputedAttrs() .get(computedAttr); return expressionFactory.getExpression(parent, getQuery()); } else { Expression<Object> expression = QuerydslUtils.get(parent, targetAttr.getName()); querydslQuery.getMetadata().addJoin(QuerydslUtils.convertJoinType(joinType), expression); return expression; } }
Example #8
Source File: RSQLUtility.java From hawkbit with Eclipse Public License 1.0 | 6 votes |
private Path<?> getJoinFieldPath(final Path<?> fieldPath, final String fieldNameSplit) { if (fieldPath instanceof PluralJoin) { final Join<Object, ?> join = (Join<Object, ?>) fieldPath; final From<?, Object> joinParent = join.getParent(); final Optional<Join<Object, Object>> currentJoinOfType = findCurrentJoinOfType(join.getJavaType()); if (currentJoinOfType.isPresent() && isOrLevel) { // remove the additional join and use the existing one joinParent.getJoins().remove(join); return currentJoinOfType.get(); } else { final Join<Object, Object> newJoin = joinParent.join(fieldNameSplit, JoinType.LEFT); addCurrentJoin(newJoin); return newJoin; } } return fieldPath; }
Example #9
Source File: BranchStatisticSpecification.java From mojito with Apache License 2.0 | 6 votes |
public static SingleParamSpecification<BranchStatistic> createdByUserNameEquals(final String createdByUserName) { return new SingleParamSpecification<BranchStatistic>(createdByUserName) { @Override public Predicate toPredicate(Root<BranchStatistic> root, CriteriaQuery<?> query, CriteriaBuilder builder) { Join<BranchStatistic, Branch> branchJoin = root.join(BranchStatistic_.branch, JoinType.LEFT); Join<Branch, User> userJoin = branchJoin.join(Branch_.createdByUser, JoinType.LEFT); return builder.equal(userJoin.get(User_.username), createdByUserName); } }; }
Example #10
Source File: SpecificationArgumentResolverTest.java From specification-arg-resolver with Apache License 2.0 | 6 votes |
@Test public void resolvesJoinContainerWithJoinFetch() throws Exception { MethodParameter param = MethodParameter.forExecutable(testMethod("testMethod_joinContainerWithJoinFetch"), 0); NativeWebRequest req = mock(NativeWebRequest.class); QueryContext queryCtx = new WebRequestQueryContext(req); when(req.getParameterValues("path1")).thenReturn(new String[] { "value1" }); Specification<?> resolved = (Specification<?>) resolver.resolveArgument(param, null, req, null); assertThat(innerSpecs(resolved)) .hasSize(2) .contains(new Like<Object>(queryCtx, "path1", new String[] { "value1" })) .contains(new Conjunction<Object>( new net.kaczmarzyk.spring.data.jpa.domain.JoinFetch<Object>(new String[] { "fetch1" }, JoinType.LEFT), new net.kaczmarzyk.spring.data.jpa.domain.JoinFetch<Object>(new String[] { "fetch2" }, JoinType.INNER))); }
Example #11
Source File: TargetSpecifications.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * {@link Specification} for retrieving {@link Target}s by "like attribute * value". * * @param searchText * to be filtered on * @return the {@link Target} {@link Specification} */ public static Specification<JpaTarget> likeAttributeValue(final String searchText) { return (targetRoot, query, cb) -> { final String searchTextToLower = searchText.toLowerCase(); final MapJoin<JpaTarget, String, String> attributeMap = targetRoot.join(JpaTarget_.controllerAttributes, JoinType.LEFT); query.distinct(true); return cb.like(cb.lower(attributeMap.value()), searchTextToLower); }; }
Example #12
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked"}) public <X, Y> ListJoin<X, Y> joinList(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a list" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.LIST.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a list" ); } return (ListJoin<X, Y>) join( (ListAttribute) attribute, jt ); }
Example #13
Source File: ApplicationResource.java From bouncr with Eclipse Public License 1.0 | 5 votes |
@Decision(EXISTS) public boolean exists(Parameters params, RestContext context, EntityManager em) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Application> query = cb.createQuery(Application.class); Root<Application> applicationRoot = query.from(Application.class); query.where(cb.equal(applicationRoot.get("name"), params.get("name"))); List<ResourceField> embedEntities = some(params.get("embed"), embed -> new ResourceFilter().parse(embed)) .orElse(Collections.emptyList()); EntityGraph<Application> applicationGraph = em.createEntityGraph(Application.class); applicationGraph.addAttributeNodes("name", "description", "virtualPath", "passTo", "topPage"); if (embedEntities.stream().anyMatch(r -> r.getName().equalsIgnoreCase("realms"))) { applicationRoot.fetch("realms", JoinType.LEFT); query.distinct(true); applicationGraph.addSubgraph("realms") .addAttributeNodes("name", "description", "url"); } Application application = em.createQuery(query) .setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH) .setHint("javax.persistence.fetchgraph", applicationGraph) .getResultStream().findAny().orElse(null); if (application != null) { context.putValue(application); } return application != null; }
Example #14
Source File: CollectionAttributeJoin.java From lams with GNU General Public License v2.0 | 5 votes |
public CollectionAttributeJoin( CriteriaBuilderImpl criteriaBuilder, Class<E> javaType, PathSource<O> pathSource, CollectionAttribute<? super O, E> joinAttribute, JoinType joinType) { super( criteriaBuilder, javaType, pathSource, joinAttribute, joinType ); }
Example #15
Source File: MapAttributeJoin.java From lams with GNU General Public License v2.0 | 5 votes |
public MapAttributeJoin( CriteriaBuilderImpl criteriaBuilder, Class<V> javaType, PathSource<O> pathSource, MapAttribute<? super O, K, V> joinAttribute, JoinType joinType) { super( criteriaBuilder, javaType, pathSource, joinAttribute, joinType ); }
Example #16
Source File: QueryFilterBuilder.java From crnk-framework with Apache License 2.0 | 5 votes |
public List<P> filterSpecListToPredicateArray(MetaDataObject rootMeta, F root, List<FilterSpec> rowFilters, JoinType defaultPredicateJoinType) { ArrayList<P> predicateList = new ArrayList<>(); for (FilterSpec rowFilter : rowFilters) { predicateList.add(filterSpecListToPredicate(rootMeta, root, rowFilter, defaultPredicateJoinType)); } return predicateList; }
Example #17
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private <Y> ListJoinImplementor<X, Y> constructJoin(ListAttribute<? super X, Y> list, JoinType jt) { if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } // TODO : runtime check that the attribute in fact belongs to this From's model/bindable final Class<Y> attributeType = list.getBindableJavaType(); return new ListAttributeJoin<X, Y>( criteriaBuilder(), attributeType, this, list, jt ); }
Example #18
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private <K, V> MapJoinImplementor<X, K, V> constructJoin(MapAttribute<? super X, K, V> map, JoinType jt) { if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } // TODO : runtime check that the attribute in fact belongs to this From's model/bindable final Class<V> attributeType = map.getBindableJavaType(); return new MapAttributeJoin<X, K, V>( criteriaBuilder(), attributeType, this, map, jt ); }
Example #19
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked"}) public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a map" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.MAP.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a map" ); } return (MapJoin<X, K, V>) join( (MapAttribute) attribute, jt ); }
Example #20
Source File: TargetSpecifications.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * {@link Specification} for retrieving {@link Target}s that are not in the * given {@link RolloutGroup}s * * @param groups * the {@link RolloutGroup}s * @return the {@link Target} {@link Specification} */ public static Specification<JpaTarget> isNotInRolloutGroups(final Collection<Long> groups) { return (targetRoot, query, cb) -> { final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot .join(JpaTarget_.rolloutTargetGroup, JoinType.LEFT); final Predicate inRolloutGroups = rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup) .get(JpaRolloutGroup_.id).in(groups); rolloutTargetJoin.on(inRolloutGroups); return cb.isNull(rolloutTargetJoin.get(RolloutTargetGroup_.target)); }; }
Example #21
Source File: ParamCriteria.java From onedev with MIT License | 5 votes |
@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 #22
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked"}) public <X, Y> Fetch<X, Y> fetch(String attributeName, JoinType jt) { if ( !canBeFetchSource() ) { throw illegalFetch(); } Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( attribute.isCollection() ) { return (Fetch<X, Y>) fetch( (PluralAttribute) attribute, jt ); } else { return (Fetch<X, Y>) fetch( (SingularAttribute) attribute, jt ); } }
Example #23
Source File: DistributionSetSpecification.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * {@link Specification} for retrieving {@link DistributionSet} with given * {@link DistributionSet#getId()}. * * @param distid * to search * @return the {@link DistributionSet} {@link Specification} */ public static Specification<JpaDistributionSet> byId(final Long distid) { return (targetRoot, query, cb) -> { final Predicate predicate = cb.equal(targetRoot.<Long> get(JpaDistributionSet_.id), distid); targetRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT); targetRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT); query.distinct(true); return predicate; }; }
Example #24
Source File: DistributionSetSpecification.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * {@link Specification} for retrieving {@link DistributionSet} with given * {@link DistributionSet#getId()}s. * * @param distids * to search * @return the {@link DistributionSet} {@link Specification} */ public static Specification<JpaDistributionSet> byIds(final Collection<Long> distids) { return (targetRoot, query, cb) -> { final Predicate predicate = targetRoot.<Long> get(JpaDistributionSet_.id).in(distids); targetRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT); targetRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT); targetRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT); query.distinct(true); return predicate; }; }
Example #25
Source File: QuerydslUtils.java From katharsis-framework with Apache License 2.0 | 5 votes |
public static com.querydsl.core.JoinType convertJoinType(JoinType joinType) { switch (joinType) { case INNER: return com.querydsl.core.JoinType.JOIN; case LEFT: return com.querydsl.core.JoinType.LEFTJOIN; case RIGHT: return com.querydsl.core.JoinType.RIGHTJOIN; default: throw new IllegalStateException(joinType.toString() + " unknown"); } }
Example #26
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked"}) public <X, Y> SetJoin<X, Y> joinSet(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a set" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.SET.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a set" ); } return (SetJoin<X, Y>) join( (SetAttribute) attribute, jt ); }
Example #27
Source File: JpaCriteriaQueryBackend.java From katharsis-framework with Apache License 2.0 | 5 votes |
@Override public Expression<?> joinMapValue(Expression<?> currentCriteriaPath, MetaAttribute pathElement, Object key) { MapJoin<Object, Object, Object> mapJoin = ((From<?, ?>) currentCriteriaPath).joinMap(pathElement.getName(), JoinType.LEFT); Predicate mapJoinCondition = cb.equal(mapJoin.key(), key); Predicate nullCondition = cb.isNull(mapJoin.key()); addPredicate(cb.or(mapJoinCondition, nullCondition)); return mapJoin; }
Example #28
Source File: CommentCriteria.java From onedev with MIT License | 5 votes |
@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 #29
Source File: JpaRolloutGroupManagement.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
@Override public Page<TargetWithActionStatus> findAllTargetsOfRolloutGroupWithActionStatus(final Pageable pageRequest, final long rolloutGroupId) { throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class); final CriteriaQuery<Long> countQuery = cb.createQuery(Long.class); final Root<RolloutTargetGroup> targetRoot = query.distinct(true).from(RolloutTargetGroup.class); final Join<RolloutTargetGroup, JpaTarget> targetJoin = targetRoot.join(RolloutTargetGroup_.target); final ListJoin<RolloutTargetGroup, JpaAction> actionJoin = targetRoot.join(RolloutTargetGroup_.actions, JoinType.LEFT); final Root<RolloutTargetGroup> countQueryFrom = countQuery.distinct(true).from(RolloutTargetGroup.class); countQueryFrom.join(RolloutTargetGroup_.target); countQueryFrom.join(RolloutTargetGroup_.actions, JoinType.LEFT); countQuery.select(cb.count(countQueryFrom)).where(cb .equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), rolloutGroupId)); final Long totalCount = entityManager.createQuery(countQuery).getSingleResult(); final CriteriaQuery<Object[]> multiselect = query.multiselect(targetJoin, actionJoin.get(JpaAction_.status)) .where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), rolloutGroupId)); final List<TargetWithActionStatus> targetWithActionStatus = entityManager.createQuery(multiselect) .setFirstResult((int) pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList() .stream().map(o -> new TargetWithActionStatus((Target) o[0], (Action.Status) o[1])) .collect(Collectors.toList()); return new PageImpl<>(targetWithActionStatus, pageRequest, totalCount); }
Example #30
Source File: SpecificationArgumentResolverTest.java From specification-arg-resolver with Apache License 2.0 | 5 votes |
public void testMethod_joinContainerWithRegularJoin( @Joins({ @Join(path = "join1", alias = "alias1", type = JoinType.INNER, distinct = true), @Join(path = "join2", alias = "alias2", type = JoinType.LEFT, distinct = false) }) @Spec(path = "path1", spec = Like.class) Specification<Object> spec) { }