use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class CacheTest method testRelationshipCachingWhenNontransactional.
public void testRelationshipCachingWhenNontransactional() throws Exception {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
// Create sample data
Object acctId = null;
try {
tx.begin();
LoginAccount acct = new LoginAccount("Barney", "Rubble", "brubble", "bambam");
pm.makePersistent(acct);
acctId = JDOHelper.getObjectId(acct);
tx.commit();
} catch (Exception e) {
LOG.error(e);
fail("Exception thrown while creating 1-1 unidirectional relationship data : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Make sure the object isn't in the cache following persistence
pmf.getDataStoreCache().evictAll();
pmf.getDataStoreCache().pinAll(true, LoginAccount.class);
pmf.getDataStoreCache().pinAll(true, Login.class);
// Retrieve the record and check the data
pm = pmf.getPersistenceManager();
try {
LOG.info(">> CacheTest fetching LoginAccount(1)");
LoginAccount acct = (LoginAccount) pm.getObjectById(acctId);
assertTrue("LoginAccount \"firstName\" is incorrect", acct.getFirstName().equals("Barney"));
assertTrue("LoginAccount \"lastName\" is incorrect", acct.getLastName().equals("Rubble"));
LOG.info(">> CacheTest fetching Login(1)");
// Access the login field to make sure it is read. Should get L2 cached now
Login login = acct.getLogin();
assertEquals("Login \"login\" is incorrect", login.getUserName(), "brubble");
assertEquals("Login \"password\" is incorrect", login.getPassword(), "bambam");
} catch (Exception e) {
LOG.error(e);
fail("Exception thrown while interrogating 1-1 unidirectional relationship data : " + e.getMessage());
} finally {
pm.close();
}
// login account is in the cache now after the last getObjectById
LOG.info(">> CacheTest fetching LoginAccount(non-tx)");
CachedPC cpc = ((JDOPersistenceManagerFactory) pmf).getNucleusContext().getLevel2Cache().get(acctId);
assertTrue("LoginAccount is not cached", cpc != null);
assertTrue("LoginAccount \"login\" is not cached", cpc.getFieldValue(2) != null);
// Retrieve the record and check the data
pm = pmf.getPersistenceManager();
try {
LoginAccount acct = (LoginAccount) pm.getObjectById(acctId);
String[] loadedFields = NucleusJDOHelper.getLoadedFields(acct, pm);
LOG.info(">> loadedFields=" + StringUtils.objectArrayToString(loadedFields));
LOG.info(">> Accessing field login");
Login login = acct.getLogin();
LOG.info(">> login=" + login);
} finally {
pm.close();
}
} finally {
clean(LoginAccount.class);
}
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class DN2NamingFactoryTest method testVersionColumnName.
public void testVersionColumnName() {
JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
NucleusContext nucCtx = jdoPMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Trade1.class, clr);
DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.COLUMN, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Column name for version is incorrect", "version", factory.getColumnName(cmd1, ColumnType.VERSION_COLUMN));
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class DN2NamingFactoryTest method testEmbeddedPCColumnNames.
public void testEmbeddedPCColumnNames() {
JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
NucleusContext nucCtx = jdoPMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.COLUMN, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
AbstractClassMetaData compCmd = mmgr.getMetaDataForClass(Computer.class, clr);
AbstractMemberMetaData graphicsMmd = compCmd.getMetaDataForMember("graphicsCard");
AbstractClassMetaData cardCmd = mmgr.getMetaDataForClass(ComputerCard.class, clr);
AbstractMemberMetaData makerMmd = cardCmd.getMetaDataForMember("makerName");
List<AbstractMemberMetaData> colMmds = new ArrayList<AbstractMemberMetaData>();
colMmds.add(graphicsMmd);
colMmds.add(makerMmd);
String colName = factory.getColumnName(colMmds, 0);
// Comes from EmbeddedMetaData override
assertEquals("graphics_maker", colName);
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class DN2NamingFactoryTest method testTableName.
public void testTableName() {
JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
NucleusContext nucCtx = jdoPMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(BooleanArray.class, clr);
DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.TABLE, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Table name is incorrect", "booleanarray", factory.getTableName(cmd1));
factory.setNamingCase(NamingCase.LOWER_CASE_QUOTED);
assertEquals("Table name is incorrect", "\"booleanarray\"", factory.getTableName(cmd1));
factory.setNamingCase(NamingCase.UPPER_CASE);
assertEquals("Table name is incorrect", "BOOLEANARRAY", factory.getTableName(cmd1));
factory.setNamingCase(NamingCase.UPPER_CASE_QUOTED);
assertEquals("Table name is incorrect", "\"BOOLEANARRAY\"", factory.getTableName(cmd1));
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class PgGeometrySpatialHelperTest method setUp.
protected void setUp() throws Exception {
helper = new SpatialHelper((JDOPersistenceManagerFactory) pmf);
super.setUp();
}
Aggregations