public void testChangeColumnTypeObjectAndSubclass() throws Exception
{
String name = "foo";
Object object = new Object();
Object subObject = new SimplestObject();
PersistenceManager pm = new PersistenceManager(driver, database, login, password);
// drop all tables
pm.dropTable(Object.class);
// create original objects
OriginalObject oo1 = new OriginalObject();
oo1.setName(name);
oo1.setValue(1);
oo1.setOtherObject(object);
pm.saveObject(oo1);
OriginalObject oo2 = new OriginalObject();
oo2.setName(name);
oo2.setValue(2);
oo2.setOtherObject(subObject);
pm.saveObject(oo2);
pm.close();
// change object to subclass
pm = new PersistenceManager(driver, database, login, password);
pm.changeName(OriginalObject.class, ObjectToSubclass.class);
pm.close();
pm = new PersistenceManager(driver, database, login, password);
pm.updateSchema(ObjectToSubclass.class);
pm.close();
//check that objects exist/not exist
pm = new PersistenceManager(driver, database, login, password);
ObjectToSubclass src = new ObjectToSubclass();
src.setValue(1);
List<ObjectToSubclass>res = pm.getObjects(ObjectToSubclass.class, new Equal(src));
assertEquals(1,res.size());
ObjectToSubclass obj = res.get(0);
assertTrue(obj.getName().equals(name));
assertNull(obj.getOtherObject());
src.setValue(2);
res = pm.getObjects(ObjectToSubclass.class, new Equal(src));
assertEquals(1,res.size());
obj = res.get(0);
assertTrue(obj.getName().equals(name));
assertNotNull(obj.getOtherObject());
//change subclass to superclass
pm = new PersistenceManager(driver, database, login, password);
pm.changeName(ObjectToSubclass.class, OriginalObject.class);
pm.close();
pm = new PersistenceManager(driver, database, login, password);
pm.updateSchema(OriginalObject.class);
List<OriginalObject>res2 = pm.getObjects(OriginalObject.class, new All());
assertEquals(2,res2.size());
pm.close();
}