ErrorObject.setExceptionsEnabled(true);
Connection conn = dbResource.getConnection();
DBDatabaseDriver driver = dbResource.newDriver();
CompanyDB db = new CompanyDB();
db.open(driver, dbResource.getConnection());
DBSQLScript script = new DBSQLScript();
db.getCreateDDLScript(db.getDriver(), script);
script.run(db.getDriver(), dbResource.getConnection(), false);
DBRecord dep = new DBRecord();
dep.create(db.DEPARTMENT);
dep.setValue(db.DEPARTMENT.NAME, "junit");
dep.setValue(db.DEPARTMENT.BUSINESS_UNIT, "test");
dep.update(conn);
Date date = dep.getDateTime(db.DEPARTMENT.UPDATE_TIMESTAMP);
assertNotNull("Date is null", date);
assertTrue("No departments", dep.getInt(db.DEPARTMENT.ID) > 0);
DBRecord emp = new DBRecord();
emp.create(db.EMPLOYEE);
emp.setValue(db.EMPLOYEE.FIRSTNAME, "junit");
emp.setValue(db.EMPLOYEE.LASTNAME, "test");
emp.setValue(db.EMPLOYEE.GENDER, "m");
emp.setValue(db.EMPLOYEE.DEPARTMENT_ID, dep.getInt(db.DEPARTMENT.ID));
emp.update(conn);
date = emp.getDateTime(db.EMPLOYEE.UPDATE_TIMESTAMP);
assertNotNull("Date is null", date);
assertTrue("Employee id O or less", emp.getInt(db.EMPLOYEE.ID) > 0);
int id = emp.getInt(db.EMPLOYEE.ID);
// Update an Employee
emp = new DBRecord();
emp.read(db.EMPLOYEE, id, conn);
// Set
emp.setValue(db.EMPLOYEE.PHONE_NUMBER, "123456");
emp.update(conn);
emp = new DBRecord();
emp.read(db.EMPLOYEE, id, conn);
assertEquals("123456", emp.getString(db.EMPLOYEE.PHONE_NUMBER));
script = new DBSQLScript();
db.getDriver().getDDLScript(DBCmdType.DROP, db.EMPLOYEE, script);
db.getDriver().getDDLScript(DBCmdType.DROP, db.DEPARTMENT, script);
script.run(db.getDriver(), conn, true);
}