Exemplo n.º 1
0
 /**
  * Stores the <code>Product</code> in the database.
  *
  * @param model the data model to store
  */
 public void saveProduct(com.skip.entity.product.Product model) throws GenericBusinessException {
   // We have to create an object:
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     // Now update the data.
     hibernateTemplate.update(model);
   } finally {
     log.debug("finished saveProduct(com.skip.entity.product.Product model)");
   }
 }
Exemplo n.º 2
0
 /**
  * Removes a product.
  *
  * @param id the unique reference for the product
  */
 public void deleteProduct(java.lang.Long id) throws GenericBusinessException {
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     // First get the data.
     Product bean = (Product) hibernateTemplate.get(Product.class, id);
     hibernateTemplate.delete(bean);
   } finally {
     log.debug("finished deleteProduct(java.lang.Long id)");
   }
 }
Exemplo n.º 3
0
 /**
  * Retrieves a data object from the database by its primary key.
  *
  * @param id the unique reference
  * @return Product the data object
  */
 public com.skip.entity.product.Product getProduct(java.lang.Long id)
     throws GenericBusinessException {
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     Product bean = (Product) hibernateTemplate.get(Product.class, id);
     return bean;
   } finally {
     log.debug("finished getProduct(java.lang.Long id)");
   }
 }
Exemplo n.º 4
0
 /**
  * Adds a new product to the database.
  *
  * @param model a data object
  * @return Product a data object with the primary key
  */
 public com.skip.entity.product.Product addProduct(com.skip.entity.product.Product model)
     throws GenericBusinessException {
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     hibernateTemplate.save(model);
     return getProduct(model.getProductId());
   } finally {
     log.debug("finished addProduct(com.skip.entity.product.Product model)");
   }
 }
Exemplo n.º 5
0
 /**
  * Obtains the total number of product objects in the database.
  *
  * @return an integer value.
  */
 public int getProductListSize() throws GenericBusinessException {
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     String queryString = "select count(*) from " + Product.class.getName();
     Query query = hibernateTemplate.createQuery(queryString);
     List list = hibernateTemplate.list(query);
     Integer countResult = (Integer) list.get(0);
     return countResult.intValue();
   } finally {
     log.debug("finished getProductListSize()");
   }
 }
Exemplo n.º 6
0
 /**
  * Retrieves a list of data object for the specified shopid field. To use a wildcard search, use a
  * % in the query.
  *
  * @param shopid the field
  * @return List of Product data objects, empty list in case no results were found.
  */
 public java.util.List findProductByShopid(java.lang.Long shopid) throws GenericBusinessException {
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     String queryString = "from " + Product.class.getName() + " e where e.shopid like :shopid ";
     // Add a an order by on all primary keys to assure reproducable results.
     String orderByPart = "";
     orderByPart += " order by e.productid";
     queryString += orderByPart;
     Query query = hibernateTemplate.createQuery(queryString);
     hibernateTemplate.setQueryParameter(query, "shopid", shopid);
     List list = hibernateTemplate.list(query);
     return list;
   } finally {
     log.debug("finished findProductByShopid(java.lang.Long shopid)");
   }
 }
Exemplo n.º 7
0
  /**
   * Returns a list of all product instances.
   *
   * @return a list of Product objects.
   */
  public List getProductList() throws GenericBusinessException {
    com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
    try {

      String queryString = "from " + Product.class.getName() + " e";
      // Add a an order by on all primary keys to assure reproducable results.
      String orderByPart = "";
      orderByPart += " order by e.productid";
      queryString += orderByPart;
      Query query = hibernateTemplate.createQuery(queryString);
      List list = hibernateTemplate.list(query);

      return list;
    } finally {
      log.debug("finished getProductList");
    }
  }
Exemplo n.º 8
0
 public Product findProductByShopidAndBarcode(Long shopid, String barcode)
     throws com.skip.exception.GenericBusinessException {
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     String queryString =
         "from "
             + Product.class.getName()
             + " e where e.barcode like :barcode and e.shopid = :shopid";
     // Add a an order by on all primary keys to assure reproducable results.
     String orderByPart = "";
     orderByPart += " order by e.productid";
     queryString += orderByPart;
     Query query = hibernateTemplate.createQuery(queryString);
     hibernateTemplate.setQueryParameter(query, "shopid", shopid);
     hibernateTemplate.setQueryParameter(query, "barcode", barcode);
     List list = hibernateTemplate.list(query);
     if (!list.isEmpty()) {
       return (Product) list.get(0);
     }
     return null;
   } finally {
     log.debug("finished findProductByShopidAndBarcode(Long shopid, String barcode)");
   }
 }
Exemplo n.º 9
0
 /**
  * Returns a subset of all product instances.
  *
  * @param startIndex the start index within the result set (1 = first record); any zero/negative
  *     values are regarded as 1, and any values greater than or equal to the total number of
  *     product instances will simply return an empty set.
  * @param endIndex the end index within the result set (<code>getProductListSize()</code> = last
  *     record), any values greater than or equal to the total number of product instances will
  *     cause the full set to be returned.
  * @return a list of Product objects, of size <code>(endIndex - startIndex)</code>.
  */
 public List getProductList(int startIndex, int endIndex) throws GenericBusinessException {
   if (startIndex < 1) {
     startIndex = 1;
   }
   if ((endIndex - startIndex) < 0) {
     // Just return an empty list.
     return new ArrayList();
   }
   com.skip.HibernateQueryHelper hibernateTemplate = new com.skip.HibernateQueryHelper();
   try {
     String queryString = "from " + Product.class.getName() + " e";
     // Add a an order by on all primary keys to assure reproducable results.
     String orderByPart = "";
     orderByPart += " order by e.productid";
     queryString += orderByPart;
     Query query = hibernateTemplate.createQuery(queryString);
     query.setFirstResult(startIndex - 1);
     query.setMaxResults(endIndex - startIndex + 1);
     List list = hibernateTemplate.list(query);
     return list;
   } finally {
     log.debug("finished getProductList(int startIndex, int endIndex)");
   }
 }