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); }
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); } }
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); } }
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; }