コード例 #1
0
  public int editProduct(Myshopee_ProductTO productTO) throws Exception {

    Myshopee_Product product = new Myshopee_Product();

    product.setProductId(productTO.getProductId());
    product.setProductName(productTO.getProductName());
    product.setQtyInStock(productTO.getQtyInStock());
    product.setPricePerUnit(productTO.getPricePerUnit());
    product.setCategory(productTO.getCategory());
    product.setAssociated_points(productTO.getAssociatedPoints());
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Group4");
    EntityManager em = null;
    int productId = 0;
    try {
      em = emf.createEntityManager();
      em.getTransaction().begin();
      em.merge(product);
      em.getTransaction().commit();
      productId = product.getProductId();

      return productId;

    } catch (Exception e) {
      ErrorLogger.logError(this.getClass().getName(), "getProductFromId", e.getMessage());

      throw e;
    } finally {
      if (em != null) em.close();
    }
  }
コード例 #2
0
  // Description : Method to add Product
  public int addProduct(Myshopee_ProductTO productTO) {

    Myshopee_Product product = new Myshopee_Product();
    product.setProductName(productTO.getProductName());
    product.setQtyInStock(productTO.getQtyInStock());
    product.setPricePerUnit(productTO.getPricePerUnit());
    product.setAssociated_points(productTO.getAssociatedPoints());
    product.setCategory(productTO.getCategory());
    EntityManager em = null;
    try {

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("Group4");
      em = emf.createEntityManager();
      em.getTransaction().begin();
      em.persist(product);
      em.getTransaction().commit();

      return product.getProductId();

    } finally {
      if (em != null) {
        em.close();
      }
    }
  }