File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
testFile.delete();
JODBSessionContainer sessionContainer = getContainerForFile(testFile);
ObjectB objectB = new ObjectB();
ObjectA objectA = new ObjectA((byte)1,(short)2,objectB);
ObjectA objectA2 = new ObjectA((byte)3,(byte)3,objectB);
objectB._val3 = objectA;
sessionContainer.set(objectA);
sessionContainer.set(objectA2);
sessionContainer.commit();
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
List classes = sessionContainer.getAllObjects();
if(classes.size()!=3){
throw new RuntimeException();
}
int index = classes.indexOf(objectA);
if(index == -1){
throw new RuntimeException();
}
Object obj = classes.get(index);
if(obj.getClass() != objectA.getClass()){
throw new RuntimeException();
}
ObjectA objA = (ObjectA) obj;
if(objA.getVal1() != objectA.getVal1() || objA.getVal2() != objectA.getVal2()){
throw new RuntimeException();
}
if(objA.getVal3().getClass() != objectB.getClass()){
throw new RuntimeException();
}
int bIndex = classes.indexOf(objectB);
if(bIndex == -1){
throw new RuntimeException();
}
ObjectB objectB2 = (ObjectB) classes.get(bIndex);
if(objectB2._val3 != objA){
throw new RuntimeException();
}
objA.setVal2((short) 33);
sessionContainer.set(objA);
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=3){
throw new RuntimeException();
}
index = classes.indexOf(objA);
if(index == -1){
throw new RuntimeException();
}
objA = (ObjectA) classes.get(index);
if(objA.getVal2() != 33){
throw new RuntimeException();
}
objA.setVal1((byte) 100);
objA.setVal2((short) 300);
sessionContainer.set(objA);
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
//sessionContainer.printFileMap();
classes = sessionContainer.getAllObjects();
if(classes.size()!=3){
throw new RuntimeException();
}
index = classes.indexOf(objA);
if(index == -1){
throw new RuntimeException();
}
objA = (ObjectA) classes.get(index);
if(objA.getVal1() != 100 || objA.getVal2() != 300 || objA.getVal3()==null ){
throw new RuntimeException();
}
objA.setVal1((byte) 111);
objA.setVal2((short) 333);
objA.setVal3(null);
sessionContainer.set(objA);
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
sessionContainer.printFileMap();
classes = sessionContainer.getAllObjects();
if(classes.size()!=3){
throw new RuntimeException();
}
index = classes.indexOf(objA);
if(index == -1){
throw new RuntimeException();
}
objA = (ObjectA) classes.get(index);
if(objA.getVal1() != 111 || objA.getVal2() != 333 || objA.getVal3()!=null ){
throw new RuntimeException();
}
sessionContainer.printFileMap();