private void change() throws PersistenceException {
MasterKeyGen master;
DetailKeyGen detail6, detail7, detail8, detail9;
int detailId8, detailId9;
OQLQuery oql;
QueryResults qres;
LOG.debug("Attempt to change details");
_db.begin();
master = (MasterKeyGen) _db.load(MasterKeyGen.class, new Integer(_masterId));
if (master == null) {
LOG.error("failed to find master with details group");
fail("failed to find master with details group");
}
// remove detail with id == 5
master.getDetails().remove(
master.getDetails().indexOf(master.findDetail(_detailId5)));
// remove detail with id == 6 explicitly
detail6 = master.findDetail(_detailId6);
master.getDetails().remove(master.getDetails().indexOf(detail6));
// add new detail
detail8 = new DetailKeyGen();
master.addDetail(detail8);
// add new detail and create it explicitely
detail9 = new DetailKeyGen();
master.addDetail(detail9);
// delete, then create detail with id == 7 explicitly
detail7 = master.findDetail(_detailId7);
master.getDetails().remove(master.getDetails().indexOf(detail7));
master.addDetail(detail7);
_db.commit();
detailId8 = detail8.getId();
detailId9 = detail9.getId();
_db.begin();
master = (MasterKeyGen) _db.load(MasterKeyGen.class, new Integer(_masterId));
if (master != null) {
if (master.getDetails().size() == 0
|| master.getDetails().contains(new DetailKeyGen(_detailId5))
|| master.getDetails().contains(new DetailKeyGen(_detailId6))
|| !master.getDetails().contains(new DetailKeyGen(_detailId7))
|| !master.getDetails().contains(new DetailKeyGen(detailId8))
|| !master.getDetails().contains(new DetailKeyGen(detailId9))) {
LOG.error("loaded master has wrong set of details: " + master);
fail("loaded master has wrong set of details: " + master);
} else {
LOG.debug("Details changed correctly: " + master);
}
} else {
LOG.error("master not found");
fail("master not found");
}
_db.commit();
LOG.debug("Test OQL query");
_db.begin();
oql = _db.getOQLQuery("SELECT master FROM " + MasterKeyGen.class.getName()
+ " master WHERE master.details.value1=$1");
oql.bind(Detail.DEFAULT_VALUE);
qres = oql.execute();
if (qres.hasMore()) {
LOG.debug("OK: correct result of query 1 ");
} else {
LOG.error("incorrect result of query 1 ");
fail("incorrect result of query 1");
}
oql.bind(Detail.DEFAULT_VALUE + "*");
qres = oql.execute();
if (qres.hasMore()) {
LOG.error("incorrect result of query 2 ");
fail("incorrect result of query 2");
} else {
LOG.debug("OK: correct result of query 2 ");
}
oql.close();
oql = _db.getOQLQuery("SELECT master FROM " + MasterKeyGen.class.getName()
+ " master WHERE master.details.details2.value1=$1");
oql.bind(DetailKeyGen2.DEFAULT_VALUE);
qres = oql.execute();
if (qres.hasMore()) {
LOG.debug("OK: correct result of query 3 ");
} else {
LOG.error("incorrect result of query 3 ");
fail("incorrect result of query 3");
}
oql.bind(DetailKeyGen2.DEFAULT_VALUE + "*");
qres = oql.execute();
if (qres.hasMore()) {
LOG.error("incorrect result of query 4 ");
fail("incorrect result of query 4");
} else {
LOG.debug("OK: correct result of query 4 ");
}
oql.close();
oql = _db.getOQLQuery("SELECT master FROM " + MasterKeyGen.class.getName()
+ " master WHERE master.group=$1");
oql.bind(Group.DEFAULT_ID);
qres = oql.execute();
if (qres.hasMore()) {
LOG.debug("OK: correct result of query 5 ");
} else {
LOG.error("incorrect result of query 5 ");
fail("incorrect result of query 5");
}