package com.alodar.example.ejb;

/**
 * @author Mark Lui
 *
 * @ejb:bean
 *    type="CMP"
 *    cmp-version="2.x"
 *    name="Customer"
 *    jndi-name="com.alodar.example.interfaces.Customer"
 *    local-jndi-name="com.alodar.example.interfaces.CustomerLocal"
 *    view-type="both"
 *
 * @ejb:util
 *      generate="physical"
 *
 * @jboss:table-name Customer
 * @jboss:create-table "false"
 *
 * @jboss-net:data-object
 *      urn="CustomerData"
 */
public abstract class CustomerBean implements javax.ejb.EntityBean
{

    /**
    * Context set by container
    */
    private javax.ejb.EntityContext _entityContext;

    
    /**
    * Returns the customerId
    *
    * @return the customerId
    *
    * @ejb:persistent-field
    * @ejb:pk-field
    *
    * @jboss:column-name CustomerId
    */
    public abstract Integer getCustomerId();

    /**
    * Sets the customerId
    *
    * @param customerId the new customerId
    */
    public abstract void setCustomerId(Integer customerId);
    
    /**
    * Returns the firstName
    *
    * @return the firstName
    *
    * @ejb:persistent-field
    * 
    *
    * @jboss:column-name FirstName
    */
    public abstract String getFirstName();

    /**
    * Sets the firstName
    *
    * @param firstName the new firstName
    */
    public abstract void setFirstName(String firstName);
    
    /**
    * Returns the lastName
    *
    * @return the lastName
    *
    * @ejb:persistent-field
    * 
    *
    * @jboss:column-name LastName
    */
    public abstract String getLastName();

    /**
    * Sets the lastName
    *
    * @param lastName the new lastName
    */
    public abstract void setLastName(String lastName);
    
    /**
    * Returns the email
    *
    * @return the email
    *
    * @ejb:persistent-field
    * 
    *
    * @jboss:column-name Email
    */
    public abstract String getEmail();

    /**
    * Sets the email
    *
    * @param email the new email
    */
    public abstract void setEmail(String email);
    
    
    /**
    * Returns a collection of local Item
    *
    * @return a collection of local Item
    *
    * @ejb:interface-method view-type="local"
    * @ejb:relation
    *      name = "Customer-Item"
    *      role-name = "Customer-has-Item"
    *
    */
    public abstract java.util.Collection getItem();

    /**
    * Sets a collection of local Item
    *
    * @param item a collection of local Item
    *
    * @ejb:interface-method view-type="local"
    */
    public abstract void setItem(java.util.Collections item);

    /**
    * Adds to collection of local Item
    *
    * @param itemData data value object of Item
    *
    * @ejb:interface-method view-type="both"
    */
    public void addItem(com.alodar.example.interfaces.ItemData itemData)
            throws javax.naming.NamingException, javax.ejb.CreateException
    {
        com.alodar.example.interfaces.ItemLocalHome itemHome =
                (com.alodar.example.interfaces.ItemLocalHome)com.alodar.example.interfaces.ItemUtil.getLocalHome();
        com.alodar.example.interfaces.ItemLocal item =
                itemHome.create(itemData);
        this.getItem().add(item);
    }
    
    /**
    * Returns a local Address
    *
    * @return a local Address
    *
    * @ejb:interface-method view-type="local"
    * @ejb:relation
    *      name = "Customer-Address"
    *      role-name = "Customer-has-Address"
    *
    */
    public abstract com.alodar.example.interfaces.AddressLocal getAddress();

    /**
    * Sets a local Address
    *
    * @param myOrders a local Address
    *
    * @ejb:interface-method view-type="local"
    */
    public abstract void setAddress(com.alodar.example.interfaces.AddressLocal address);

    /**
    * Sets local Address
    *
    * @param addressData data value object of Address
    *
    * @ejb:interface-method view-type="both"
    */
    public void setAddress(com.alodar.example.interfaces.AddressData addressData)
            throws javax.naming.NamingException, javax.ejb.CreateException
    {
        com.alodar.example.interfaces.AddressLocalHome addressHome =
                (com.alodar.example.interfaces.AddressLocalHome)com.alodar.example.interfaces.AddressUtil.getLocalHome();
        com.alodar.example.interfaces.AddressLocal address =
                addressHome.create(addressData);
        this.setAddress(address);
    }
    
    /**
    * Gets a data object representing this instance
    *
    * @return a data object representing this instance
    *
    * @ejb:interface-method view-type="both"
    */
    public com.alodar.example.interfaces.CustomerData getData()
    {
      // We don't implement it here. XDoclet will create a subclass that implements it properly.
      return null;
    }

    /**
    * Sets a data object representing this instance
    *
    * @param data a data object holding new values
    *
    * @ejb:interface-method view-type="both"
    */
    public void setData(com.alodar.example.interfaces.CustomerData data)
    {
      // We don't implement it here. XDoclet will create a subclass that implements it properly.
    }

    /**
    * When the client invokes a create method, the EJB container invokes the ejbCreate method.
    * Typically, an ejbCreate method in an entity bean performs the following tasks:
    *
    * Inserts the entity state into the database.
    * Initializes the instance variables.
    * Returns the primary key.
    *
    *
    * @param data the data object used to initialise the new instance
    * @return the primary key of the new instance
    *
    * @ejb:create-method
    */
    public com.alodar.example.interfaces.CustomerPK ejbCreate(com.alodar.example.interfaces.CustomerData data) throws javax.ejb.CreateException
    {
      setCustomerId(data.getCustomerId());
      setData(data);
      // EJB 2.0 spec says return null for CMP ejbCreate methods.
      return null;
    }

    /**
    * The container invokes thos method immediately after it calls ejbCreate.
    *
    * @param data the data object used to initialise the new instance
    */
    public void ejbPostCreate(com.alodar.example.interfaces.CustomerData data) throws javax.ejb.CreateException
    {
    }

    // Implementation of the javax.ejb.EntityBean interface methods

    /**
    * The container invokes setEntityContext just once - when it creates the bean instance.
    */
    public void setEntityContext(javax.ejb.EntityContext entityContext)
    {
      _entityContext = entityContext;
    }

    /**
    * At the end of the life cycle, the container removes the instance from
    * the pool and invokes this method.
    */
    public void unsetEntityContext()
    {
      _entityContext = null;
    }

    /**
    * The container invokes this method to instruct the instance to synchronize its
    * state by loading it state from the underlying database.
    */
    public void ejbLoad()
    {
    }

    /**
    * 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() throws javax.ejb.RemoveException
    {
    }

    /**
    * The container invokes this method to instruct the instance to synchronize its
    * state by storing it to the underlying database.
    */
    public void ejbStore()
    {
    }
}