Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public List<Pilot> findPiloteByName(String name) {
- Root<Pilot> root;
- Expression<String> nameRoot;
- CriteriaBuilder cb = em.getCriteriaBuilder();
- CriteriaQuery<Pilot> cq = cb.createQuery(Pilot.class);
- root = cq.from(Pilot.class);
- cq.select(root);
- nameRoot=root.get("name");
- cq.where(cb.like(nameRoot,name));
- return em.createQuery(cq).getResultList();
- }
- /**
- * Read all the pilots using @NamedQuery from DB
- * @return returning a list of the all pilots
- */
- @Override
- public List<Pilot> catchThemAllPilot() {
- TypedQuery<Pilot> query =
- em.createNamedQuery("Pilot.findAll", Pilot.class);
- List<Pilot> results = query.getResultList();
- return results;
- }
- /**
- * Find Plane By name - finding a plane by name in SQL
- * using a CriteriaBuilder and CriteriaQuery
- * @param name name of the plane
- * @return returning a needed information about Plane
- */
- @Override
- public List<Plane> findPlaneByName(String name) {
- Root<Plane> root;
- Expression<String> nameRoot;
- CriteriaBuilder cb = em.getCriteriaBuilder();
- CriteriaQuery<Plane> cq = cb.createQuery(Plane.class);
- root = cq.from(Plane.class);
- cq.select(root);
- nameRoot=root.get("name");
- cq.where(cb.like(nameRoot,name));
- return em.createQuery(cq).getResultList();
- }
- /**
- * Read all the planes using @NamedQuery from DB
- *
- * @return returning a list of the all planes
- */
- @Override
- public List<Plane> catchThemAllPlane() {
- TypedQuery<Plane> query =
- em.createNamedQuery("Pilot.findAllPlanes", Plane.class);
- List<Plane> results = query.getResultList();
- return results;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement