use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class AnnotationTest method testSequenceGenerator.
/**
* Test of basic JPA @SequenceGenerator
*/
public void testSequenceGenerator() {
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 cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
PackageMetaData pmd = cmd1.getPackageMetaData();
assertEquals("Number of Sequences registered for Department class is wrong", pmd.getNoOfSequences(), 1);
SequenceMetaData seqmd = pmd.getSequences()[0];
assertEquals("SequenceGenerator has incorrect name", seqmd.getName(), "DepartmentGenerator");
assertEquals("SequenceGenerator has incorrect sequence name", seqmd.getDatastoreSequence(), "DEPT_SEQ");
assertEquals("SequenceGenerator has incorrect initial value", seqmd.getInitialValue(), 1);
assertEquals("SequenceGenerator has incorrect allocation size", seqmd.getAllocationSize(), 50);
}
use of org.datanucleus.PersistenceNucleusContextImpl 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.PersistenceNucleusContextImpl 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.PersistenceNucleusContextImpl 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.PersistenceNucleusContextImpl 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());
}
Aggregations