_db = _category.getDatabase();
}
public void runTest() throws PersistenceException {
OQLQuery oql;
QueryResults results;
NestedObject t;
// Open transaction in order to perform JDO operations
_db.begin();
oql = _db.getOQLQuery("SELECT t FROM "
+ NestedObject.class.getName() + " t WHERE id = $1");
oql.bind(NestedObject.DEFAULT_ID);
results = oql.execute();
if (results.hasMore()) {
t = (NestedObject) results.next();
_db.remove(t);
LOG.debug("Deleting object: " + t);
}
_db.commit();
_db.begin();
t = new NestedObject();
LOG.debug("Creating new object: " + t);
_db.create(t);
_db.commit();
_db.begin();
oql.bind(NestedObject.DEFAULT_ID);
results = oql.execute();
if (results.hasMore()) {
t = (NestedObject) results.next();
String nv1 = t.getNested1().getValue1();
String nv2 = t.getNested2().getNested3().getValue2();
if (NestedObject.DEFAULT_VALUE1.equals(nv1)
&& NestedObject.DEFAULT_VALUE2.equals(nv2)) {
LOG.debug("OK: Created object: " + t);
} else {
LOG.error("Creating object: " + t);
fail("Creating object failed");
}
}
_db.commit();
oql.close();
LOG.info("Testing nested fields in OQLQuery...");
_db.begin();
oql = _db.getOQLQuery("SELECT t FROM "
+ NestedObject.class.getName()
+ " t WHERE nested2.nested3.value2 = $1");
oql.bind(NestedObject.DEFAULT_VALUE2);
results = oql.execute();
if (results.hasMore()) {
LOG.info("OK: Nested fields persisted");
} else {
LOG.error("Failed to persist nested fields");
fail("Failed to persist nested fields");
}