Ejemplo n.º 1
0
 public List<Order> getAllOrders() {
   EntityManager em = pm.createEntityManager();
   List<Order> order =
       (ArrayList<Order>) em.createNamedQuery(Order.GET_ALL, Order.class).getResultList();
   pm.closeEntityManager(em);
   return order;
 }
Ejemplo n.º 2
0
 public void persistOrder(Order order) {
   EntityManager em = pm.createEntityManager();
   em.getTransaction().begin();
   em.persist(order);
   em.getTransaction().commit();
   pm.closeEntityManager(em);
 }
Ejemplo n.º 3
0
 public void updateOrder(Order order) {
   if (order == null) {
     throw new ValidationException("null value passed");
   }
   EntityManager em = pm.createEntityManager();
   em.merge(order);
   pm.closeEntityManager(em);
 }
Ejemplo n.º 4
0
 public Order findByOrderID(int OrderID) {
   EntityManager em = pm.createEntityManager();
   TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_ORDER_ID, Order.class);
   tq.setParameter("order_id", OrderID);
   pm.closeEntityManager(em);
   try {
     return tq.getSingleResult();
   } catch (NoResultException nre) {
     return null;
   }
 }
Ejemplo n.º 5
0
  public Order findByStatusAndId(OrderStatus status, int customerId) {

    EntityManager em = pm.createEntityManager();
    TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_STATUS_AND_ID, Order.class);
    tq.setParameter("status", status);
    tq.setParameter("customer", customerId);
    pm.closeEntityManager(em);
    try {
      return tq.getSingleResult();
    } catch (NoResultException nre) {
      return null;
    }
  }
Ejemplo n.º 6
0
  public Order findBasketByUserId(OrderStatus status, LoginDetails customer) {

    EntityManager em = pm.createEntityManager();
    TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_STATUS_AND_ID, Order.class);
    tq.setParameter("status", status);
    tq.setParameter("customerId", customer);
    try {
      return tq.getSingleResult();
    } catch (NoResultException nre) {
      return null;
    } finally {
      pm.closeEntityManager(em);
    }
  }
Ejemplo n.º 7
0
  public List<Order> findByDatePlaced(String datePlaced) {
    List<Order> orders = new ArrayList<Order>();

    EntityManager em = pm.createEntityManager();
    TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_DATE_PLACED, Order.class);
    tq.setParameter("datePlaced", datePlaced);
    pm.closeEntityManager(em);
    try {
      orders = (ArrayList<Order>) tq.getResultList();
    } catch (NoResultException nre) {
      return null;
    }

    return orders;
  }
Ejemplo n.º 8
0
  public List<Order> findByStatus(OrderStatus status) {
    List<Order> orders = new ArrayList<Order>();

    EntityManager em = pm.createEntityManager();
    TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_STATUS, Order.class);
    tq.setParameter("status", status);
    pm.closeEntityManager(em);
    try {
      orders = (ArrayList<Order>) tq.getResultList();
    } catch (NoResultException nre) {
      return null;
    }

    return orders;
  }
Ejemplo n.º 9
0
  public List<Order> findByEmployeeId(int employeeId) {
    List<Order> orders = new ArrayList<Order>();

    EntityManager em = pm.createEntityManager();
    TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_EMPLOYEE_ID, Order.class);
    tq.setParameter("employee_id", employeeId);
    pm.closeEntityManager(em);
    try {
      orders = (ArrayList<Order>) tq.getResultList();
    } catch (NoResultException nre) {
      return null;
    }

    return orders;
  }
Ejemplo n.º 10
0
  public List<Order> findByCustomerId(int customerId) {
    List<Order> orders = new ArrayList<Order>();

    EntityManager em = pm.createEntityManager();
    TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_CUSTOMER_ID, Order.class);
    tq.setParameter("customer_id", customerId);
    pm.closeEntityManager(em);
    try {
      orders = (ArrayList<Order>) tq.getResultList();
    } catch (NoResultException nre) {
      return null;
    }

    return orders;
  }
Ejemplo n.º 11
0
  public List<Order> findByTwoDatesOrderDelivered(String firstDate, String secondDate) {
    List<Order> orders = new ArrayList<Order>();

    EntityManager em = pm.createEntityManager();
    TypedQuery<Order> tq = em.createNamedQuery(Order.FIND_BY_TWO_DATES_DELIVERED, Order.class);
    tq.setParameter("fDate", firstDate);
    tq.setParameter("sDate", secondDate);
    pm.closeEntityManager(em);
    try {
      orders = (ArrayList<Order>) tq.getResultList();
    } catch (NoResultException nre) {
      return null;
    }

    return orders;
  }