Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. @Override
  2. public List<Pilot> findPiloteByName(String name) {
  3. Root<Pilot> root;
  4. Expression<String> nameRoot;
  5. CriteriaBuilder cb = em.getCriteriaBuilder();
  6. CriteriaQuery<Pilot> cq = cb.createQuery(Pilot.class);
  7. root = cq.from(Pilot.class);
  8. cq.select(root);
  9. nameRoot=root.get("name");
  10. cq.where(cb.like(nameRoot,name));
  11. return em.createQuery(cq).getResultList();
  12. }
  13. /**
  14. * Read all the pilots using @NamedQuery from DB
  15. * @return returning a list of the all pilots
  16. */
  17. @Override
  18. public List<Pilot> catchThemAllPilot() {
  19. TypedQuery<Pilot> query =
  20. em.createNamedQuery("Pilot.findAll", Pilot.class);
  21. List<Pilot> results = query.getResultList();
  22.  
  23. return results;
  24. }
  25. /**
  26. * Find Plane By name - finding a plane by name in SQL
  27. * using a CriteriaBuilder and CriteriaQuery
  28. * @param name name of the plane
  29. * @return returning a needed information about Plane
  30. */
  31. @Override
  32. public List<Plane> findPlaneByName(String name) {
  33. Root<Plane> root;
  34. Expression<String> nameRoot;
  35. CriteriaBuilder cb = em.getCriteriaBuilder();
  36. CriteriaQuery<Plane> cq = cb.createQuery(Plane.class);
  37. root = cq.from(Plane.class);
  38. cq.select(root);
  39. nameRoot=root.get("name");
  40. cq.where(cb.like(nameRoot,name));
  41.  
  42. return em.createQuery(cq).getResultList();
  43. }
  44. /**
  45. * Read all the planes using @NamedQuery from DB
  46. *
  47. * @return returning a list of the all planes
  48. */
  49. @Override
  50. public List<Plane> catchThemAllPlane() {
  51. TypedQuery<Plane> query =
  52. em.createNamedQuery("Pilot.findAllPlanes", Plane.class);
  53. List<Plane> results = query.getResultList();
  54. return results;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement