示例#1
0
 private static void deleteWorkerFromHisDepartmentAndRelocateHimToNullDep(
     String workerName, Department nullDepartment) {
   Worker workerForDel = workerDAO.getByName(workerName);
   Department depForUpdate = departmentDAO.getByWorker(workerForDel);
   if (depForUpdate != null) {
     depForUpdate.removeWorker(workerForDel);
     nullDepartment.addWorker(workerForDel);
     departmentDAO.update(depForUpdate);
     departmentDAO.update(nullDepartment);
   }
 }
示例#2
0
 private static void deleteWorkerFromAnywhere(String workerName) {
   Worker workerForDel = workerDAO.getByName(workerName);
   Department depForUpdate = departmentDAO.getByWorker(workerForDel);
   if (depForUpdate != null) {
     depForUpdate.removeWorker(workerForDel);
     departmentDAO.update(depForUpdate);
   }
   workerDAO.remove(workerForDel);
 }
示例#3
0
 private static void deleteDepartmentAndRelocateWorkersToNullDep(
     String departmentName, Department nullDepartment) {
   Department depForDel = departmentDAO.getByName(departmentName);
   if (depForDel != null) {
     nullDepartment.getWorkers().addAll(depForDel.getWorkers());
     departmentDAO.remove(depForDel);
     departmentDAO.update(nullDepartment);
   }
 }
示例#4
0
  private static Worker getWorkOrCreate(
      Department currentDepartment, Department nullDepartment, String workerName) {
    Worker w = workerDAO.getByName(workerName);
    if (w == null) {
      w = new Worker(workerName);
      workerDAO.save(w);
    } else {
      Department oldWorkerDep = departmentDAO.getByWorker(w);
      if (oldWorkerDep != null) {
        oldWorkerDep.removeWorker(w);
        departmentDAO.update(oldWorkerDep);
      }
    }

    if (currentDepartment != null) {
      currentDepartment.addWorker(w);
      departmentDAO.update(currentDepartment);
    } else {
      nullDepartment.addWorker(w);
      departmentDAO.update(nullDepartment);
    }

    return w;
  }