public void testAddingWithIndex() throws Exception
{
// create a unique name:
String name = "testAddingWithIndex_" + System.currentTimeMillis();
Transaction tx = odmg.newTransaction();
tx.begin();
DList list = odmg.newDList();
database.bind(list, name);
tx.commit();
tx = odmg.newTransaction();
tx.begin();
for (int i = 0; i < 5; i++)
{
DObject a = createObject(name);
list.add(a);
}
list.add(2, createObject(name+"_pos2"));
list.add(0, createObject(name+"_pos0"));
list.add(7, createObject(name+"_pos7"));
tx.commit();
tx.begin();
((TransactionImpl) tx).getBroker().clearCache();
// System.out.println("list: " + list);
// System.out.println("lookup list: " + db.lookup(name));
tx.commit();
//System.out.println("sequence of items in list:");
Iterator iter = list.iterator();
DObject a;
while (iter.hasNext())
{
a = (DObject) iter.next();
assertNotNull(a);
//System.out.print(a.getArticleId() + ", ");
}
tx = odmg.newTransaction();
tx.begin();
((TransactionImpl) tx).getBroker().clearCache();
DList lookedUp = (DList) database.lookup(name);
// System.out.println("lookup list: " + lookedUp);
assertNotNull("database lookup does not find DList", lookedUp);
assertEquals(8, lookedUp.size());
iter = lookedUp.iterator();
while (iter.hasNext())
{
a = (DObject) iter.next();
}
tx.commit();
}