Search in sources :

Example 1 with EntityTypeImpl

use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testAttribute_getAttribute_of_TransientNonEntityNonMappedSuperclass_SuperclassOfEntity_throws_IAE.

// Test that we are getting an Illegal argument exception when trying to access non-persistent fields from transient classes
public void testAttribute_getAttribute_of_TransientNonEntityNonMappedSuperclass_SuperclassOfEntity_throws_IAE() {
    EntityManager em = null;
    boolean exceptionThrown = false;
    try {
        em = privateTestSetup();
        assertNotNull(em);
        Metamodel metamodel = em.getMetamodel();
        assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
        // Verify that the non-Entity/non-MappedSuperclass is a BasicType
        Type positionNonEntity = ((MetamodelImpl) metamodel).getType(Position.class);
        assertNotNull(positionNonEntity);
        assertEquals(Type.PersistenceType.BASIC, positionNonEntity.getPersistenceType());
        // Get direct inheriting subclass
        EntityTypeImpl<GalacticPosition> entityLocation_ = (EntityTypeImpl) metamodel.entity(GalacticPosition.class);
        assertNotNull(entityLocation_);
        // We will be testing that the non-persistent fields
        Attribute anAttributeThatShouldNotHaveBeenInherited = entityLocation_.getAttribute("nonPersistentObject");
        // we should never get to the following line - go directly to catch block
        assertTrue("IllegalArgumentException expected on transient type attribute should not be in subclass for managedType.getAttribute()", exceptionThrown);
    } catch (IllegalArgumentException iae) {
        // iae.printStackTrace();
        exceptionThrown = true;
        assertTrue("IllegalArgumentException expected on transient type attribute should not be in subclass for managedType.getAttribute()", exceptionThrown);
    } finally {
        cleanup(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) EntityType(jakarta.persistence.metamodel.EntityType) IdentifiableType(jakarta.persistence.metamodel.IdentifiableType) PersistentAttributeType(jakarta.persistence.metamodel.Attribute.PersistentAttributeType) MappedSuperclassType(jakarta.persistence.metamodel.MappedSuperclassType) EmbeddableType(jakarta.persistence.metamodel.EmbeddableType) PersistenceType(jakarta.persistence.metamodel.Type.PersistenceType) CollectionType(jakarta.persistence.metamodel.PluralAttribute.CollectionType) Type(jakarta.persistence.metamodel.Type) ManagedType(jakarta.persistence.metamodel.ManagedType) MetamodelImpl(org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl) PluralAttribute(jakarta.persistence.metamodel.PluralAttribute) Attribute(jakarta.persistence.metamodel.Attribute) MapAttribute(jakarta.persistence.metamodel.MapAttribute) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) SetAttribute(jakarta.persistence.metamodel.SetAttribute) ListAttribute(jakarta.persistence.metamodel.ListAttribute) CollectionAttribute(jakarta.persistence.metamodel.CollectionAttribute) GalacticPosition(org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) Metamodel(jakarta.persistence.metamodel.Metamodel)

Example 2 with EntityTypeImpl

use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testMapAttribute_getKeyType_294811_UC12_DI86_Embedded_keyType_Method.

// This test verifies the workaround for 294811
public void testMapAttribute_getKeyType_294811_UC12_DI86_Embedded_keyType_Method() {
    EntityManager em = null;
    boolean exceptionThrown = 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_);
        // Actual Test Case
        /**
         * Return the type representing the key type of the map.
         * @return type representing key type
         */
        // Type<K> getKeyType();
        MapAttribute<? super Computer, ?, ?> anAttribute = entityComputer_.getMap("positionUC12");
        // verify the key type is the Map key - not the managedType PK
        Class<?> keyJavaType = anAttribute.getKeyJavaType();
        // UC12:  mapKey defined via generics and is an Embeddable (EmbeddedId) java class defined as an IdClass on the element(value) class
        // @OneToMany(mappedBy="computerUC12", cascade=ALL, fetch=EAGER)
        // @MapKey // key defaults to an instance of the composite pk class
        // private Map<EmbeddedPK, GalacticPosition> positionUC12;
        Type keyType = anAttribute.getKeyType();
        // When @MapKey(name="name") is present or we use generics
        assertEquals(EmbeddedPK.class, keyJavaType);
        assertNotNull(keyType);
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        exceptionThrown = true;
    } finally {
        cleanup(em);
        assertFalse("An IAE exception should not occur here.", exceptionThrown);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) EntityType(jakarta.persistence.metamodel.EntityType) IdentifiableType(jakarta.persistence.metamodel.IdentifiableType) PersistentAttributeType(jakarta.persistence.metamodel.Attribute.PersistentAttributeType) MappedSuperclassType(jakarta.persistence.metamodel.MappedSuperclassType) EmbeddableType(jakarta.persistence.metamodel.EmbeddableType) PersistenceType(jakarta.persistence.metamodel.Type.PersistenceType) CollectionType(jakarta.persistence.metamodel.PluralAttribute.CollectionType) Type(jakarta.persistence.metamodel.Type) ManagedType(jakarta.persistence.metamodel.ManagedType) Computer(org.eclipse.persistence.testing.models.jpa.metamodel.Computer) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) Metamodel(jakarta.persistence.metamodel.Metamodel)

Example 3 with EntityTypeImpl

use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testManagedType_getDeclaredSingularAttribute_Type_param_Method.

