ResultSet rs = dbConnector.query("SELECT * FROM " + Company.getTableName());
if (rs.next()) {
company = new Company(this, rs);
} else {
company = getDummyCompany();
final Department d = getDummyDepartment();
final Employee e = getDummyEmployee();
final Project project = getDummyProject();
final WorkPackage workPackage = getRootWorkPackage();
dbConnector.execute("SET REFERENTIAL_INTEGRITY FALSE;",
e.toSQL(owner), company.toSQL(owner), d.toSQL(owner), project.toSQL(owner), workPackage.toSQL(owner),
"SET REFERENTIAL_INTEGRITY TRUE;");
}
employees = new HashMap<Long, Employee>();
rs = dbConnector.query("SELECT * FROM " + Employee.getTableName());
while (rs.next()) {
employees.put(rs.getLong("id"), new Employee(this, rs));
}
departments = new HashMap<Long, Department>();
rs = dbConnector.query("SELECT * FROM " + Department.getTableName());
while (rs.next()) {
departments.put(rs.getLong("id"), new Department(this, rs));
}
projects = new HashMap<Long, Project>();
rs = dbConnector.query("SELECT * FROM " + Project.getTableName());
while (rs.next()) {
projects.put(rs.getLong("id"), new Project(this, rs));
}
workPackages = new HashMap<Long, WorkPackage>();
rs = dbConnector.query("SELECT * FROM " + WorkPackage.getTableName());
while (rs.next()) {
workPackages.put(rs.getLong("id"), new WorkPackage(this, rs));
}
tasks = new HashMap<List<Long>, Task>();
rs = dbConnector.query("SELECT * FROM " + Task.getTableName());
while (rs.next()) {
Task t = new Task(this, rs);
tasks.put(t.getPrimaryKey(), t);
}
durations = new HashMap<List<Long>, Duration>();
rs = dbConnector.query("SELECT * FROM " + Duration.getTableName());
while (rs.next()) {
Duration d = new Duration(this, rs);
durations.put(d.getPrimaryKey(), d);
}
employeeProjectRelations = new RelationList<Employee, Project, EPRData, EmployeeProjectRelation>();
rs = dbConnector.query("SELECT * FROM " + EmployeeProjectRelation.getTableName());
while (rs.next()) {
employeeProjectRelations.add(new EmployeeProjectRelation(this, rs));
}
ftOverrides = new HashMap<Long, FTOverride>();
rs = dbConnector.query("SELECT * FROM " + FTOverride.getTableName());
while (rs.next()) {
ftOverrides.put(rs.getLong("id"), new FTOverride(this, rs));
}
employeeWorkPackageRelations =
new RelationList<Employee, WorkPackage, EWPRData, EmployeeWorkPackageRelation>();
rs = dbConnector.query("SELECT * FROM " + EmployeeWorkPackageRelation.getTableName());
while (rs.next()) {
employeeWorkPackageRelations.add(new EmployeeWorkPackageRelation(this, rs));
}
workPackageDependsRelations = new RelationList<WorkPackage, WorkPackage, WPDRData, WorkPackageDependsRelation>();
rs = dbConnector.query("SELECT * FROM " + WorkPackageDependsRelation.getTableName());
while (rs.next()) {
workPackageDependsRelations.add(new WorkPackageDependsRelation(this, rs));
}
checkReferentialIntegrity();
rs = dbConnector.query(SQLFormatter.generateQuery("SELECT * FROM %s WHERE timestamp = 0 AND employee = %d", Task.getTableName(), owner.getId()));
while (rs.next()) {
syncUp.addObject(new Task(null, rs));
}
rs = dbConnector.query(SQLFormatter.generateQuery("SELECT * FROM %s WHERE timestamp = 0 AND employee = %d", Duration.getTableName(), owner.getId()));
while (rs.next()) {
syncUp.addObject(new Duration(null, rs));
}
rs = dbConnector.query(SQLFormatter.generateQuery("SELECT * FROM %s WHERE timestamp = -1 AND employee = %d", Task.getTableName(), owner.getId()));
while (rs.next()) {
if (owner.getId() == company.getManagerId()) {
ProgressUtils.errorMessage("You want to remove objects as a company manager from off-line data. This is not supported.");
System.exit(1);
}
Task t = new Task(null, rs);
t.setState(Status.REMOVED);
syncUp.addObject(t);
}
rs = dbConnector.query(SQLFormatter.generateQuery("SELECT * FROM %s WHERE timestamp = -1 AND employee = %d", Duration.getTableName(), owner.getId()));
while (rs.next()) {
if (owner.getId() == company.getManagerId()) {
ProgressUtils.errorMessage("You want to remove objects as a company manager from off-line data. This is not supported.");
System.exit(1);
}
Duration d = new Duration(null, rs);
d.setState(Status.REMOVED);
syncUp.addObject(d);
}
syncUp.addObject(createTimestampTable());
synchronize();