use of jakarta.persistence.metamodel.IdentifiableType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testAttribute_getJavaType_BasicType_Method.
public void testAttribute_getJavaType_BasicType_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);
/**
* Return the Java type of the represented attribute.
* @return Java type
*/
// Class<Y> getJavaType();
ManagedType<Person> msPerson = metamodel.managedType(Person.class);
assertNotNull(msPerson);
assertEquals(Type.PersistenceType.MAPPED_SUPERCLASS, msPerson.getPersistenceType());
Attribute idAttribute = ((IdentifiableType) msPerson).getDeclaredId(Integer.class);
assertNotNull(idAttribute);
assertEquals(Integer.class, idAttribute.getJavaType());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.IdentifiableType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testAttribute_getJavaMember_BasicType_on_MappedSuperclass_Method.
public void testAttribute_getJavaMember_BasicType_on_MappedSuperclass_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);
ManagedType<Person> msPerson = metamodel.managedType(Person.class);
assertNotNull(msPerson);
assertEquals(Type.PersistenceType.MAPPED_SUPERCLASS, msPerson.getPersistenceType());
/**
* Return the java.lang.reflect.Member for the represented
* attribute.
* @return corresponding java.lang.reflect.Member
*/
// java.lang.reflect.Member getJavaMember();
Attribute idAttribute = ((IdentifiableType) msPerson).getDeclaredId(Integer.class);
assertNotNull(idAttribute);
assertEquals(Integer.class, idAttribute.getJavaType());
// For primitive and basic types - we should not return null - the attributeAccessor on the MappedSuperclass is not initialized - see
// http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_95:_20091017:_Attribute.getJavaMember.28.29_returns_null_for_a_BasicType_on_a_MappedSuperclass_because_of_an_uninitialized_accessor
Member aMember = idAttribute.getJavaMember();
assertNotNull("id java member is null", aMember);
assertTrue("id attribute java member is not an instance of Field", aMember instanceof Field);
assertEquals("id", aMember.getName());
assertNotNull(((Field) aMember).getType());
assertEquals(Integer.class.getName(), ((Field) aMember).getType().getName());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.IdentifiableType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testIdentifiableType_getDeclaredId_variant_execution_attribute_is_declared_above.
public void testIdentifiableType_getDeclaredId_variant_execution_attribute_is_declared_above() {
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);
ManagedType<Manufacturer> entityManufacturer_ = metamodel.managedType(Manufacturer.class);
assertNotNull(entityManufacturer_);
assertEquals(Type.PersistenceType.ENTITY, entityManufacturer_.getPersistenceType());
/**
* Return the attribute that corresponds to the id attribute
* declared by the entity or mapped superclass.
* @param type the type of the represented declared id attribute
* @return declared id attribute
* @throws IllegalArgumentException if id attribute of the given
* type is not declared in the identifiable type or if
* the identifiable type has an id class
*/
// <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type);
// Not declared - invalid - IAE thrown (actually declared 2 levels above in "Person")
Attribute idAttribute = ((IdentifiableType) entityManufacturer_).getDeclaredId(Integer.class);
} catch (IllegalArgumentException iae) {
// iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertTrue("non-declared attribute should throw an IAE", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.IdentifiableType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testAttribute_getName_Method.
public void testAttribute_getName_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);
/**
* Return the name of the attribute.
* @return name
*/
// String getName();
ManagedType<Person> msPerson = metamodel.managedType(Person.class);
assertNotNull(msPerson);
assertEquals(Type.PersistenceType.MAPPED_SUPERCLASS, msPerson.getPersistenceType());
Attribute idAttribute = ((IdentifiableType) msPerson).getDeclaredId(Integer.class);
assertNotNull(idAttribute);
assertEquals(Integer.class, idAttribute.getJavaType());
assertEquals("id", idAttribute.getName());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of jakarta.persistence.metamodel.IdentifiableType in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testIdentifiableType_getDeclaredId_normal_execution_attribute_is_declared.
public void testIdentifiableType_getDeclaredId_normal_execution_attribute_is_declared() {
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);
ManagedType<Person> msPerson = metamodel.managedType(Person.class);
assertNotNull(msPerson);
assertEquals(Type.PersistenceType.MAPPED_SUPERCLASS, msPerson.getPersistenceType());
/**
* Return the attribute that corresponds to the id attribute
* declared by the entity or mapped superclass.
* @param type the type of the represented declared id attribute
* @return declared id attribute
* @throws IllegalArgumentException if id attribute of the given
* type is not declared in the identifiable type or if
* the identifiable type has an id class
*/
// <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type);
// declared - valid
Attribute idAttribute = ((IdentifiableType) msPerson).getDeclaredId(Integer.class);
assertNotNull(idAttribute);
assertEquals(Integer.class, idAttribute.getJavaType());
// declared and valid
// *********************************************/
// FUTURE: Require a version on a MappedSuperclass
// assertNotNull(msPerson1_.getDeclaredId(Integer.class)); - keep commented
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
Aggregations