コード例 #1
0
 public OrderPurchase createNewOrder(OrderPurchase orderPurchase) {
   if (orderPurchase.getDateCreate() == null) {
     orderPurchase.setDateCreate(new Date());
   }
   orderPurchase.setDateUpdate(new Date());
   if (orderPurchase.getId() == null) {
     orderPurchase = createNewOrderWithRightOrderNumber(orderPurchase);
   }
   return orderPurchase;
 }
コード例 #2
0
  public OrderPurchase getOrderByOrderNum(final String orderNum, Object... params) {
    Criteria criteria = createDefaultCriteria(OrderPurchase.class);

    FetchPlan fetchPlan = handleSpecificOrderFetchMode(criteria, params);

    criteria.add(Restrictions.eq("orderNum", orderNum));
    OrderPurchase orderPurchase = (OrderPurchase) criteria.uniqueResult();
    if (orderPurchase != null) {
      orderPurchase.setFetchPlan(fetchPlan);
    }
    return orderPurchase;
  }
コード例 #3
0
 public void setLastOrder(OrderPurchase lastOrder) {
   if (lastOrders != null && Hibernate.isInitialized(lastOrders) && lastOrder != null) {
     for (OrderPurchase orderPurchase : lastOrders) {
       if (orderPurchase != null
           && getCurrentMarketArea() != null
           && getCurrentMarketAreaRetailer() != null
           && orderPurchase.getMarketAreaId().equals(getCurrentMarketArea().getId())
           && orderPurchase.getRetailerId().equals(getCurrentMarketAreaRetailer().getId()))
         lastOrders.remove(orderPurchase);
     }
     lastOrders.add(lastOrder);
   }
 }
コード例 #4
0
 public OrderPurchase getLastOrder() {
   if (lastOrders != null && Hibernate.isInitialized(lastOrders)) {
     for (OrderPurchase orderPurchase : lastOrders) {
       if (orderPurchase != null
           && getCurrentMarketArea() != null
           && getCurrentMarketAreaRetailer() != null
           && orderPurchase.getMarketAreaId().equals(getCurrentMarketArea().getId())
           && orderPurchase.getRetailerId().equals(getCurrentMarketAreaRetailer().getId()))
         return orderPurchase;
     }
   }
   return null;
 }
コード例 #5
0
  protected OrderPurchase createNewOrderWithRightOrderNumber(final OrderPurchase orderPurchase) {
    OrderPurchase mergedOrSavedOrderPurchase = null;
    try {
      Session session = (Session) em.getDelegate();
      String hql = "FROM OrderNumber";
      Query query = session.createQuery(hql);
      OrderNumber orderNumber = (OrderNumber) query.uniqueResult();
      Integer previousLastOrderNumber = orderNumber.getLastOrderNumber();
      Integer newLastOrderNumber = orderNumber.getLastOrderNumber() + 1;

      orderPurchase.setPrefixHashFolder(CoreUtil.generateEntityCode());
      orderPurchase.setOrderNum("" + newLastOrderNumber);

      //            if (orderPurchase.getId() != null) {
      //                if (em.contains(orderPurchase)) {
      //                    em.refresh(orderPurchase);
      //                }
      //                mergedOrSavedOrderPurchase = em.merge(orderPurchase);
      //                em.flush();
      //                return orderPurchase;
      //            } else {
      //                em.persist(orderPurchase);
      //                mergedOrSavedOrderPurchase = orderPurchase;
      //            }
      mergedOrSavedOrderPurchase = em.merge(orderPurchase);

      hql =
          "UPDATE OrderNumber SET lastOrderNumber = :newLastOrderNumber WHERE lastOrderNumber = :previousLastOrderNumber";
      query = session.createQuery(hql);
      query.setInteger("newLastOrderNumber", newLastOrderNumber);
      query.setInteger("previousLastOrderNumber", previousLastOrderNumber);
      int rowCount = query.executeUpdate();

      if (rowCount == 0) {
        em.getTransaction().rollback();
        mergedOrSavedOrderPurchase = createNewOrderWithRightOrderNumber(orderPurchase);
      }

    } catch (RollbackException e) {
      logger.debug("Failed to create a new Order with a specific OrderNumber increment", e);
    } catch (Exception e) {
      logger.error("Failed to create a new Order with a specific OrderNumber increment", e);
    }
    return mergedOrSavedOrderPurchase;
  }
コード例 #6
0
  public OrderPurchase saveOrUpdateOrder(OrderPurchase orderPurchase) {
    if (orderPurchase.getDateCreate() == null) {
      orderPurchase.setDateCreate(new Date());
    }
    orderPurchase.setDateUpdate(new Date());
    //        if (orderPurchase.getId() != null) {
    //            if(em.contains(orderPurchase)){
    //                em.refresh(orderPurchase);
    //            }
    //            OrderPurchase mergedOrderPurchase = em.merge(orderPurchase);
    //            em.flush();
    //            return mergedOrderPurchase;
    //        } else {
    //            em.persist(orderPurchase);
    //            return orderPurchase;
    //        }

    if (em.contains(orderPurchase)) {
      em.refresh(orderPurchase);
    }
    OrderPurchase mergedOrderPurchase = em.merge(orderPurchase);
    em.flush();
    return mergedOrderPurchase;
  }