View Javadoc

1   /*
2    * Created on Oct 21, 2004
3    *
4    * TODO To change the template for this generated file go to
5    * Window - Preferences - Java - Code Style - Code Templates
6    */
7   package ch.ledcom.hephaistos;
8   
9   import net.sf.hibernate.Criteria;
10  import net.sf.hibernate.HibernateException;
11  import net.sf.hibernate.Session;
12  import net.sf.hibernate.expression.Expression;
13  
14  import org.apache.log4j.Logger;
15  import org.apache.struts.action.ActionForm;
16  
17  import ch.ledcom.hephaistos.abstractActions.HibernateAddAction;
18  import ch.ledcom.hephaistos.dao.ProductClass;
19  import ch.ledcom.hephaistos.dao.ProductGroup;
20  
21  
22  /***
23   * @author gehel
24   *
25   * @struts.action
26   *  name="productGroupForm"
27   *  path="/ProductGroupAdd"
28   *  validate="true"
29   *  input="/pages/productGroupAdd.jsp"
30   * @struts.action-forward
31   *  name="success"
32   *  path="/index.jsp"  
33   * @struts.action-forward
34   *  name="failure"
35   *  path="/ProductGroupAddNew.do"
36   */
37  public class ProductGroupAddAction extends HibernateAddAction {
38    private static final Logger logger = Logger
39    .getLogger(ProductGroupAddAction.class);
40  
41    /* (non-Javadoc)
42     * @see ch.ledcom.hephaistos.HibernateAddAction#doAdd(org.apache.struts.action.ActionForm, net.sf.hibernate.Session)
43     */
44    protected void doAdd(ActionForm form, Session session)
45        throws HibernateException {
46      logger.debug("Casting the ActionForm to ProductGroupForm");
47      ProductGroupForm productGroupForm = (ProductGroupForm) form;
48  
49      logger.debug("Getting the associated Product Class");
50      Criteria criteria = session.createCriteria(ProductClass.class);
51      criteria.add(Expression.eq("id", productGroupForm.getProductClassId()));
52      
53      ProductClass productClass = (ProductClass) criteria.uniqueResult();
54  
55      
56      logger.debug("Creating a new ProductGroup object and populate it");
57      ProductGroup productGroup = new ProductGroup();
58      productGroup.setNo(productGroupForm.getNo());
59      productGroup.setNameF(productGroupForm.getNameF());
60      productGroup.setNameD(productGroupForm.getNameD());
61      
62      productGroup.setProductClass(productClass);
63      
64      logger.info("Saving the new product class");
65      session.save(productGroup);
66    }
67  
68  }