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 ); }
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 ); }
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 <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 ); }
/** * 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; }
/** * 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); }
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 ); }
if( join.getAttribute().equals(parentJoinAttr) ) { fieldParentJoin = (Join<F, T>) join; if( ! JoinType.INNER.equals(fieldParentJoin.getJoinType()) ) {
@Override @SuppressWarnings({"unchecked"}) public <X, Y> Join<X, Y> join(String attributeName, JoinType jt) { if ( !canBeJoinSource() ) { throw illegalJoin(); } if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( attribute.isCollection() ) { final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( PluralAttribute.CollectionType.COLLECTION.equals( pluralAttribute.getCollectionType() ) ) { return (Join<X, Y>) join( (CollectionAttribute) attribute, jt ); } else if ( PluralAttribute.CollectionType.LIST.equals( pluralAttribute.getCollectionType() ) ) { return (Join<X, Y>) join( (ListAttribute) attribute, jt ); } else if ( PluralAttribute.CollectionType.SET.equals( pluralAttribute.getCollectionType() ) ) { return (Join<X, Y>) join( (SetAttribute) attribute, jt ); } else { return (Join<X, Y>) join( (MapAttribute) attribute, jt ); } } else { return (Join<X, Y>) join( (SingularAttribute) attribute, jt ); } }
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 ); }
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 ); }
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 <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 ); }
/** * 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; }
/** * 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); }
public <Y> Join<X, Y> join(SingularAttribute<? super X, Y> attribute, JoinType jt) { if (((SingularAttribute)attribute).getType().getPersistenceType().equals(PersistenceType.BASIC)){ throw new IllegalStateException(ExceptionLocalization.buildMessage("CAN_NOT_JOIN_TO_BASIC")); } Class clazz = attribute.getBindableJavaType(); Join<X, Y> join = null; ObjectExpression exp = ((ObjectExpression)this.currentNode).newDerivedExpressionNamed(attribute.getName()); if (jt.equals(JoinType.LEFT)){ exp.doUseOuterJoin(); }else if(jt.equals(JoinType.RIGHT)){ throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); }else{ exp.doNotUseOuterJoin(); } join = new JoinImpl<X, Y>(this, this.metamodel.managedType(clazz), this.metamodel, clazz, exp, attribute, jt); this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
public <Y> SetJoin<X, Y> join(javax.persistence.metamodel.SetAttribute<? super X, Y> set, JoinType jt) { org.eclipse.persistence.expressions.Expression node; Class clazz = set.getBindableJavaType(); SetJoin<X, Y> join = null; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(set.getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(set.getName()); } if (set.getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { join = new BasicSetJoinImpl<X, Y>(this, this.metamodel, clazz, node, (Bindable) set, jt); } else { join = new SetJoinImpl<X, Y>(this, metamodel.managedType(clazz), this.metamodel, clazz, node, (Bindable) set, jt); } this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
public <Y> ListJoin<X, Y> join(ListAttribute<? super X, Y> list, JoinType jt) { org.eclipse.persistence.expressions.Expression node; Class clazz = list.getBindableJavaType(); ListJoin<X, Y> join = null; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(list.getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(list.getName()); } if (list.getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { join = new BasicListJoinImpl<X, Y>(this, this.metamodel, clazz, node, (Bindable) list, jt); } else { join = new ListJoinImpl<X, Y>(this, metamodel.managedType(clazz), this.metamodel, clazz, node, (Bindable) list, jt); } this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
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 ); }