*/
@Test
public void testChangeSubclassing() throws Exception
{
PersistenceManager pm = new PersistenceManager(driver, database, login, password);
// drop all tables
pm.dropTable(Object.class);
// create two OriginalObject, store them.
pm.saveObject(new OriginalObject());
pm.saveObject(new OriginalObject());
// create two NotSubClass, store them
NotSubClass ns = new NotSubClass();
ns.setName("foo");
pm.saveObject(ns);
ns = new NotSubClass();
ns.setName("bar");
pm.saveObject(ns);
pm.close();
pm = new PersistenceManager(driver, database, login, password);
// rename NotSubClass to SubClass
pm.changeName(NotSubClass.class, SubClass.class);
pm.close();
pm = new PersistenceManager(driver, database, login, password);
// change the database schema
pm.updateSchema(SubClass.class);
// search all SubClass, make sure both objects are returned
List<SubClass> res2 = pm.getObjects(SubClass.class, new All());
assertEquals(2, res2.size());
// search all OriginalObject, make sure all objects are returned.
List<OriginalObject> res3 = pm.getObjects(OriginalObject.class, new All());
assertEquals(4, res3.size());
// search all OriginalObject with name "foo", make sure SubClass
// objects are returned.
OriginalObject searchObject = new OriginalObject();
searchObject.setName("foo");
res3 = pm.getObjects(OriginalObject.class, new Equal(searchObject));
assertEquals(1, res3.size());
for (OriginalObject oo : res3)
{
assertTrue(oo instanceof SubClass);
}
// rename SubClass to to NotSubClass
pm.changeName(SubClass.class, NotSubClass.class);
// change the database schema
pm.updateSchema(NotSubClass.class);
// search all OriginalObject, make sure both objects are returned.
res3 = pm.getObjects(OriginalObject.class, new All());
assertEquals(2, res3.size());
// search all NotSubClass, make sure both objects are returned
List<NotSubClass> res1 = pm.getObjects(NotSubClass.class, new All());
assertEquals(2, res1.size());
// search NotSubClass, make sure only matchign object is returned
NotSubClass searchObject2 = new NotSubClass();
searchObject2.setName("foo");
res1 = pm.getObjects(NotSubClass.class, new Equal(searchObject2));
assertEquals(1, res1.size());
pm.close();
// TODO: Test changing inheritance of an object that is a property of
// another object
}