package ecb.perf;

import java.util.Collection;
import java.sql.Date;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.DuplicateKeyException;
import javax.ejb.RemoveException;
 
/**
 * Person Bean, represents a Person for an organisation
 *
 * @author <a href="mailto:Chris.Shaw@ECB.int">Chris Shaw</a>
 *
 * @ejb:bean
 *    type="CMP"
 *    cmp-version="2.x"
 *    name="Person"
 *    jndi-name="PersonHome"
 *    view-type="local"
 *
 * @weblogic:table-name person
 * @weblogic:data-source-name dbPool
 * @weblogic:persistence
 *
 * @jboss:table-name "person"
 */
public abstract class PersonBean implements EntityBean {

    private EntityContext ctx;

    /* Accessors */

    /**
     * Id of this Person
     *
     * @return id of this person
     *
     * @ejb:interface-method view-type="local"     
     * @ejb:persistent-field
     * @ejb:pk-field
     *
     * @weblogic:dbms-column p_id
     * @jboss:column-name  p_id
     */
    public abstract Integer getId();

    /**
     * Name of this Person
     *
     * @param name name of this person
     *
     * @ejb:interface-method view-type="local"
     * @ejb:persistent-field
     *
     * @weblogic:dbms-column p_name
     * @jboss:column-name  p_name 
     */
    public abstract String getName();

    /**
     * Mentor of this Person
     *
     * @return mentor of this person
     *
     * @ejb:interface-method view-type="local"
     * @ejb:relation
     *    name="mentor-person"
     *    role-name="many-persons-have-one-mentor"
     *
     * @weblogic:relation
     *    name="mentor-person"
     *    key-column="p_id"
     *    foreign-key-column="mentor_fk"
     *
     * @jboss-relation
     *    pk-field="p_id"
     *    foreign-key-column="mentor_fk"     
     */
    public abstract PersonLocal getMentor();

    /**
     * All Persons under this Person/Mentor (if applicable)
     *
     * @return all persons of this mentor
     *
     * @ejb:interface-method view-type="local"
     * @ejb:relation
     *    name="mentor-person"
     *    role-name="one-mentor-has-many-persons"
     *    multiple="yes"
     *
     * @weblogic:relation
     *    name="mentor-person"
     */
    public abstract Collection getPersons();

    /**
     * Division that this Person works for
     *
     * @return division of this person
     *
     * @ejb:interface-method view-type="local"
     * @ejb:relation
     *    name="division-person"
     *    role-name="many-persons-have-one-division"
     *
     * @weblogic:relation
     *    name="division-person"
     *    key-column="d_id"
     *    foreign-key-column="d_id_fk"
     *
     * @jboss-relation
     *    pk-field="d_id"
     *    foreign-key-column="d_id_fk"     
     */
    public abstract DivisionLocal getDivision();

    /* Mutators */

    /**
     * @param id id of this person
     *
     */
    public abstract void setId(Integer id);

    /**
     * @return name of this person
     *
     * @ejb:interface-method view-type="local"
     */
    public abstract void setName(String name);

    /**
     *
     * @return mentor of this person
     *
     * @ejb:interface-method view-type="local"
     */
    public abstract void setMentor(PersonLocal mentor);

    /**
     * @param persons all persons of this mentor
     *
     * @ejb:interface-method view-type="local"
     */
    public abstract void setPersons(Collection persons);

    /**
     * @param division department of this person
     *
     * @ejb:interface-method view-type="local"
     */
    public abstract void setDivision(DepartmentLocal division);

    /**
     * Generated bulk accessor.
      *
     * @param data bulk data
     *
     * @ejb:interface-method view-type="local"
     */
    public abstract void setData(PersonData data);
        
    /* Default methods */

    /**
     * Default ejb-create method
     *
     * @param person   new person data
     * @param mentor   mentor for this person
     * @param division division for this person
     * @param persons  persons for a mentor
     *     
     * @ejb:create-method view-type="local"
     */
    public PersonPK ejbCreate(PersonData person, PersonLocal mentor,
            DivisionLocal division, Collection persons) 
            throws DuplicateKeyException {
        setId(person.getId());
        setData(person);
                
        return null;
    }

    /**
     * Default ejb-postCreate method
     *
     * @param person   new person data
     * @param mentor   mentor for this person
     * @param division division for this person
     * @param persons  persons for a mentor
     */
    public void ejbPostCreate(PersonData person,  PersonLocal mentor,
            DivisionLocal division, Collection persons) 
            throws DuplicateKeyException {
        setMentor(mentor);
        setDivision(division);
        
        if (persons != null) {
            setPersons(persons);  //cannot be null for cmr collection
        }
    }

    public void setEntityContext(EntityContext ctx) {
        this.ctx = ctx;
    }

    public void unsetEntityContext() {
        ctx = null;
    }

    public void ejbLoad() {
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }

    public void ejbRemove() throws RemoveException {
    }

    public void ejbStore() {
    }
}
