Search in sources :

Example 1 with MappedSuperclassTypeImpl

use of org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl 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 2 with MappedSuperclassTypeImpl

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

the class MetamodelMetamodelTest method testManagedType_getList_Type_param_Method.

// TODO: This is not testing anything different?
public void testManagedType_getList_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 3 with MappedSuperclassTypeImpl

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

the class MetamodelMetamodelTest method testManagedType_getDeclaredSingularAttribute_on_MappedSuperclass_Method.

public void testManagedType_getDeclaredSingularAttribute_on_MappedSuperclass_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);
        MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl) metamodel.managedType(Person.class);
        assertNotNull(msPerson_);
        // Test case
        Attribute anAttribute = msPerson_.getSingularAttribute("name");
        assertNotNull(anAttribute);
        assertEquals(PersistentAttributeType.BASIC, anAttribute.getPersistentAttributeType());
        assertFalse(((AttributeImpl) anAttribute).isPlural());
        assertTrue(anAttribute instanceof SingularAttribute);
        assertEquals(String.class, anAttribute.getJavaType());
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        expectedIAExceptionThrown = true;
    } finally {
        cleanup(em);
        assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
    }
}
Also used : SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) EntityManager(jakarta.persistence.EntityManager) 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) MappedSuperclassTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl) Metamodel(jakarta.persistence.metamodel.Metamodel) Person(org.eclipse.persistence.testing.models.jpa.metamodel.Person)

Example 4 with MappedSuperclassTypeImpl

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

the class MetamodelMetamodelTest method testManagedType_getCollection_Type_param_Method.

// TODO: This is not testing anything different?
public void testManagedType_getCollection_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 5 with MappedSuperclassTypeImpl

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

the class MetamodelMetamodelTest method testIdentifiableType_getIdType_Method.

