final String name = "testRemoveAdd_" + System.currentTimeMillis();
TransactionExt tx = (TransactionExt) odmg.newTransaction();
tx.begin();
// create DList and bound by name
DList list = odmg.newDList();
database.bind(list, name);
// add object to list
for (int i = 0; i < 5; i++)
{
DObject a = createObject(name);
list.add(a);
}
tx.commit();
// check current list
Iterator iter = list.iterator();
while (iter.hasNext())
{
DObject a = (DObject) iter.next();
assertNotNull(a);
}
tx.begin();
tx.getBroker().clearCache();
// lookup list and check entries
DList lookedUp = (DList) database.lookup(name);
assertNotNull("binded DList not found", lookedUp);
//System.out.println("sequence of items in lookedup list:");
iter = lookedUp.iterator();
Iterator iter1 = list.iterator();
while (iter.hasNext())
{
DObject a = (DObject) iter.next();
DObject b = (DObject) iter1.next();
assertNotNull(a);
assertNotNull(b);
assertEquals(a.getId(), b.getId());
}
tx.commit();
// add and remove new entries
tx.begin();
for (int i = 0; i < 3; i++)
{
DObject a = createObject(name + "_new_entry_NOT_PERSIST");
list.add(a);
list.remove(list.size()-1);
}
tx.commit();
tx.begin();
tx.getBroker().clearCache();
lookedUp = (DList) database.lookup(name);
iter = lookedUp.iterator();
iter1 = list.iterator();
assertEquals("Wrong number of DListEntry found", 5, list.size());
while (iter.hasNext())
{
DObject a = (DObject) iter.next();
DObject b = (DObject) iter1.next();
assertNotNull(a);
assertNotNull(b);
assertEquals(a.getId(), b.getId());
}
tx.commit();
assertNotNull("binded DList not found", lookedUp);
tx.begin();
for (int i = 0; i < 3; i++)
{
DObject a = createObject(name + "_new_entry_new_persist");
list.add(a);
list.remove(0);
}
tx.commit();
tx.begin();
tx.getBroker().clearCache();
lookedUp = (DList) database.lookup(name);
iter = lookedUp.iterator();
iter1 = list.iterator();
assertEquals("Wrong number of DListEntry found", 5, list.size());
while (iter.hasNext())
{
DObject a = (DObject) iter.next();