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 ); }
@Override public void appendJoin(boolean firstFromElement, StringBuilder builder, Map<String, Object> queryParamValues) { if (firstFromElement) { throw new IllegalArgumentException( "An inner/outer join cannot come as first 'from element'" ); } builder.append( ' ' ).append( joinType.name() .toLowerCase( Locale.US ) ).append( " join " ) .append( entityName ).append( ' ' ) .append( getAlias() ).append( " on " ); joinConditionParameters.build( builder, queryParamValues ); }
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"); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((joinType == null) ? 0 : joinType.hashCode()); result = prime * result + ((pathsToFetch == null) ? 0 : pathsToFetch.hashCode()); return result; }
@Override public String toString() { return joinType.toString() + " " + path() + " " + comparator.toString() + " " + value.toString(); }
public void addToCriteria(DetachedCriteria criteria) { if (joinType == null) { criteria.createAlias(associationPath, alias); } else if (withClause == null) { criteria.createAlias(associationPath, alias, joinType.ordinal()); } else { criteria.createAlias(associationPath, alias, joinType.ordinal(), withClause); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((alias == null) ? 0 : alias.hashCode()); result = prime * result + (distinctQuery ? 1231 : 1237); result = prime * result + ((joinType == null) ? 0 : joinType.hashCode()); result = prime * result + ((pathToJoinOn == null) ? 0 : pathToJoinOn.hashCode()); result = prime * result + ((queryContext == null) ? 0 : queryContext.hashCode()); return result; }
private <Y> SetJoinImplementor<X, Y> constructJoin(SetAttribute<? super X, Y> set, 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 = set.getBindableJavaType(); return new SetAttributeJoin<X, Y>( criteriaBuilder(), attributeType, this, set, jt ); }
@Override public void appendJoin(boolean firstFromElement, StringBuilder builder, Map<String, Object> queryParamValues) { if (firstFromElement) { throw new IllegalArgumentException( "An inner/outer join cannot come as first 'from element'" ); } builder.append( ' ' ).append( joinType.name() .toLowerCase( Locale.US ) ).append( " join " ) .append( entityName ).append( ' ' ) .append( getAlias() ).append( " on " ); joinConditionParameters.build( builder, queryParamValues ); }
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 ); }
private void join(Root<Object> root, List<String> joinFetchTables, JoinType type) { if (joinFetchTables != null && (joinFetchTables.size() > 0)) { logger.debug("{} join root {} with table {}", type.name(), root.getJavaType(), joinFetchTables); for (String table : joinFetchTables) { if (table != null) root.fetch(table, type); } } }
private <Y> CollectionJoinImplementor<X, Y> constructJoin( CollectionAttribute<? super X, Y> collection, 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 = collection.getBindableJavaType(); return new CollectionAttributeJoin<X, Y>( criteriaBuilder(), attributeType, this, collection, jt ); }
@Override public String toString() { return this.getParent().toString() + ' ' + this.joinType.name().toLowerCase() + " join(mode = " + this.joinMode.name().toLowerCase() + ") " + this.attribute.getName(); }
/** * Return whether the given {@link From} contains a fetch declaration for the attribute with the given name. * * @param from the {@link From} to check for fetches. * @param attribute the attribute name to check. * @return */ private static boolean isAlreadyFetched(From<?, ?> from, String attribute) { for (Fetch<?, ?> fetch : from.getFetches()) { boolean sameName = fetch.getAttribute().getName().equals(attribute); if (sameName && fetch.getJoinType().equals(JoinType.LEFT)) { return true; } } return false; }
} else { output .append(this.joinType.name().toLowerCase()) .append(" join "); if (this.fetch) {
/** * Returns an existing join for the given attribute if one already exists or creates a new one if not. * * @param from the {@link From} to get the current joins from. * @param attribute the {@link Attribute} to look for in the current joins. * @return will never be {@literal null}. */ private static Join<?, ?> getOrCreateJoin(From<?, ?> from, String attribute) { for (Join<?, ?> join : from.getJoins()) { boolean sameName = join.getAttribute().getName().equals(attribute); if (sameName && join.getJoinType().equals(JoinType.LEFT)) { return join; } } return from.join(attribute, JoinType.LEFT); }
jpqlBuilder .append(' ') .append(entity.getJoinType().name().toLowerCase()) .append(" join "); if (entity.isFetch()) {
private <T> void useDistinctWhenLefOuterJoinsPresent(CriteriaQuery<T> criteriaQuery) { boolean useDistinct = false; Root<TaskImpl> taskRoot = null; ROOTS_FOR: for( Root root : criteriaQuery.getRoots() ) { if( TaskImpl.class.equals(root.getJavaType()) ) { taskRoot = (Root<TaskImpl>) root; for( Join<TaskImpl, ?> taskJoin : taskRoot.getJoins() ) { if( PeopleAssignmentsImpl.class.equals(taskJoin.getJavaType()) ) { Join<TaskImpl, PeopleAssignmentsImpl> peopleAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) taskJoin; if( JoinType.LEFT.equals(peopleAssignJoin.getJoinType()) ) { useDistinct = true; break ROOTS_FOR; } for( Join peopleAssignJoinJoin : peopleAssignJoin.getJoins() ) { if( JoinType.LEFT.equals(peopleAssignJoinJoin.getJoinType()) ) { useDistinct = true; break ROOTS_FOR; } } } } } } if( useDistinct ) { criteriaQuery.distinct(true); } }
private <Y> JoinImplementor<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, JoinType jt) { if ( Type.PersistenceType.BASIC.equals( attribute.getType().getPersistenceType() ) ) { throw new BasicPathUsageException( "Cannot join to attribute of basic type", attribute ); } // TODO : runtime check that the attribute in fact belongs to this From's model/bindable if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } final Class<Y> attributeType = attribute.getBindableJavaType(); return new SingularAttributeJoin<X, Y>( criteriaBuilder(), attributeType, this, attribute, jt ); }