use of org.datanucleus.samples.jfire.organisation.JFireOrganisationID in project tests by datanucleus.
the class AttachDetachReplicateTest method testReplicateSimple2.
/**
* Another test of replication, with no relations. Just the object
*/
public void testReplicateSimple2() {
PersistenceManagerFactory pmf2 = getPersistenceManagerFactory2();
try {
PersistenceManager pm1 = pmf.getPersistenceManager();
JFireOrganisation organisation = null;
JFireOrganisationID organisationID = JFireOrganisationID.create("datanucleus.jfire.org");
// Persist in first DB
Transaction tx = null;
try {
tx = pm1.currentTransaction();
tx.begin();
JFireOrganisation org1 = new JFireOrganisation(organisationID.organisationID);
org1 = pm1.makePersistent(org1);
// Detach it for copying
organisation = pm1.detachCopy(org1);
tx.commit();
} catch (JDOException ue) {
LOG.error("Exception thrown persisting/detaching object", ue);
fail("Exception thrown while creating object in first datastore : " + ue.getMessage());
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
pm1.close();
}
// Check the detached object
if (!JDOHelper.isDetached(organisation)) {
fail("Organisation has not been detached!");
}
// Copy to other DB
PersistenceManager pm2 = pmf2.getPersistenceManager();
tx = pm2.currentTransaction();
try {
tx.begin();
pm2.makePersistent(organisation);
tx.commit();
} catch (JDOException ue) {
LOG.error("Exception thrown replicating object", ue);
fail("Exception thrown while copying object into second datastore : " + ue.getMessage());
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
}
// Check the persistence in the second datastore
try {
tx = pm2.currentTransaction();
tx.begin();
// Use Extent since PM may have just put object in cache.
Extent e = pm2.getExtent(JFireOrganisation.class);
Iterator iter = e.iterator();
boolean copied = false;
while (iter.hasNext()) {
JFireOrganisation o = (JFireOrganisation) iter.next();
if (pm2.getObjectId(o).equals(organisationID)) {
copied = true;
break;
}
}
assertTrue("Organisation was not copied to second datastore!", copied);
tx.commit();
} catch (JDOException ue) {
LOG.error("Exception thrown checking results", ue);
fail("Exception thrown while querying object in second datastore : " + ue.getMessage());
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
pm2.close();
}
} finally {
PersistenceManagerFactory[] pmfs = new PersistenceManagerFactory[] { pmf, pmf2 };
for (int i = 0; i < pmfs.length; ++i) {
clean(pmf, JFireOrganisation.class);
}
}
}
Aggregations