lock childs first, then lock father
TODO: Does not pass - why? A defined lock
order necessary?
if this doesn't make sense remove the test
*/
Transaction tx = odmg.newTransaction();
tx.begin();
tx.lock(child_1, Transaction.WRITE);
tx.lock(child_2, Transaction.WRITE);
tx.lock(father, Transaction.WRITE);
tx.commit();
// without running tx, should not take effect
father.setChildren(null);
father.setFirstname(null);
tx.begin();
// make sure all objects are retrieved freshly in subsequent transactions
((TransactionImpl) tx).getBroker().clearCache();
OQLQuery qry = odmg.newOQLQuery();
qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
qry.bind(firstnameFather);
Collection result = (Collection) qry.execute();
assertEquals("Exactly one element in result set", 1, result.size());
Person returnedFather = (Person) result.iterator().next();
// should retrieve new instance, cause we clear the cache
assertTrue("not same", returnedFather != father);
Person[] returnedChildren = returnedFather.getChildren();
assertNotNull(returnedChildren);
assertEquals(2, returnedChildren.length);
Person child = returnedChildren[0];
Person lookupFather = child.getFather();
assertNotNull(lookupFather);
assertEquals(returnedFather.getFirstname(), lookupFather.getFirstname());
// unfortunately, PersonImpl does not have a suitable equals method.
assertEquals(
"children's names are equal",
Arrays.asList(getFirstNames(returnedChildren)),
Arrays.asList(getFirstNames(children)));
// System.out.println(Arrays.asList(getFirstNames(returnedChildren)));
tx.commit();
/*
delete father then children
fk-constraints?
*/
tx.begin();
database.deletePersistent(returnedFather.getChildren()[0]);
database.deletePersistent(returnedFather.getChildren()[1]);
database.deletePersistent(returnedFather);
tx.commit();
qry = odmg.newOQLQuery();
qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
qry.bind(firstnameFather);
result = (Collection) qry.execute();