Search in sources :

Example 1 with Manufacturer

use of org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer 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 Manufacturer

use of org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer 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 3 with Manufacturer

use of org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer 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)

Example 4 with Manufacturer

use of org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer in project eclipselink by eclipse-ee4j.

the class MetamodelMetamodelTest method testMapAttribute_getKeyJavaType_UC9_DI86_Embeddable_IdClass_keyType_Method.

// See
// http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_86:_20090921:_Handle_Embeddable_Type_keyType_in_MapAttributeImpl_constructor
public void testMapAttribute_getKeyJavaType_UC9_DI86_Embeddable_IdClass_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<Manufacturer> entityManufacturer_ = (EntityTypeImpl) metamodel.entity(Manufacturer.class);
        assertNotNull(entityManufacturer_);
        // Actual Test Case
        /**
         * Return the Java type of the map key.
         * @return Java key type
         */
        // Class<K> getKeyJavaType();
        MapAttribute<? super Manufacturer, ?, ?> anAttribute = entityManufacturer_.getMap("enclosureByBoardMapUC9");
        // verify the key type is the Map key - not the managedType PK
        Class<?> keyJavaType = anAttribute.getKeyJavaType();
        // UC9: no targetEntity, no MapKey, but generics are set (MapKey has an IdClass with an Embeddable)
        // @OneToMany(cascade=CascadeType.ALL, mappedBy="mappedManufacturerUC9")
        // private Map<Board, Enclosure> enclosureByBoardMapUC9;
        Type keyType = anAttribute.getKeyType();
        // When @MapKey(name="name") is present or we use generics
        assertEquals(Board.class, keyJavaType);
        assertNotNull(keyType);
        assertTrue(keyType instanceof Type);
        assertEquals(Type.PersistenceType.ENTITY, keyType.getPersistenceType());
    } 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) 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 Manufacturer

use of org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer 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)

Aggregations

EntityManager (jakarta.persistence.EntityManager)85 Manufacturer (org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer)85 Metamodel (jakarta.persistence.metamodel.Metamodel)83 EntityTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl)80 HardwareDesigner (org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner)36 Computer (org.eclipse.persistence.testing.models.jpa.metamodel.Computer)32 GalacticPosition (org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition)31 Person (org.eclipse.persistence.testing.models.jpa.metamodel.Person)29 MappedSuperclassTypeImpl (org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl)28 PluralAttribute (jakarta.persistence.metamodel.PluralAttribute)27 Corporation (org.eclipse.persistence.testing.models.jpa.metamodel.Corporation)26 Attribute (jakarta.persistence.metamodel.Attribute)25 CollectionAttribute (jakarta.persistence.metamodel.CollectionAttribute)25 ListAttribute (jakarta.persistence.metamodel.ListAttribute)25 MapAttribute (jakarta.persistence.metamodel.MapAttribute)25 SetAttribute (jakarta.persistence.metamodel.SetAttribute)25 SingularAttribute (jakarta.persistence.metamodel.SingularAttribute)25 IdentifiableType (jakarta.persistence.metamodel.IdentifiableType)19 ManagedType (jakarta.persistence.metamodel.ManagedType)18 PersistentAttributeType (jakarta.persistence.metamodel.Attribute.PersistentAttributeType)17