package com.alodar.example.ejb;

/**
 * @author Mark Lui
 *
 * @ejb:bean
 *    type="Stateless"
 *    name="ItemBO"
 *    jndi-name="com.alodar.example.interfaces.ItemBO"
 *    view-type="local"
 *
 * @ejb:transaction type="Required"
 * @ejb:transaction-type type="Container"
 *
 * @jboss-net:web-service urn="ItemBO"
 *                        expose-all="true"
 *
 */
public class ItemBOBean implements javax.ejb.SessionBean
{

    /**
    * echo test method
    *
    * @param value - String value to return
    *
    * @ejb:interface-method view-type="local"
    */
    public String echo(String value)
    {
        return value;
    }

    /**
    * returns String value of com.alodar.example.interfaces.ItemData
    *
    * @param itemData - data object
    *
    * @ejb:interface-method view-type="local"
    */
    public String test(com.alodar.example.interfaces.ItemData itemData)
    {
        return itemData.toString();

    }

    /**
    * get Item data object
    *
    * @param key - primary key
    *
    * @ejb:interface-method view-type="local"
    */
    public com.alodar.example.interfaces.ItemData get(int key) throws ItemBOException
    {

        try
        {

            com.alodar.example.interfaces.ItemLocalHome itemHome =
                    (com.alodar.example.interfaces.ItemLocalHome)com.alodar.example.interfaces.ItemUtil.getLocalHome();
            com.alodar.example.interfaces.ItemLocal item =
                    itemHome.findByPrimaryKey(new com.alodar.example.interfaces.ItemPK(new Integer(key)));

            return item.getData();

        }
        catch(Exception e)
        {
            throw new ItemBOException(e.getMessage());
        }
    }

    /**
    * creates new Item
    *
    * @param itemData - data object
    *
    * @ejb:interface-method view-type="local"
    */
    public void create(com.alodar.example.interfaces.ItemData itemData)
            throws ItemBOException
    {

        try
        {

            com.alodar.example.interfaces.ItemLocalHome itemHome =
                    (com.alodar.example.interfaces.ItemLocalHome)com.alodar.example.interfaces.ItemUtil.getLocalHome();
            itemHome.create(itemData);

        }
        catch(Exception e)
        {
            throw new ItemBOException(e.getMessage());
        }

    }
    
    /**
    * updates Item
    *
    * @param itemData - data object
    *
    * @ejb:interface-method view-type="local"
    */
    public void update(com.alodar.example.interfaces.ItemData itemData)
            throws ItemBOException
    {

        try
        {

            com.alodar.example.interfaces.ItemLocalHome itemHome =
                    (com.alodar.example.interfaces.ItemLocalHome)com.alodar.example.interfaces.ItemUtil.getLocalHome();
            com.alodar.example.interfaces.ItemLocal item =
                    itemHome.findByPrimaryKey(new com.alodar.example.interfaces.ItemPK(itemData.getItemId()));
            item.setData(itemData);
        }
        catch(Exception e)
        {
            throw new ItemBOException(e.getMessage());
        }

    }

    /**
    * The container invokes this method when the instance is taken out of the pool of
    * available instances to become associated with a specific EJB object.
    */
    public void ejbActivate()
    {
    }

    /**
    * The container invokes this method on an instance before the instance becomes
    * disassociated with a specific EJB object.
    */
    public void ejbPassivate()
    {
    }

    /**
    * The container invokes this method before it removes the EJB object that is
    * currently associated with the instance.
    */
    public void ejbRemove()
    {
    }

    /**
    * The container invokes setSessionContext just once - when it creates the bean instance.
    */
    public void setSessionContext(javax.ejb.SessionContext sessionContext) {}
}