@Test
public void testUpdateComplex() throws Exception
{
PersistenceManager persist = new PersistenceManager(driver, database, login, password);
// create a complex object
ComplexObject object = new ComplexObject();
Integer[] ages = new Integer[] { 1, 2, 3 };
object.setObject(ages);
// save it
persist.saveObject(object);
// make sure only one object exists
List<ComplexObject> allObjects = persist.getObjectsMatching(new ComplexObject());
assertEquals(1, allObjects.size());
// change the object
ages[1] = 20;
// save the object again
persist.saveObject(object);
// make sure there's still only one object
allObjects = persist.getObjectsMatching(new ComplexObject());
assertEquals(1, allObjects.size());
// re-open the database connection
persist.close();
persist = new PersistenceManager(driver, database, login, password);
// make sure the object has been changed
allObjects = persist.getObjectsMatching(new ComplexObject());
assertEquals(1, allObjects.size());
ComplexObject first = allObjects.get(0);
Integer[] databaseAges = (Integer[]) first.getObject();
assertEquals(1, (int) databaseAges[0]);
assertEquals(20, (int) databaseAges[1]);
assertEquals(3, (int) databaseAges[2]);
assertTrue(databaseAges.length == 3);
// add another object
ComplexObject nuObject = new ComplexObject();
Integer[] nuAges = new Integer[] { 5, 6, 7 };
nuObject.setObject(nuAges);
persist.saveObject(nuObject);
// update the new object
nuAges[1] = 60;
// make sure only one object has been modified
allObjects = persist.getObjectsMatching(new ComplexObject());
assertEquals(2, allObjects.size());
first = allObjects.get(0);
ComplexObject second = allObjects.get(1);
Integer[] a = (Integer[]) first.getObject();
Integer[] b = (Integer[]) second.getObject();
assertTrue((a[0] == 1 && b[0] == 5) || (b[0] == 1 && a[0] == 5));
assertTrue((a[1] == 20 && b[1] == 60) || (b[1] == 20 && a[1] == 60));
assertTrue((a[2] == 3 && b[2] == 7) || (b[2] == 3 && a[2] == 7));