// create a unique name:
final String name = "testAdding_" + System.currentTimeMillis();
// get facade instance
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
//open database
db.open(databaseName, Database.OPEN_READ_WRITE);
Transaction tx = odmg.newTransaction();
tx.begin();
// create DList and bound by name
DList list = odmg.newDList();
db.bind(list, name);
tx.commit();
tx = odmg.newTransaction();
tx.begin();
Object obj = db.lookup(name);
tx.commit();
assertNotNull("binded DList not found", obj);
tx = odmg.newTransaction();
tx.begin();
// add objects to list
for (int i = 0; i < 5; i++)
{
DListObject a = createObject(name);
list.add(a);
}
tx.commit();
// check current list
Iterator iter = list.iterator();
while (iter.hasNext())
{
DListObject a = (DListObject) iter.next();
assertNotNull(a);
}
tx = odmg.newTransaction();
tx.begin();
((TransactionExt) odmg.currentTransaction()).getBroker().clearCache();
// lookup list and check entries
DList lookedUp = (DList) db.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())
{
DListObject a = (DListObject) iter.next();
DListObject b = (DListObject) iter1.next();
assertNotNull(a);
assertNotNull(b);
assertEquals(a.getId(), b.getId());
}
tx.commit();
// add new entries to list
tx.begin();
for (int i = 0; i < 3; i++)
{
DListObject a = createObject(name + "_new_entry");
list.add(a);
}
tx.commit();
tx = odmg.newTransaction();
tx.begin();
((TransactionExt) odmg.currentTransaction()).getBroker().clearCache();
lookedUp = (DList) db.lookup(name);
iter = lookedUp.iterator();
iter1 = list.iterator();
assertEquals("Wrong number of DListEntry found", 8, list.size());
while (iter.hasNext())
{