Search in sources :

Example 1 with PluralAttribute

use of jakarta.persistence.metamodel.PluralAttribute in project hibernate-orm by hibernate.

the class AbstractManagedType method getDeclaredSet.

@Override
@SuppressWarnings("unchecked")
public <E> SetAttribute<J, E> getDeclaredSet(String name, Class<E> elementType) {
    final PluralAttribute attribute = findDeclaredPluralAttribute(name);
    checkSetElementType(attribute, name, elementType);
    return (SetAttribute<J, E>) attribute;
}
Also used : PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) SetAttribute(jakarta.persistence.metamodel.SetAttribute)

Example 2 with PluralAttribute

use of jakarta.persistence.metamodel.PluralAttribute in project hibernate-orm by hibernate.

the class AbstractManagedType method getDeclaredList.

@Override
@SuppressWarnings("unchecked")
public <E> ListAttribute<J, E> getDeclaredList(String name, Class<E> elementType) {
    final PluralAttribute attribute = findDeclaredPluralAttribute(name);
    checkListElementType(attribute, name, elementType);
    return (ListAttribute<J, E>) attribute;
}
Also used : PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) ListAttribute(jakarta.persistence.metamodel.ListAttribute)

Example 3 with PluralAttribute

use of jakarta.persistence.metamodel.PluralAttribute in project eclipselink by eclipse-ee4j.

the class FromImpl method join.

@Override
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(attribute.getName());
        } else if (jt.equals(JoinType.RIGHT)) {
            throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED"));
        } else {
            node = this.currentNode.anyOfAllowingNone(attribute.getName());
        }
        Join join;
        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);
            }
        } else {
            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);
            }
        }
        this.joins.add(join);
        ((FromImpl) join).isJoin = true;
        return join;
    } else {
        return join(((SingularAttribute) attribute), jt);
    }
}
Also used : CollectionAttribute(jakarta.persistence.metamodel.CollectionAttribute) PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) Attribute(jakarta.persistence.metamodel.Attribute) MapAttribute(jakarta.persistence.metamodel.MapAttribute) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) ListAttribute(jakarta.persistence.metamodel.ListAttribute) PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) Bindable(jakarta.persistence.metamodel.Bindable) CollectionJoin(jakarta.persistence.criteria.CollectionJoin) ListJoin(jakarta.persistence.criteria.ListJoin) SetJoin(jakarta.persistence.criteria.SetJoin) MapJoin(jakarta.persistence.criteria.MapJoin) Join(jakarta.persistence.criteria.Join) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute)

Example 4 with PluralAttribute

use of jakarta.persistence.metamodel.PluralAttribute in project eclipselink by eclipse-ee4j.

the class FromImpl method get.

@Override
public <Y> Path<Y> get(String attName) {
    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);
            }
        } else {
            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);
            }
        }
    } else {
        Class<Y> clazz = ((SingularAttribute) attribute).getBindableJavaType();
        if (((SingularAttribute) attribute).getType().getPersistenceType().equals(PersistenceType.BASIC)) {
            return new PathImpl<Y>(this, this.metamodel, clazz, this.currentNode.get(attribute.getName()), (Bindable) attribute);
        } else {
            join = new JoinImpl(this, this.metamodel.managedType(clazz), this.metamodel, clazz, this.currentNode.get(attribute.getName()), (Bindable) attribute);
        }
    }
    this.joins.add(join);
    return join;
}
Also used : CollectionAttribute(jakarta.persistence.metamodel.CollectionAttribute) PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) Attribute(jakarta.persistence.metamodel.Attribute) MapAttribute(jakarta.persistence.metamodel.MapAttribute) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) ListAttribute(jakarta.persistence.metamodel.ListAttribute) PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) Bindable(jakarta.persistence.metamodel.Bindable) CollectionJoin(jakarta.persistence.criteria.CollectionJoin) ListJoin(jakarta.persistence.criteria.ListJoin) SetJoin(jakarta.persistence.criteria.SetJoin) MapJoin(jakarta.persistence.criteria.MapJoin) Join(jakarta.persistence.criteria.Join) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute)

Example 5 with PluralAttribute

use of jakarta.persistence.metamodel.PluralAttribute in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testManagedType_getDeclaredPluralAttributes_root_entity_Method.

public void testManagedType_getDeclaredPluralAttributes_root_entity_Method() {
    EntityManager em = null;
    boolean expectedIAExceptionThrown = false;
    try {
        em = privateTestSetup();
        assertNotNull(em);
        Metamodel metamodel = em.getMetamodel();
        assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
        EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl) metamodel.entity(Computer.class);
        assertNotNull(entityComputer_);
        // This also tests getCollections()
        expectedIAExceptionThrown = false;
        Set<PluralAttribute<Computer, ?, ?>> collections = entityComputer_.getDeclaredPluralAttributes();
        assertNotNull(collections);
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        expectedIAExceptionThrown = true;
    } finally {
        cleanup(em);
        assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) Computer(org.eclipse.persistence.testing.models.jpa.metamodel.Computer) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) Metamodel(jakarta.persistence.metamodel.Metamodel)

Aggregations

PluralAttribute (jakarta.persistence.metamodel.PluralAttribute)22 EntityManager (jakarta.persistence.EntityManager)15 Metamodel (jakarta.persistence.metamodel.Metamodel)15 CollectionAttribute (jakarta.persistence.metamodel.CollectionAttribute)14 ListAttribute (jakarta.persistence.metamodel.ListAttribute)14 EntityTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl)14 Attribute (jakarta.persistence.metamodel.Attribute)13 MapAttribute (jakarta.persistence.metamodel.MapAttribute)13 SingularAttribute (jakarta.persistence.metamodel.SingularAttribute)13 Bindable (jakarta.persistence.metamodel.Bindable)12 SetAttribute (jakarta.persistence.metamodel.SetAttribute)12 Manufacturer (org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer)12 HardwareDesigner (org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner)5 Computer (org.eclipse.persistence.testing.models.jpa.metamodel.Computer)4 MappedSuperclassTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl)3 Corporation (org.eclipse.persistence.testing.models.jpa.metamodel.Corporation)3 Person (org.eclipse.persistence.testing.models.jpa.metamodel.Person)3 CollectionJoin (jakarta.persistence.criteria.CollectionJoin)2 Join (jakarta.persistence.criteria.Join)2 ListJoin (jakarta.persistence.criteria.ListJoin)2