public void classTypeConstraints(boolean reopen) throws Exception{
File testFileDir = new File(TEST_DATA_DIR);
testFileDir.mkdirs();
File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
testFile.delete();
JODBSessionContainer sessionContainer = getContainerForFile(testFile);
ObjectA objectA = new ObjectA((byte)2,(byte)3,null);
ObjectB objectB = new ObjectB();
objectB._val3 = objectA;
sessionContainer.set(objectA);
sessionContainer.set(objectB);
sessionContainer.commit();
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
List list = sessionContainer.query(ObjectA.class);
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectA.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
Query query = sessionContainer.query();
query.constrain(ObjectA.class);
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectA.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
query.constrain(ObjectA.class).not();
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectB.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
query.constrain(ObjectA.class).or(query.constrain(ObjectB.class));
list = query.execute();
if(list.size()!=2){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
query.constrain(ObjectA.class).or(query.constrain(ObjectB.class).not());
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectA.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
query.descend("_val3").constrain(ObjectA.class);
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectB.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
query.descend("_val3").constrain(ObjectB.class);
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectA.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
query.descend("_val3").constrain(ObjectA.class);
query.descend("_val2").constrain(short.class);
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectB.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
Constraint constraint = query.descend("_val3").constrain(ObjectB.class);
query.descend("_val2").constrain(short.class).or(constraint);
list = query.execute();
if(list.size()!=2){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
constraint = query.descend("_val3").constrain(ObjectB.class);
query.descend("_val2").constrain(short.class);
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectA.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
constraint = query.descend("_val3").constrain(ObjectB.class);
query.descend("_val2").constrain(int.class).or(constraint);
list = query.execute();
if(list.size()!=1){
throw new RuntimeException();
}
if(list.get(0).getClass() != ObjectA.class){
throw new RuntimeException();
}
if(reopen){
sessionContainer.close();
sessionContainer = getContainerForFile(testFile);
}
query = sessionContainer.query();
constraint = query.descend("_val3").constrain(ObjectB.class);
query.descend("_val2").constrain(int.class).and(constraint);
list = query.execute();
if(list.size()!=0){
throw new RuntimeException();
}
sessionContainer.close();
}