public void testIdentifiableType_getIdType_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_);
        EntityTypeImpl<GalacticPosition> entityLocation_ = (EntityTypeImpl) metamodel.entity(GalacticPosition.class);
        assertNotNull(entityLocation_);
        EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl) metamodel.entity(Computer.class);
        assertNotNull(entityComputer_);
        // Actual Test Case
        /**
         *  Return the type that represents the type of the id.
         *  @return type of id
         */
        // Type<?> getIdType();
        // Test EntityType
        // Test normal path for an [Embeddable] type via @EmbeddedId
        expectedIAExceptionThrown = false;
        Type<?> locationIdType = null;
        try {
            locationIdType = entityLocation_.getIdType();
        } catch (IllegalArgumentException iae) {
            // expecting no exception
            iae.printStackTrace();
            expectedIAExceptionThrown = true;
        }
        assertFalse(expectedIAExceptionThrown);
        assertNotNull(locationIdType);
        assertEquals(PersistenceType.EMBEDDABLE, locationIdType.getPersistenceType());
        assertEquals(EmbeddedPK.class, locationIdType.getJavaType());
        // check that the elementType and the owningType (managedType) are set correctly
        // See issue 50 where some mapping types were not setting the elementType correctly (this includes aggregate types like Embeddable)
        // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_50:_20090727:_Handle_all_mapping_types_in_the_SingularAttribute_constructor
        // Get the ManagedType and check this SingularAttribute PK
        Attribute locationIdAttribute = entityLocation_.getAttribute("primaryKey");
        assertNotNull(locationIdAttribute);
        assertTrue(locationIdAttribute instanceof SingularAttributeImpl);
        assertFalse(locationIdAttribute.isCollection());
        // non-spec.
        assertFalse(((AttributeImpl) locationIdAttribute).isPlural());
        ManagedType locationIdAttributeManagedType = locationIdAttribute.getDeclaringType();
        assertEquals(entityLocation_, locationIdAttributeManagedType);
        ManagedTypeImpl locationIdAttributeManagedTypeImpl = ((SingularAttributeImpl) locationIdAttribute).getManagedTypeImpl();
        assertEquals(locationIdType.getJavaType(), ((SingularAttributeImpl) locationIdAttribute).getBindableJavaType());
        assertEquals(Bindable.BindableType.SINGULAR_ATTRIBUTE, ((SingularAttributeImpl) locationIdAttribute).getBindableType());
        assertEquals(locationIdType.getJavaType(), locationIdAttribute.getJavaType());
        Type embeddableType = ((SingularAttributeImpl) locationIdAttribute).getType();
        assertNotNull(embeddableType);
        assertNotSame(embeddableType, locationIdAttributeManagedType);
        // Test normal path for a [Basic] type
        expectedIAExceptionThrown = false;
        Type<?> computerIdType = null;
        try {
            computerIdType = entityComputer_.getIdType();
        } catch (IllegalArgumentException iae) {
            // expecting no exception
            iae.printStackTrace();
            expectedIAExceptionThrown = true;
        }
        assertFalse(expectedIAExceptionThrown);
        assertNotNull(computerIdType);
        assertEquals(PersistenceType.BASIC, computerIdType.getPersistenceType());
        assertEquals(Integer.class, computerIdType.getJavaType());
        // Test MappedSuperclassType
        // Test normal path for a [Basic] type
        expectedIAExceptionThrown = false;
        Type<?> personIdType = null;
        MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl) metamodel.managedType(Person.class);
        assertNotNull(msPerson_);
        MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl) metamodel.managedType(Corporation.class);
        assertNotNull(msCorporation_);
        // Verify all types (entities, embeddables, mappedsuperclasses and basic)
        // get all 21 types (a non spec function - for testing introspection)
        Map<String, TypeImpl<?>> typesMap = ((MetamodelImpl) metamodel).getTypes();
        // verify each one
        assertNotNull(typesMap);
        ((MetamodelImpl) metamodel).printAllTypes();
        // Note: Since BasicTypes are lazy - loaded into the metamodel-types Map - this test must preceed any test that verifies all BasicType objects like "testIdentifiableType_getIdType_Method"
        // You will get a lower number here - if only this single test is run via the Testing Browser
        assertEquals(METAMODEL_ALL_TYPES, typesMap.size());
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        expectedIAExceptionThrown = true;
    } finally {
        cleanup(em);
        assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
    }
}
Also used : 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) SingularAttributeImpl(org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl) Manufacturer(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) Computer(org.eclipse.persistence.testing.models.jpa.metamodel.Computer) MappedSuperclassTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl) Metamodel(jakarta.persistence.metamodel.Metamodel) MappedSuperclassTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl) TypeImpl(org.eclipse.persistence.internal.jpa.metamodel.TypeImpl) EmbeddableTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EmbeddableTypeImpl) BasicTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.BasicTypeImpl) EntityTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl) ManagedTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl) ManagedType(jakarta.persistence.metamodel.ManagedType) GalacticPosition(org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition) Corporation(org.eclipse.persistence.testing.models.jpa.metamodel.Corporation) 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) ManagedTypeImpl(org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl) Person(org.eclipse.persistence.testing.models.jpa.metamodel.Person)

Aggregations

EntityManager (jakarta.persistence.EntityManager)32 Metamodel (jakarta.persistence.metamodel.Metamodel)32 MappedSuperclassTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl)32 Person (org.eclipse.persistence.testing.models.jpa.metamodel.Person)30 Manufacturer (org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer)29 EntityTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl)28 Computer (org.eclipse.persistence.testing.models.jpa.metamodel.Computer)27 GalacticPosition (org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition)27 Corporation (org.eclipse.persistence.testing.models.jpa.metamodel.Corporation)26 HardwareDesigner (org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner)26 PluralAttribute (jakarta.persistence.metamodel.PluralAttribute)7 Attribute (jakarta.persistence.metamodel.Attribute)5 CollectionAttribute (jakarta.persistence.metamodel.CollectionAttribute)5 ListAttribute (jakarta.persistence.metamodel.ListAttribute)5 MapAttribute (jakarta.persistence.metamodel.MapAttribute)5 SetAttribute (jakarta.persistence.metamodel.SetAttribute)5 SingularAttribute (jakarta.persistence.metamodel.SingularAttribute)5 IdentifiableType (jakarta.persistence.metamodel.IdentifiableType)4 PersistentAttributeType (jakarta.persistence.metamodel.Attribute.PersistentAttributeType)3 EmbeddableType (jakarta.persistence.metamodel.EmbeddableType)3