public void testSwizzle2() throws TransactionException, LockingException, PBFactoryException, PersistenceBrokerException
{
clearTestData();
TestClassA a = generateTestData();
Transaction tx = _kit.getTransaction(_conn);
tx.begin();
_conn.makePersistent(a.getB());
_conn.makePersistent(a);
tx.commit();
/**
* clear to start test
*/
_conn.invalidateAll();
/**
* get A to make it and the related B in cache
*/
tx = _kit.getTransaction(_conn);
tx.begin();
Identity oid = _conn.getIdentity(a);
TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oid);
assertTrue(a1.getB() != null);
assertTrue(a1.getB().getValue1().equals("hi there"));
/**
* everything is good, update b
*/
tx.commit();
/**
* now get B and update it, do NOT get it by traversing A
*/
tx = _kit.getTransaction(_conn);
tx.begin();
Identity boid = _conn.getIdentity(a.getB());
TestClassB b1 = (TestClassB) _conn.getObjectByIdentity(boid);
assertTrue(b1 != null);
assertTrue(b1.getValue1().equals("hi there"));
/**
* everything is good, update b
*/
_conn.lockForWrite(b1);
b1.setValue1("goodbye there");
tx.commit();
/**
* make sure b was updated
*/
tx = _kit.getTransaction(_conn);
tx.begin();
boid = _conn.getIdentity(a.getB());
b1 = (TestClassB) _conn.getObjectByIdentity(boid);
assertTrue(b1 != null);
assertTrue(b1.getValue1().equals("goodbye there"));
tx.commit();
/**
* now get A again and make sure the related B is updated to reflect
* the new value.
*/
tx = _kit.getTransaction(_conn);
tx.begin();
TestClassA a2 = (TestClassA) _conn.getObjectByIdentity(oid);
assertTrue(a2.getB() != null);
assertTrue(a2.getB().getValue1().equals("goodbye there"));
tx.commit();
clearTestData();
}