    1   /***
    2    * @(#)ProductDAO.java
    3    *
    4    * JFoxSOAF, Service-Oriented Application Framework
    5    *
    6    * Copyright(c) JFoxSOAF Team
    7    *
    8    * Licensed under the GNU LGPL, Version 2.1 (the "License");
    9    * you may not use this file except in compliance with the License.
    10   * You may obtain a copy of the License at
    11   *
    12   * http://www.gnu.org/copyleft/lesser.html
    13   *
    14   * Unless required by applicable law or agreed to in writing, software
    15   * distributed under the License is distributed on an "AS IS" BASIS,
    16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17   * See the License for the specific language governing permissions and
    18   * limitations under the License.
    19   *
    20   * For more information, please visit:
    21   * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
    22   * http://www.huihoo.org/jfox/jfoxsoaf
    23   */
    24
    25  package org.huihoo.jfox.soaf.services.dao;
    26
    27  import java.util.LinkedList;
    28  import java.util.List;
    29
    30  import net.sf.hibernate.HibernateException;
    31
    32  import org.huihoo.jfox.soaf.exception.DAOException;
    33
    34  /***
    35   * JUnit test case model
    36   * {@link org.huihoo.jfox.soaf.services.persistence.ProductHibernateDAOImpl).
    37   *
    38   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
    39   * @version $Revision:$ $Date:$
    40   * @version Revision: 1.0
    41   */
    42
    43  public class ProductHibernateDAOImpl extends AbstractHibernateDAO implements
    44          ProductDAO {
    45
    46      /***
    47       * @see org.huihoo.jfox.soaf.services.dao.ProductDAO#getProduct(java.lang.String)
    48       */
    49      public Product getProduct(String productId) {
    50          Product product = null;
    51          try {
    52              product = (Product) get(Product.class, productId);
    53          } catch (DAOException e) {
    54              e.printStackTrace();
    55          } catch (HibernateException e) {
    56              e.printStackTrace();
    57          }
    58          return product;
    59      }
    60
    61      /***
    62       * @see org.huihoo.jfox.soaf.services.dao.ProductDAO#getProductList(org.huihoo.jfox.soaf.services.dao.Product)
    63       */
    64      public List getProductList() {
    65          List list = new LinkedList();
    66          try {
    67              list = find("from Product");
    68          } catch (DAOException e) {
    69              e.printStackTrace();
    70          } catch (HibernateException e) {
    71              e.printStackTrace();
    72          }
    73          return list;
    74      }
    75
    76      /***
    77       * @see org.huihoo.jfox.soaf.services.dao.ProductDAO#saveProduct(org.huihoo.jfox.soaf.services.dao.Product)
    78       */
    79      public void saveProduct(Product product) {
    80          try {
    81              saveOrUpdate(product);
    82          } catch (DAOException e) {
    83              e.printStackTrace();
    84          } catch (HibernateException e) {
    85              e.printStackTrace();
    86          }
    87      }
    88
    89      /***
    90       * @see org.huihoo.jfox.soaf.services.dao.ProductDAO#removeProduct(java.lang.String)
    91       */
    92      public void removeProduct(String productId) {
    93          try {
    94              Object product = load(Product.class, productId);
    95              delete(product);
    96          } catch (DAOException e) {
    97              e.printStackTrace();
    98          } catch (HibernateException e) {
    99              e.printStackTrace();
    100         }
    101     }
    102
    103 }