Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public static boolean demanderVoyance(Voyance voy){
  2. if (voy==null) { return false; }
  3.  
  4. JpaUtil.creerEntityManager();
  5. JpaUtil.ouvrirTransaction();
  6.  
  7. EmployeDAO employeDAO = new EmployeDAO();
  8. VoyanceDAO voyanceDAO = new VoyanceDAO();
  9. voyanceDAO.persistVoyance(voy);
  10. List<Employe> emps = voy.getMedium().getIncarnations();
  11. Employe e=null;
  12. Integer size = Integer.MAX_VALUE;
  13. for(Employe emp : emps){
  14. List<Voyance> voys = voyanceDAO.historiqueEmploye(emp);
  15. if(voys.size()<size && !emp.estOccupe()){
  16. e = emp;
  17. size = voys.size();
  18. }
  19. }
  20. if (e!=null){
  21. voy.setEmploye(e);
  22. e.setVoyance(voy);
  23. try {
  24. employeDAO.mergeEmploye(e);
  25. voyanceDAO.mergeVoyance(voy);
  26.  
  27. JpaUtil.validerTransaction();
  28. } catch(Exception exc){
  29. JpaUtil.annulerTransaction();
  30. voy.setEmploye(null);
  31. e.setVoyance(null);
  32. e=null;
  33. }
  34. } else {
  35. JpaUtil.annulerTransaction();
  36. }
  37. JpaUtil.fermerEntityManager();
  38. return e!=null;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement