private <E> void checkTypeForPluralAttributes( String attributeType, PluralAttribute<?,?,?> attribute, String name, Class<E> elementType, PluralAttribute.CollectionType collectionType) { if ( attribute == null || ( elementType != null && !attribute.getBindableJavaType().equals( elementType ) ) || attribute.getCollectionType() != collectionType ) { throw new IllegalArgumentException( attributeType + " named " + name + ( elementType != null ? " and of element type " + elementType : "" ) + " is not present" ); } }
.getBindableJavaType() : attribute.getJavaType()))
private <E> void checkTypeForPluralAttributes( String attributeType, PluralAttribute<?,?,?> attribute, String name, Class<E> elementType, PluralAttribute.CollectionType collectionType) { if ( attribute == null || ( elementType != null && !attribute.getBindableJavaType().equals( elementType ) ) || attribute.getCollectionType() != collectionType ) { throw new IllegalArgumentException( attributeType + " named " + name + ( elementType != null ? " and of element type " + elementType : "" ) + " is not present" ); } }
/** * Gets name of the attribute type. For collection and map type attribute, the name is * appended with generic type argument names. * @param attr */ public static String getAttributeTypeName(Attribute<?, ?> attr) { StringBuilder name = new StringBuilder(attr.getJavaType().getSimpleName()); switch (attr.getPersistentAttributeType()) { case ONE_TO_MANY: case ELEMENT_COLLECTION: name.append("<") .append(((PluralAttribute<?,?,?>)attr).getBindableJavaType().getSimpleName()) .append(">"); break; case MANY_TO_MANY: name.append("<") .append(((MapAttribute<?,?,?>)attr).getKeyJavaType().getSimpleName()) .append(',') .append(((MapAttribute<?,?,?>)attr).getBindableJavaType().getSimpleName()) .append(">"); break; default: } return name.toString(); }
public <T> Subgraph<T> addKeySubgraph(Attribute<X, T> attribute) { if (!this.isMutable) { throw new IllegalStateException("immutable_entitygraph"); } Class type = attribute.getJavaType(); if (attribute.isCollection()) { type = ((PluralAttribute) attribute).getBindableJavaType(); } return addKeySubgraph(attribute.getName(), type); }
public <T> Subgraph<T> addSubgraph(Attribute<X, T> attribute) { Class type = attribute.getJavaType(); if (attribute.isCollection()) { type = ((PluralAttribute) attribute).getBindableJavaType(); } return addSubgraph(attribute.getName(), type); }
private void encodeManagedType(ManagedType<?> type, Element parent) { Document doc = parent.getOwnerDocument(); Element root = doc.createElement(type.getPersistenceType().toString().toLowerCase()); parent.appendChild(root); root.setAttribute(ATTR_NAME, type.getJavaType().getSimpleName()); List<Attribute<?,?>> attributes = MetamodelHelper.getAttributesInOrder(type); for (Attribute<?,?> a : attributes) { String tag = MetamodelHelper.getTagByAttributeType(a); Element child = doc.createElement(tag); root.appendChild(child); child.setAttribute(ATTR_TYPE, typeOf(a.getJavaType())); if (a instanceof PluralAttribute) { if (a instanceof MapAttribute) { child.setAttribute(ATTR_KEY_TYPE, typeOf(((MapAttribute)a).getKeyJavaType())); child.setAttribute(ATTR_VALUE_TYPE, typeOf(((MapAttribute)a).getBindableJavaType())); } else { child.setAttribute(ATTR_MEMBER_TYPE, typeOf(((PluralAttribute)a).getBindableJavaType())); } } child.setTextContent(a.getName()); } }
fetch = new BasicCollectionJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt); } else if (assoc.getCollectionType().equals(CollectionType.LIST)) { fetch = new BasicListJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt); } else if (assoc.getCollectionType().equals(CollectionType.SET)) { fetch = new BasicSetJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt); } else { fetch = new BasicMapJoinImpl(this, this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt); fetch = new CollectionJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) assoc).getBindableJavaType()), this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt); } else if (assoc.getCollectionType().equals(CollectionType.LIST)) { fetch = new ListJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) assoc).getBindableJavaType()), this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt); } else if (assoc.getCollectionType().equals(CollectionType.SET)) { fetch = new SetJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) assoc).getBindableJavaType()), this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt); } else { fetch = new MapJoinImpl(this, metamodel.managedType(((PluralAttribute) assoc).getBindableJavaType()), this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt);
if (((PluralAttribute) attribute).getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) { join = new BasicCollectionJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) { join = new BasicListJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) { join = new BasicSetJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt); } else{ join = new BasicMapJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt); join = new CollectionJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) { join = new ListJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) { join = new SetJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt); } else { join = new MapJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
/** * Get the property Type out of the metamodel. * * @param property Property name for type extraction. * @param classMetadata Reference class metamodel that holds property type. * @return Class java type for the property, * if the property is a pluralAttribute it will take the bindable java type of that collection. */ private static <T> Class<?> findPropertyType(String property, ManagedType<T> classMetadata) { Class<?> propertyType = null; if (classMetadata.getAttribute(property).isCollection()) { propertyType = ((PluralAttribute)classMetadata.getAttribute(property)).getBindableJavaType(); } else { propertyType = classMetadata.getAttribute(property).getJavaType(); } return propertyType; }
Class aBindableJavaClass = ((PluralAttribute)anAttribute).getBindableJavaType(); if(attributeElementType != aBindableJavaClass) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
if (!((PluralAttribute) attribute).getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) { join = new CollectionJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) { join = new ListJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) { join = new SetJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); } else { join = new MapJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); join = new BasicCollectionJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) { join = new BasicListJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); } else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) { join = new BasicSetJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); } else{ join = new BasicMapJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
.getBindableJavaType() : attribute.getJavaType()))