@Test
public void testChangeColumnTypeLongAndObject() throws Exception
{
String name = "foo";
int value = 1;
Object otherObject = new SimpleObject();
Object redundantObject = new SimplestObject();
PersistenceManager pm = new PersistenceManager(driver, database, login, password);
// drop all tables
pm.dropTable(Object.class);
// create original objects
OriginalObject oo = new OriginalObject();
oo.setName(name);
oo.setValue(value);
oo.setOtherObject(otherObject);
oo.setRedundantObject(redundantObject);
pm.saveObject(oo);
pm.close();
// change object to long
pm = new PersistenceManager(driver, database, login, password);
pm.changeName(OriginalObject.class, ObjectToLong.class);
pm.close();
pm = new PersistenceManager(driver, database, login, password);
pm.updateSchema(ObjectToLong.class);
pm.close();
//check that objects exist/not exist
pm = new PersistenceManager(driver, database, login, password);
List<ObjectToLong>res = pm.getObjects(ObjectToLong.class, new All());
assertEquals(1,res.size());
ObjectToLong tmp = res.get(0);
assertTrue(tmp.getName().equals(name));
assertNull(tmp.getOtherObject());
tmp.setOtherObject(42L);
pm.saveObject(tmp);
//check that the dependent object has been dropped
List<SimpleObject>dependents = pm.getObjects(SimpleObject.class, new All());
assertEquals(0,dependents.size());
pm.close();
// change long to object
pm = new PersistenceManager(driver, database, login, password);
pm.changeName(ObjectToLong.class, OriginalObject.class);
pm.close();
pm = new PersistenceManager(driver, database, login, password);
pm.updateSchema(OriginalObject.class);
pm.close();
pm = new PersistenceManager(driver, database, login, password);
List<OriginalObject>res1 = pm.getObjects(OriginalObject.class, new All());
assertEquals(1,res1.size());
OriginalObject tmp1 = res1.get(0);
assertNull(tmp1.getOtherObject());
tmp1.setOtherObject(new SimpleObject());
pm.saveObject(tmp1);
pm.close();
}