File testFileDir = new File(_testPath+"/testData/");
testFileDir.mkdirs();
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,null);
objectB._val3 = objectA2;
sessionContainer.set(objectA);
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);
sessionContainer.delete(obj);
sessionContainer.close();
/////
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=2){
throw new RuntimeException();
}
index = classes.indexOf(objectB);
if(index == -1){
throw new RuntimeException();
}
obj = classes.get(index);
sessionContainer.delete(obj);
sessionContainer.close();
////
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=1){
throw new RuntimeException();
}
index = classes.indexOf(objectA2);
if(index == -1){
throw new RuntimeException();
}
obj = classes.get(index);
sessionContainer.delete(obj);
sessionContainer.close();
////
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=0){
throw new RuntimeException();
}
//sessionContainer.printFileMap();
sessionContainer.set(objectA);
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=3){
throw new RuntimeException();
}
index = classes.indexOf(objectA);
if(index == -1){
throw new RuntimeException();
}
obj = classes.get(index);
sessionContainer.delete(obj,Integer.MAX_VALUE);//delete all
sessionContainer.close();
////
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=0){
throw new RuntimeException();
}
//sessionContainer.printFileMap();
sessionContainer.set(objectA);
sessionContainer.close();
////
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=3){
throw new RuntimeException();
}
index = classes.indexOf(objectB);
if(index == -1){
throw new RuntimeException();
}
obj = classes.get(index);
sessionContainer.delete(obj);
//sessionContainer.printFileMap();
sessionContainer.close();
////
sessionContainer = getContainerForFile(testFile);
sessionContainer.printFileMap();
classes = sessionContainer.getAllObjects();
if(classes.size()!=2){
throw new RuntimeException();
}
index = classes.indexOf(objectA);
if(index == -1){
throw new RuntimeException();
}
obj = classes.get(index);
if( ((ObjectA)obj).getVal3()!=null){
throw new RuntimeException();
}
sessionContainer.printFileMap();
Object_Enum object_Enum = new Object_Enum();
object_Enum._val1 = TEST_ENUM.ENUM_VAL1;
sessionContainer.set(object_Enum);
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=4){
throw new RuntimeException();
}
index = classes.indexOf(object_Enum);
if(index == -1){
throw new RuntimeException();
}
obj = classes.get(index);
sessionContainer.delete(obj);
sessionContainer.commit();
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
classes = sessionContainer.getAllObjects();
if(classes.size()!=3){
throw new RuntimeException();
}
index = classes.indexOf(object_Enum);
if(index != -1){
throw new RuntimeException();
}
sessionContainer.close();
}