use of jakarta.persistence.metamodel.Type in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testAttribute_isCollection_false_Method.
public void testAttribute_isCollection_false_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<GalacticPosition> entityLocation_ = (EntityTypeImpl) metamodel.entity(GalacticPosition.class);
assertNotNull(entityLocation_);
Type<?> locationIdType = entityLocation_.getIdType();
assertNotNull(locationIdType);
assertEquals(PersistenceType.EMBEDDABLE, locationIdType.getPersistenceType());
assertEquals(EmbeddedPK.class, locationIdType.getJavaType());
Attribute locationIdAttribute = entityLocation_.getAttribute("primaryKey");
assertNotNull(locationIdAttribute);
assertTrue(locationIdAttribute instanceof SingularAttributeImpl);
/**
* Is the attribute collection-valued.
* @return boolean indicating whether attribute is
* collection-valued
*/
// boolean isCollection();
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);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.Type in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyType_294811_UC13_DI86_Embedded_keyType_Method.
// This test verifies the workaround for 294811
public void testMapAttribute_getKeyType_294811_UC13_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("positionUniUC13");
// verify the key type is the Map key - not the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// UC13: mapKey defined via generics and is an Embeddable (EmbeddedId) java class defined as an IdClass on the element(value) class
// However, here we make the owning OneToMany - unidirectional and an effective ManyToMany
// @MapKey // key defaults to an instance of the composite pk class
// private Map<EmbeddedPK, GalacticPosition> positionUniUC13;
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);
}
}
use of jakarta.persistence.metamodel.Type in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyType_UC4_Method.
public void testMapAttribute_getKeyType_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 type representing the key type of the map.
* @return type representing key type
*/
// Type<K> getKeyType();
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.Type in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyJavaType_UC8_Method.
public void testMapAttribute_getKeyJavaType_UC8_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("hardwareDesignersMapUC8");
// verify the key type is the Map key - not the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// UC 8: Generics KV set, targetEntity not set, @MapKey is set but name attribute is defaulted
// @OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC8")
// Same as UC1a - that is missing the @MapKey name attribute
// private Map<String, HardwareDesigner> hardwareDesignersMapUC8;
Type keyType = anAttribute.getKeyType();
// When @MapKey or generics are not present - we default to the PK
assertEquals(Integer.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.Type in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyType_UC8_Method.
public void testMapAttribute_getKeyType_UC8_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("hardwareDesignersMapUC8");
// verify the key type is the Map key - not the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// UC 8: Generics KV set, targetEntity not set, @MapKey is set but name attribute is defaulted
// @OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC8")
// Same as UC1a - that is missing the @MapKey name attribute
// private Map<String, HardwareDesigner> hardwareDesignersMapUC8;
Type keyType = anAttribute.getKeyType();
// When @MapKey is not present or missing name attribute - we default to the PK
assertEquals(Integer.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);
}
}
Aggregations