use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationTest method testCharDefaultTo1Length.
/**
* Test of char length default to 1 with JPA.
*/
public void testCharDefaultTo1Length() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(TypeHolder.class.getName(), clr);
assertEquals(1, cmd1.getMetaDataForMember("char1").getColumnMetaData()[0].getLength().intValue());
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationTest method testOneToManyBiFK.
/**
* Test of JPA 1-N bidir FK relation
*/
public void testOneToManyBiFK() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
// owner side
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("departments");
assertNotNull("Manager.departments is null!", fmd1);
assertEquals("Manager.departments mapped-by is incorrect", fmd1.getMappedBy(), "manager");
assertEquals("Manager.departments relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_BI);
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNull("Manager.departments has join column info but shouldnt (specified on N side)", elemmd);
// non-owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("manager");
assertNotNull("Department.manager is null!", fmd2);
assertEquals("Department.manager mapped-by is incorrect", fmd2.getMappedBy(), null);
assertEquals("Department.manager relationType is incorrect", fmd2.getRelationType(clr), RelationType.MANY_TO_ONE_BI);
ColumnMetaData[] colmds = fmd2.getColumnMetaData();
assertNotNull("Department.manager has no join column info", colmds);
assertEquals("Department.manager has incorrect number of joincolumns", colmds.length, 1);
assertEquals("Department.manager joincolumn name is wrong", "MGR_ID", colmds[0].getName());
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationTest method testSqlResultSetMapping.
/**
* Test of JPA @SqlResultSetMapping
*/
public void testSqlResultSetMapping() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(LoginAccount.class.getName(), clr);
QueryResultMetaData[] queryResultMappings = cmd.getQueryResultMetaData();
assertNotNull("LoginAccount has no QueryResultMetaData!", queryResultMappings);
assertEquals("LoginAccount has incorrect number of query result mappings", 4, queryResultMappings.length);
// Example 1 : Returning 2 entities
QueryResultMetaData qrmd = null;
for (int i = 0; i < queryResultMappings.length; i++) {
QueryResultMetaData md = queryResultMappings[i];
if (md.getName().equals("AN_LOGIN_PLUS_ACCOUNT")) {
qrmd = md;
break;
}
}
if (qrmd == null) {
fail("SQL ResultSet mapping AN_LOGIN_PLUS_ACCOUNT is not present!");
}
String[] scalarCols = qrmd.getScalarColumns();
assertNull("LoginAccount sql mapping has incorrect scalar cols", scalarCols);
PersistentTypeMapping[] sqlMappingEntities = qrmd.getPersistentTypeMappings();
assertNotNull("LoginAccount sql mapping has incorrect entities", sqlMappingEntities);
assertEquals("LoginAccount sql mapping has incorrect number of entities", 2, sqlMappingEntities.length);
// LoginAccount
assertEquals("LoginAccount sql mapping entity 0 has incorrect class", LoginAccount.class.getName(), sqlMappingEntities[0].getClassName());
assertNull("LoginAccount sql mapping entity 0 has incorrect discriminator", sqlMappingEntities[0].getDiscriminatorColumn());
// Login
assertEquals("LoginAccount sql mapping entity 1 has incorrect class", Login.class.getName(), sqlMappingEntities[1].getClassName());
assertNull("LoginAccount sql mapping entity 1 has incorrect discriminator", sqlMappingEntities[1].getDiscriminatorColumn());
// Example 2 : Returning 2 scalars
qrmd = null;
for (int i = 0; i < queryResultMappings.length; i++) {
QueryResultMetaData md = queryResultMappings[i];
if (md.getName().equals("AN_ACCOUNT_NAMES")) {
qrmd = md;
break;
}
}
if (qrmd == null) {
fail("SQL ResultSet mapping AN_ACCOUNT_NAMES is not present!");
}
scalarCols = qrmd.getScalarColumns();
assertNotNull("LoginAccount sql mapping has incorrect scalar cols", scalarCols);
assertEquals("LoginAccount sql mapping has incorrect column name", "FIRSTNAME", scalarCols[0]);
assertEquals("LoginAccount sql mapping has incorrect column name", "LASTNAME", scalarCols[1]);
sqlMappingEntities = qrmd.getPersistentTypeMappings();
assertNull("LoginAccount sql mapping has incorrect entities", sqlMappingEntities);
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationTest method testStringLength.
/**
* Test of string length default to JPA default 255.
*/
public void testStringLength() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Account.class.getName(), clr);
AbstractMemberMetaData mmd1 = cmd1.getMetaDataForMember("username");
assertEquals(255, mmd1.getColumnMetaData()[0].getLength().intValue());
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationTest method testMappedSuperclass.
/**
* Test of MappedSuperclass
*/
public void testMappedSuperclass() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
// AbstractSimpleBase
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(AbstractSimpleBase.class.getName(), clr);
assertNotNull("No MetaData found for AbstractSimpleBase yet is MappedSuperclass", cmd);
assertNotNull("No Inheritance info found for AbstractSimpleBase", cmd.getInheritanceMetaData());
assertEquals("Inheritance for AbstractSimpleBase is incorrect", "subclass-table", cmd.getInheritanceMetaData().getStrategy().toString());
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("id");
assertNotNull("No field info found for AbstractSimpleBase.id", fmd);
assertNotNull("No column info found for AbstractSimpleBase.id", fmd.getColumnMetaData());
assertEquals("Column name for AbstractSimpleBase.id is wrong", "ID", fmd.getColumnMetaData()[0].getName());
fmd = cmd.getMetaDataForMember("baseField");
assertNotNull("No field info found for AbstractSimpleBase.baseField", fmd);
assertNotNull("No column info found for AbstractSimpleBase.baseField", fmd.getColumnMetaData());
assertEquals("Column name for Product.baseField is wrong", "BASE_FIELD", fmd.getColumnMetaData()[0].getName());
// ConcreteSimpleSub1
cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(ConcreteSimpleSub1.class.getName(), clr);
assertNotNull("No MetaData found for ConcreteSimpleSub1 yet is Entity", cmd);
assertNotNull("No Inheritance info found for ConcreteSimpleSub1", cmd.getInheritanceMetaData());
assertEquals("Inheritance for ConcreteSimpleSub1 is incorrect", "new-table", cmd.getInheritanceMetaData().getStrategy().toString());
fmd = cmd.getOverriddenMember("baseField");
assertNotNull("No overridden field info found for ConcreteSimpleSub1.baseField", fmd);
assertNotNull("No column info found for ConcreteSimpleSub1.baseField", fmd.getColumnMetaData());
assertEquals("Column name for ConcreteSimpleSub1.baseField is wrong", "BASE_FIELD_OR", fmd.getColumnMetaData()[0].getName());
fmd = cmd.getMetaDataForMember("sub1Field");
assertNotNull("No field info found for ConcreteSimpleSub1.sub1Field", fmd);
assertNotNull("No column info found for ConcreteSimpleSub1.sub1Field", fmd.getColumnMetaData());
assertEquals("Column name for ConcreteSimpleSub1.sub1Field is wrong", "SUB1_FIELD", fmd.getColumnMetaData()[0].getName());
// ConcreteSimpleSub2
cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(ConcreteSimpleSub2.class.getName(), clr);
assertNotNull("No MetaData found for ConcreteSimpleSub2 yet is Entity", cmd);
assertNotNull("No Inheritance info found for ConcreteSimpleSub2", cmd.getInheritanceMetaData());
assertEquals("Inheritance for ConcreteSimpleSub2 is incorrect", "new-table", cmd.getInheritanceMetaData().getStrategy().toString());
fmd = cmd.getOverriddenMember("baseField");
assertNull("Overridden field info found for ConcreteSimpleSub2.baseField!", fmd);
fmd = cmd.getMetaDataForMember("sub2Field");
assertNotNull("No overridden field info found for ConcreteSimpleSub2.sub2Field", fmd);
assertNotNull("No column info found for ConcreteSimpleSub2.sub2Field", fmd.getColumnMetaData());
assertEquals("Column name for ConcreteSimpleSub2.sub2Field is wrong", "SUB2_FIELD", fmd.getColumnMetaData()[0].getName());
}
Aggregations