WriteIntersectingFactory factory = new WriteIntersectingFactory();
JODBConfig.setRandomAccessBufferFactory(factory);
JODBSessionContainer sessionContainer = getContainerForFile(testFile);
int dataEntries = sessionContainer.getDatabaseStatistics().totalDataEntries();
StringBuffer className = new StringBuffer("TestClass");
final int testIndexStart = 100;
int testIndex = testIndexStart;
int totalWritten = 0;
Object object = null;
int newTableCreationIOCalls = 0;
while(dataEntries < 2 && className.length() < 0xFFFF){
factory.intersectionInit(null, Integer.MAX_VALUE, false);
factory.setIntersectEnabled(true);
className.append("Test"+testIndex);
DynamicTestClass dynamicTestClass = new DynamicTestClass(className.toString(),testIndex);
object = dynamicTestClass.load(sessionContainer);
totalWritten++;
testIndex++;
sessionContainer.set(object);
sessionContainer.commit();
newTableCreationIOCalls = factory._counter;
if(closeAfterCommit){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
sessionContainer.setClassLoader(dynamicTestClass._classLoader);
}
dataEntries = sessionContainer.getDatabaseStatistics().totalDataEntries();
dynamicTestClass.delete();
}
if(dataEntries!=2){
throw new RuntimeException();
}
List list = sessionContainer.getAllObjects();
if(list.size()!=totalWritten){
throw new RuntimeException();
}
int index = list.indexOf(object);
if(index == -1){
throw new RuntimeException();
}
DynamicTestClass dynamicTestClass = new DynamicTestClass(className.toString(),testIndex);
object = dynamicTestClass.load(sessionContainer);
totalWritten++;
testIndex++;
sessionContainer.set(object);
sessionContainer.commit();
if(closeAfterCommit){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
sessionContainer.setClassLoader(dynamicTestClass._classLoader);
}
dataEntries = sessionContainer.getDatabaseStatistics().totalDataEntries();
dynamicTestClass.delete();
if(dataEntries!=2){
throw new RuntimeException();
}
list = sessionContainer.getAllObjects();
if(list.size()!=totalWritten){
throw new RuntimeException();
}
index = list.indexOf(object);
if(index == -1){
throw new RuntimeException();
}
sessionContainer.close();
className = new StringBuffer("TestClass");
testIndex = testIndexStart;
testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
testFile.delete();
sessionContainer = getContainerForFile(testFile);
sessionContainer.setClassLoader(dynamicTestClass._classLoader);
for (int i = 0 ; i < totalWritten-2; i++) {
className.append("Test"+testIndex);
dynamicTestClass = new DynamicTestClass(className.toString(),testIndex);
object = dynamicTestClass.load(sessionContainer);
testIndex++;
sessionContainer.set(object);
sessionContainer.commit();
if(closeAfterCommit){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
sessionContainer.setClassLoader(dynamicTestClass._classLoader);
}
dataEntries = sessionContainer.getDatabaseStatistics().totalDataEntries();
dynamicTestClass.delete();
}
if(dataEntries!=1){
throw new RuntimeException();
}
className.append("Test"+testIndex);
dynamicTestClass = new DynamicTestClass(className.toString(),testIndex);
object = dynamicTestClass.load(sessionContainer);
for (int i = 0; i < newTableCreationIOCalls; i++) {
factory.intersectionInit(null, i, true);
factory.setIntersectEnabled(true);
sessionContainer.set(object);
try {
sessionContainer.commit();
break;
} catch (IOException e) {
e.printStackTrace();
}
factory.setIntersectEnabled(false);
if (factory._bufferedType == BUFFER_TYPE.MAIN) {
byte[] incompleteTransaction = factory.getBuffer();
verifyDataReadable(incompleteTransaction, null,totalWritten-2,totalWritten-1);
}
List classes = sessionContainer.getAllObjects();
if(classes.size()!=totalWritten-2){
throw new RuntimeException();
}
if(sessionContainer.getDatabaseStatistics().totalDataEntries()!=1){
throw new RuntimeException();
}
}
factory.setIntersectEnabled(false);
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
sessionContainer.setClassLoader(dynamicTestClass._classLoader);
sessionContainer.set(object);
sessionContainer.commit();
testIndex++;
dynamicTestClass.delete();
className.append("Test"+testIndex);
dynamicTestClass = new DynamicTestClass(className.toString(),testIndex);
object = dynamicTestClass.load(sessionContainer);
for (int i = 0; i < Integer.MAX_VALUE; i++) {
factory.intersectionInit(null, i, true);
factory.setIntersectEnabled(true);
sessionContainer.set(object);
try {
sessionContainer.commit();
break;
} catch (Exception e) {
e.printStackTrace();
}
factory.setIntersectEnabled(false);
if (factory._bufferedType == BUFFER_TYPE.MAIN) {
byte[] incompleteTransaction = factory.getBuffer();
verifyDataReadable(incompleteTransaction, null,totalWritten,totalWritten+1);
}
List classes = sessionContainer.getAllObjects();
if(classes.size()!=totalWritten){
throw new RuntimeException();
}
if(sessionContainer.getDatabaseStatistics().totalDataEntries()!=2){
throw new RuntimeException();
}
}
factory.setIntersectEnabled(false);
dynamicTestClass.delete();
sessionContainer.close();
}