toAttrJoinType = parentJoinAttr.getJavaType(); } else if( parentJoinAttr instanceof PluralAttribute ) { toAttrJoinType = ((PluralAttribute) parentJoinAttr).getElementType().getJavaType(); } else { String joinName = parentJoinAttr.getDeclaringType().getJavaType().getSimpleName() + "." + parentJoinAttr.getName(); throw new IllegalStateException("Unknown attribute type encountered when trying to join " + joinName );
@Override @SuppressWarnings({"unchecked"}) public <X, Y> CollectionJoin<X, Y> joinCollection(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a collection" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.COLLECTION.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a collection" ); } return (CollectionJoin<X, Y>) join( (CollectionAttribute) attribute, jt ); }
private String [] createOriginalAndExpectedKeys(Attribute embeddedAttr, PluralAttribute listAttr) { String originalKey = embeddedAttr.getDeclaringType().getJavaType().getName() + "." + embeddedAttr.getName() + "." + listAttr.getName(); String copyKey = listAttr.getDeclaringType().getJavaType().getName() + "." + listAttr.getName(); String [] keys = { originalKey, copyKey }; return keys; }
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" ); } }
private String resolveRole(PluralAttribute attribute) { switch ( attribute.getDeclaringType().getPersistenceType() ) { case ENTITY: { return attribute.getDeclaringType().getJavaType().getName() + '.' + attribute.getName(); (MappedSuperclassType) attribute.getDeclaringType(), (EntityType) getPathSource().getModel() ); return entityTypeNearestDeclaringType.getJavaType().getName() + '.' + attribute.getName(); StringBuilder role = new StringBuilder().append( '.' ).append( attribute.getName() ); PathSource parentPath = getPathSource(); SingularAttribute singularAttribute; String.format( "Unexpected PersistenceType: [%s]", attribute.getDeclaringType().getPersistenceType()
if (!attribute.getName().equals(m.getIdAttribute().getName()) && !attribute.isAssociation()) Field field = (Field) ((Attribute) attribute).getJavaMember(); byte[] name = ByteBufferUtil.bytes(((AbstractAttribute) attribute).getJPAColumnName()).array(); if (metaModel.isEmbeddable(attribute.isCollection() ? ((PluralAttribute) attribute) .getBindableJavaType() : attribute.getJavaType()))
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); }
private static <E> Class<?> getJavaType(Attribute<? super E, ?> attribute) { return (attribute instanceof PluralAttribute) ? ((PluralAttribute<?, ?, ?>) attribute).getElementType().getJavaType() : attribute.getJavaType(); }
@Override public boolean isCompositeNode(Attribute<?, ?> attr) { if (attr.isCollection()) { PluralAttribute<?, ?, ?> pluralAttribute = (PluralAttribute<?, ?, ?>) attr; if (pluralAttribute.getElementType().getPersistenceType() == Type.PersistenceType.BASIC) { return false; } return true; } return attr.getPersistentAttributeType() == Attribute.PersistentAttributeType.MANY_TO_ONE || attr.getPersistentAttributeType() == Attribute.PersistentAttributeType.ONE_TO_ONE; }
public <T, Y> Join<T, Y> join(String attributeName, JoinType jt) { Attribute attribute = this.managedType.getAttribute(attributeName); if (attribute.isCollection()) { org.eclipse.persistence.expressions.Expression node; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(((PluralAttribute) attribute).getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(((PluralAttribute) attribute).getName()); 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); if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) { 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);
public void verifyPath(List<Attribute<?, ?>> path) { List<Attribute<?, ?>> attributes = newArrayList(path); Class<?> from = null; if (attributes.get(0).isCollection()) { from = ((PluralAttribute) attributes.get(0)).getElementType().getJavaType(); } else { from = attributes.get(0).getJavaType(); } attributes.remove(0); for (Attribute<?, ?> attribute : attributes) { if (!attribute.getDeclaringType().getJavaType().isAssignableFrom(from)) { throw new IllegalStateException("Wrong path."); } from = attribute.getJavaType(); } }
Attribute attribute = this.managedType.getAttribute(attName); Join join; if (attribute.isCollection()) { 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); if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) { 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); if (((SingularAttribute)attribute).getType().getPersistenceType().equals(PersistenceType.BASIC)){ return new PathImpl<Y>(this, this.metamodel, clazz, this.currentNode.get(attribute.getName()), (Bindable)attribute); }else{
public boolean selects(Attribute<? super X, ?> attr) { boolean result = (attr instanceof PluralAttribute<?, ?, ?>) && (_elementType == null || ((PluralAttribute<?, ?, ?>) attr).getElementType().getJavaType() == _elementType); return _invert ? !result : result; }
DataFetcher dataFetcher = PropertyDataFetcher.fetching(attribute.getName()); && attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.BASIC) { arguments.add(GraphQLArgument.newArgument() .name(ORDER_BY_PARAM_NAME) && attribute.getPersistentAttributeType() != Attribute.PersistentAttributeType.BASIC) { ManagedType foreignType = (ManagedType) ((SingularAttribute) attribute).getType(); && (attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.ONE_TO_MANY || attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.MANY_TO_MANY)) { EntityType declaringType = (EntityType) ((PluralAttribute) attribute).getDeclaringType(); EntityType elementType = (EntityType) ((PluralAttribute) attribute).getElementType();
throw new RuntimeException("Attribute [" + property + "] not found on class " + startType.getJavaType().getName()); final PluralAttribute.CollectionType collectionType = targetAttribute.getCollectionType(); final boolean isElementCollection = jpaProvider.getJpaMetamodelAccessor().isElementCollection(targetAttribute); if (managedTargetType instanceof EntityType<?>) { subqueryRequired = ((EntityType<?>) managedTargetType).getIdType().getPersistenceType() == PersistenceType.EMBEDDABLE; } else { throw new RuntimeException("Path [" + sizeArg.toString() + "] does not refer to a collection"); jpaProvider.isBag((EntityType<?>) targetAttribute.getDeclaringType(), targetAttribute.getName()) || requiresBlacklistedNode(sizeArg) || aggregateFunctionContext; if (IDENTIFIABLE_PERSISTENCE_TYPES.contains(targetAttribute.getElementType().getPersistenceType()) && targetAttribute.isCollection()) { for (Attribute<?, ?> idAttribute : JpaMetamodelUtils.getIdAttributes(((IdentifiableType<?>) sizeArgTargetAttribute.getElementType()))) { List<PathElementExpression> pathElementExpressions = new ArrayList<>(sizeArg.getExpressions().size() + 1); pathElementExpressions.addAll(sizeArg.getExpressions()); pathElementExpressions.add(new PropertyExpression(idAttribute.getName())); PathExpression pathExpression = new PathExpression(pathElementExpressions); countArguments.add(pathExpression);
Class<?> collectionElementClass = cd.getElementType().getJavaType(); EntityType<?> elementEntityType = entityManager.getMetamodel().entity(collectionElementClass); collection.setName(cd.getName()); collection.setRelatedType(collectionElementClass); populateImplementationSpecificCollectionLevelMetadata(collection, cd); PersistentAttributeType persistentAttributeType = cd.getPersistentAttributeType(); List<String> pkFields = getPrimaryKeyAttributeNames((EntityType<?>) cd.getDeclaringType()); List<String> fkFields = getPrimaryKeyAttributeNames(elementEntityType); List<DataObjectAttributeRelationship> attributeRelationships = new ArrayList<DataObjectAttributeRelationship>();
/** * Assert on owner type attributes. * * @param managedType * the managed type * @param fieldName * the field name * @param fieldClazz * the field clazz * @param javaClazz * the java clazz */ private void assertOnOwnerTypeAttributes(AbstractManagedType managedType, String fieldName, Class fieldClazz, Class javaClazz) { Assert.assertNotNull(managedType); Assert.assertNotNull(managedType.getPluralAttributes()); Assert.assertEquals(4, managedType.getPluralAttributes().size()); Assert.assertNotNull(managedType.getAttribute(fieldName)); Assert.assertEquals(javaClazz, managedType.getAttribute(fieldName).getJavaType()); Assert.assertEquals(fieldClazz, ((PluralAttribute) managedType.getAttribute(fieldName)).getElementType() .getJavaType()); Assert.assertEquals(BindableType.PLURAL_ATTRIBUTE, ((PluralAttribute) managedType.getAttribute(fieldName)).getBindableType()); Assert.assertNotNull(((PluralAttribute) managedType.getAttribute(fieldName)).getJavaMember()); Assert.assertNotNull(fieldName, ((PluralAttribute) managedType.getAttribute(fieldName)).getJavaMember() .getName()); }
if(anAttribute.isCollection()) { if(((PluralAttribute)anAttribute).getCollectionType().equals(aReturnCollectionType)) { Class aBindableJavaClass = ((PluralAttribute)anAttribute).getBindableJavaType(); if(attributeElementType != aBindableJavaClass) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage( "metamodel_managed_type_attribute_type_incorrect", new Object[] { anAttribute.getName(), this, attributeElementType, aBindableJavaClass })); new Object[] { anAttribute.getName(), this, aReturnCollectionType, ((PluralAttribute)anAttribute).getCollectionType()}));
public boolean isBasicCollection() { return Type.PersistenceType.BASIC.equals( getAttribute().getElementType().getPersistenceType() ); }
public JPACollectionType(PluralAttribute<?,?,?> collection, SecureEntity secureEntity) { super(collection.getName(), collection.getJavaType(), collection.getElementType().getJavaType(), secureEntity); String relName = StringUtilities.singularize(collection.getName()); this.idsFieldDefinition = new FieldDefinition( relName + AdaptrexEntityType.COLLECTION_IDS_NAME, ExtTypeFormatter.AUTO ); String capName = StringUtilities.capitalize(getName()); Class<?> declaringClass = collection.getDeclaringType().getJavaType(); try { getter = declaringClass.getMethod("get" + capName); } catch (Exception e) {} if (getter == null) return; try { setter = declaringClass.getMethod("set" + capName, getter.getReturnType()); } catch (Exception e) {} }