// TODO: This is not testing anything different?
public void testManagedType_getDeclaredSingularAttribute_Type_param_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<Manufacturer> entityManufacturer_ = (EntityTypeImpl) metamodel.entity(Manufacturer.class);
        assertNotNull(entityManufacturer_);
        MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl) metamodel.managedType(Person.class);
        assertNotNull(msPerson_);
        MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl) metamodel.managedType(Corporation.class);
        assertNotNull(msCorporation_);
        EntityTypeImpl<GalacticPosition> entityLocation_ = (EntityTypeImpl) metamodel.entity(GalacticPosition.class);
        assertNotNull(entityLocation_);
        EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl) metamodel.entity(Computer.class);
        assertNotNull(entityComputer_);
        EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl) metamodel.entity(HardwareDesigner.class);
        assertNotNull(entityHardwareDesigner_);
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        expectedIAExceptionThrown = true;
    } finally {
        cleanup(em);
        assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
    }
}
Also used : GalacticPosition(org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition) Corporation(org.eclipse.persistence.testing.models.jpa.metamodel.Corporation) EntityManager(jakarta.persistence.EntityManager) HardwareDesigner(org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner) Manufacturer(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) MappedSuperclassTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl) Computer(org.eclipse.persistence.testing.models.jpa.metamodel.Computer) Metamodel(jakarta.persistence.metamodel.Metamodel) Person(org.eclipse.persistence.testing.models.jpa.metamodel.Person)

Example 4 with EntityTypeImpl

use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testIdentifiableType_getDeclaredVersion_does_not_exist_at_all_Method.

// TODO: This is not testing anything different?
public void testIdentifiableType_getDeclaredVersion_does_not_exist_at_all_Method() {
    EntityManager em = null;
    boolean expectedIAExceptionThrown = false;
    try {
        em = privateTestSetup();
        assertNotNull(em);
        Metamodel metamodel = em.getMetamodel();
        assertNotNull(metamodel);
        EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl) metamodel.entity(Manufacturer.class);
        assertNotNull(entityManufacturer_);
        // Actual Test Case
        /**
         *  Return the attribute that corresponds to the version
         *  attribute declared by the entity or mapped superclass.
         *  @param type  the type of the represented declared version
         *               attribute
         *  @return declared version attribute
         *  @throws IllegalArgumentException if version attribute of the
         *          type is not declared in the identifiable type
         */
        // <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type);
        // Does not exist
        // EntityType<Enclosure> anEnclosureType = metamodel.entity(Enclosure.class);
        // assertNotNull(anEnclosureType.getDeclaredVersion(Integer.class));
        // Is declared
        assertNotNull(entityManufacturer_.getDeclaredVersion(int.class));
    // FUTURE: need an undeclared subclass
    // Is declared for assertNotNull(msPerson1_.getDeclaredVersion(Integer.class));
    } 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) Manufacturer(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) Metamodel(jakarta.persistence.metamodel.Metamodel)

Example 5 with EntityTypeImpl

use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testIdentifiableType_getDeclaredVersion_exists_Method.

public void testIdentifiableType_getDeclaredVersion_exists_Method() {
    EntityManager em = null;
    boolean expectedIAExceptionThrown = false;
    try {
        em = privateTestSetup();
        assertNotNull(em);
        Metamodel metamodel = em.getMetamodel();
        assertNotNull(metamodel);
        EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl) metamodel.entity(Manufacturer.class);
        assertNotNull(entityManufacturer_);
        // Actual Test Case
        /**
         *  Return the attribute that corresponds to the version
         *  attribute declared by the entity or mapped superclass.
         *  @param type  the type of the represented declared version
         *               attribute
         *  @return declared version attribute
         *  @throws IllegalArgumentException if version attribute of the
         *          type is not declared in the identifiable type
         */
        // <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type);
        // FUTURE: need an undeclared subclass
        // Is declared
        SingularAttribute<Manufacturer, ?> anAttribute = entityManufacturer_.getDeclaredVersion(int.class);
        assertNotNull(anAttribute);
        assertNotNull(anAttribute.getType());
        assertNotNull(anAttribute.getBindableType());
        assertNotNull(anAttribute.getBindableJavaType());
        assertNotNull(anAttribute.getDeclaringType());
        assertEquals(entityManufacturer_, anAttribute.getDeclaringType());
        assertFalse(anAttribute.isId());
        assertTrue(anAttribute.isVersion());
        assertEquals(PersistentAttributeType.BASIC, anAttribute.getPersistentAttributeType());
        assertTrue(anAttribute.isOptional());
        assertNotNull(anAttribute.getJavaType());
        assertFalse(anAttribute.isAssociation());
        assertFalse(anAttribute.isCollection());
    } 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) Manufacturer(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) Metamodel(jakarta.persistence.metamodel.Metamodel)

Aggregations

EntityManager (jakarta.persistence.EntityManager)99 Metamodel (jakarta.persistence.metamodel.Metamodel)99 EntityTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl)99 Manufacturer (org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer)80 Computer (org.eclipse.persistence.testing.models.jpa.metamodel.Computer)45 GalacticPosition (org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition)42 PluralAttribute (jakarta.persistence.metamodel.PluralAttribute)38 HardwareDesigner (org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner)36 Attribute (jakarta.persistence.metamodel.Attribute)35 CollectionAttribute (jakarta.persistence.metamodel.CollectionAttribute)35 ListAttribute (jakarta.persistence.metamodel.ListAttribute)35 MapAttribute (jakarta.persistence.metamodel.MapAttribute)35 SetAttribute (jakarta.persistence.metamodel.SetAttribute)35 SingularAttribute (jakarta.persistence.metamodel.SingularAttribute)35 MappedSuperclassTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl)29 Person (org.eclipse.persistence.testing.models.jpa.metamodel.Person)29 Corporation (org.eclipse.persistence.testing.models.jpa.metamodel.Corporation)27 IdentifiableType (jakarta.persistence.metamodel.IdentifiableType)25 ManagedType (jakarta.persistence.metamodel.ManagedType)25 PersistentAttributeType (jakarta.persistence.metamodel.Attribute.PersistentAttributeType)24