public void test(final Database db) throws Exception {
System.out.println("New run");
// create
Employee e = initEmployeeFirst();
Employee f = initEmployeeSecond();
Employee g = initEmployeeAdam();
Employee h = initEmployeeEve();
Employee i = initEmployeeRapheal();
db.begin();
db.create(e);
db.create(f);
db.create(g);
db.create(h);
db.create(i);
db.commit();
Integer eid = e.getId();
Integer fid = f.getId();
Integer gid = g.getId();
Integer hid = h.getId();
Integer iid = i.getId();
// update
db.begin();
e = (Employee) db.load(Employee.class, eid);
f = (Employee) db.load(Employee.class, fid);
g = (Employee) db.load(Employee.class, gid);
BigDecimal rate = new BigDecimal(1.2);
e.getHourlyRate().multiply(rate);
e.setHoliday(e.getHoliday() + 10);
e.getSkills().add("Coffee making");
f.getHourlyRate().multiply(rate);
f.setHoliday(f.getHoliday() + 10);
f.getSkills().add("Pengine traning");
g.getHourlyRate().multiply(rate);
g.setHoliday(g.getHoliday() + 10);
g.getSkills().add("farming");
db.commit();
// update
db.begin();
e = (Employee) db.load(Employee.class, eid);
f = (Employee) db.load(Employee.class, fid);
g = (Employee) db.load(Employee.class, gid);
e.getHourlyRate().multiply(rate);
e.setHoliday(e.getHoliday() + 10);
e.getSkills().add("Singing");
f.getHourlyRate().multiply(rate);
f.setHoliday(f.getHoliday() + 10);
f.getSkills().removeAllElements();
g.getHourlyRate().multiply(rate);
g.setHoliday(g.getHoliday() + 10);
db.commit();
// update
db.begin();
e = (Employee) db.load(Employee.class, eid);
f = (Employee) db.load(Employee.class, fid);
g = (Employee) db.load(Employee.class, gid);
e.setHoliday(e.getHoliday() + 15);
f.setHoliday(f.getHoliday() + 15);
g.setHoliday(g.getHoliday() + 15);
db.commit();
// update
db.begin();
e = (Employee) db.load(Employee.class, eid);
f = (Employee) db.load(Employee.class, fid);
g = (Employee) db.load(Employee.class, gid);
e.setHoliday(e.getHoliday() + 15);
f.setHoliday(f.getHoliday() + 15);
g.setHoliday(g.getHoliday() + 15);
db.commit();
// update
db.begin();
BigDecimal borderLine = new BigDecimal(10.0);
BigDecimal reducedRate = new BigDecimal(0.8);
String s = "SELECT e FROM " + Employee.class.getName() + " e "
+ "WHERE e.hourlyRate >= $1";
OQLQuery qry = db.getOQLQuery(s);
qry.bind(borderLine);
QueryResults rst = qry.execute();
while (rst.hasMore()) {
Employee overPriced = (Employee) rst.next();
overPriced.getHourlyRate().multiply(reducedRate);
}
db.commit();
rst.close();
qry.close();