/** * Return the Set-valued attribute of the managed type that * corresponds to the specified name and Java element type. * @param name the name of the represented attribute * @param elementType the element type of the represented * attribute * @return SetAttribute of the given name and element type * @throws IllegalArgumentException if attribute of the given * name and type is not present in the managed type */ public <E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType) { SetAttribute<? super X, E> anAttribute = (SetAttribute<? super X, E>)getSet(name); Class<E> aClass = anAttribute.getElementType().getJavaType(); if(elementType != aClass) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage( "metamodel_managed_type_attribute_type_incorrect", new Object[] { name, this, elementType, aClass.getName() })); } return anAttribute; }
/** * This clumsy code is just to get the class of plural attribute mapping * * @param et * @param fieldName * @return */ private Class<?> getPluralJavaType(EntityType<?> et, String fieldName) { for (PluralAttribute<?,?,?> pa : et.getPluralAttributes()) { if (pa.getName().equals(fieldName)) { switch (pa.getCollectionType()) { case COLLECTION: return et.getCollection(fieldName).getElementType().getJavaType(); case LIST: return et.getList(fieldName).getElementType().getJavaType(); case SET: return et.getSet(fieldName).getElementType().getJavaType(); case MAP: throw new UnsupportedOperationException("Entity Map mapping unsupported for entity: " + et.getName() + " field name: " + fieldName); } } } throw new IllegalArgumentException("Field " + fieldName + " of entity " + et.getName() + " is not a plural attribute"); }
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; }