tx.commit();
tx.begin();
tx.getBroker().clearCache();
OQLQuery query = odmg.newOQLQuery();
query.create("select products from " + Shop.class.getName() + " where name like $1");
query.bind(name + "%");
Collection result = (Collection) query.execute();
tx.commit();
assertEquals(1, result.size());
Shop newShop = (Shop) result.iterator().next();
assertNotNull(newShop.getProducts());
assertEquals(2, newShop.getProducts().size());
boolean match = false;
for(Iterator iterator = newShop.getProducts().iterator(); iterator.hasNext();)
{
Product p = (Product) iterator.next();
if(p.getSubProducts() != null && p.getSubProducts().size() > 0)
{
match = true;
assertEquals(3, p.getSubProducts().size());
}
}
assertTrue("Sub products aren't stored", match);
tx.begin();
database.deletePersistent(s);
tx.commit();
tx.begin();
tx.getBroker().clearCache();
query = odmg.newOQLQuery();
query.create("select products from " + Product.class.getName() + " where name like $1");
query.bind(name + "_subPro%");
result = (Collection) query.execute();
tx.commit();
assertEquals(3, result.size());
tx.begin();
query = odmg.newOQLQuery();
query.create("select products from " + Product.class.getName() + " where name like $1");
query.bind(name + "_product_1");
result = (Collection) query.execute();
assertEquals(1, result.size());
database.deletePersistent(result.iterator().next());
tx.commit();
tx.begin();
tx.getBroker().clearCache();
query = odmg.newOQLQuery();
query.create("select products from " + Product.class.getName() + " where name like $1");
query.bind(name + "_subPro%");
result = (Collection) query.execute();
tx.commit();
assertEquals(3, result.size());
}