// 3. Get a list of some articles
Transaction tx = odmg.newTransaction();
OQLQuery query = odmg.newOQLQuery();
ManageableCollection all = null;
java.util.Iterator it = null;
int i = 0;
query.create("select effectiveness from " + org.apache.ojb.broker.Effectiveness.class.getName());
/**
* try doing this as part of one transaction, ODMG should figure out
* which order to delete in.
*/
all = (ManageableCollection) query.execute();
// Iterator over the restricted articles objects
it = all.ojbIterator();
Effectiveness eff = null;
Version ver = null;
Contract contract = null;
/**
* should mark all these objects for delete then on commit
* ODMG should make sure they get deleted in proper order
*/
tx.begin();
while (it.hasNext())
{
eff = (Effectiveness) it.next();
ver = eff.getVersion();
contract = ver.getContract();
/**
* should mean that version and effectivedate are cascade deleted.
*/
database.deletePersistent(contract);
i++;
}
/**
* commit all changes.
*/
tx.commit();
if (i < COUNT)
fail("Should have found at least " + COUNT + " effectiveness to delete, only found " + i);
/**
* run query again, should get 0 results.
*/
query.create("select contracts from " + org.apache.ojb.broker.Contract.class.getName());
ManageableCollection allContracts = (ManageableCollection) query.execute();
allContracts = (ManageableCollection) query.execute();
it = allContracts.ojbIterator();
if (it.hasNext())
{
fail("all contracts should have been removed, we found one.");
}
}