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