// 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;
while (it.hasNext())
{
eff = (Effectiveness) it.next();
ver = eff.getVersion();
contract = ver.getContract();
tx.begin();
database.deletePersistent(eff);
tx.commit();
tx.begin();
database.deletePersistent(ver);
tx.commit();
tx.begin();
database.deletePersistent(contract);
tx.commit();
// keep the count
i++;
}
if (i < COUNT)
fail("Should have found at least " + COUNT + " items 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.");
}
}