use of jakarta.persistence.metamodel.ManagedType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyJavaType_UC7_Method.
public void testMapAttribute_getKeyJavaType_UC7_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("hardwareDesignersMapUC7");
// verify the key type is the Map key - not the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// UC 7: Generics KV set, targetEntity is also set, @MapKey is *(set/unset)
// @OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC7")
// Same as UC1a - that is missing the @MapKey
// private Map<String, HardwareDesigner> hardwareDesignersMapUC7;
Type keyType = anAttribute.getKeyType();
// When @MapKey(name="name") is present - or generics are set
assertEquals(String.class, keyJavaType);
assertNotNull(keyType);
assertTrue(keyType instanceof Type);
assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.ManagedType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyJavaType_UC4_Method.
public void testMapAttribute_getKeyJavaType_UC4_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("hardwareDesignersMapUC4");
// verify the key type is the Map key - not the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// UC 4: No Generics KV set, @MapKey is present
// @OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC4")
// @MapKey(name="name")
// private Map hardwareDesignersMapUC4;
Type keyType = anAttribute.getKeyType();
// When @MapKey(name="name") is present
assertEquals(String.class, keyJavaType);
assertNotNull(keyType);
assertTrue(keyType instanceof Type);
assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.ManagedType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyType_UC0_Method.
public void testMapAttribute_getKeyType_UC0_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 type representing the key type of the map.
* @return type representing key type
*/
// Type<K> getKeyType();
MapAttribute<? super Manufacturer, ?, ?> anAttribute = entityManufacturer_.getMap("hardwareDesignersMap");
// verify the default key type is the not the Map key - rather that is is the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// @OneToMany(cascade=ALL, mappedBy="mappedEmployer")
// private Map<String, HardwareDesigner> hardwareDesignersMap;// = new HashMap<String, HardwareDesigner>();
// http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
// Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
Type keyType = anAttribute.getKeyType();
// When @MapKey(name="name") is present - or generics are set
assertEquals(String.class, keyJavaType);
assertNotNull(keyType);
assertTrue(keyType instanceof Type);
assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.ManagedType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyJavaType_UC2_Method.
public void testMapAttribute_getKeyJavaType_UC2_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("hardwareDesignersMapUC2");
// verify the key type is the Map key - not the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// UC 2: Generics KV set, @MapKey is present
// @OneToMany(cascade=ALL, mappedBy="mappedEmployerUC2")
// @MapKey(name="name")
// private Map<String, HardwareDesigner> hardwareDesignersMapUC2;
Type keyType = anAttribute.getKeyType();
// When @MapKey(name="name") is present
assertEquals(String.class, keyJavaType);
assertNotNull(keyType);
assertTrue(keyType instanceof Type);
assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.ManagedType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testAttribute_getDeclaringType_Method.
public void testAttribute_getDeclaringType_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_);
EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl) metamodel.entity(HardwareDesigner.class);
assertNotNull(entityHardwareDesigner_);
/**
* Return the managed type representing the type in which
* the attribute was declared.
* @return declaring type
*/
// ManagedType<X> getDeclaringType();
// Test case
Attribute anAttribute = entityManufacturer_.getDeclaredAttribute("hardwareDesignersMapUC4");
ManagedType aManagedType = anAttribute.getDeclaringType();
assertEquals(entityManufacturer_, aManagedType);
assertNotNull(anAttribute);
assertEquals(PersistentAttributeType.ONE_TO_MANY, anAttribute.getPersistentAttributeType());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
Aggregations