package address.ejb;

/**
 * @ejb.bean
 *    type="CMP"
 *    cmp-version="2.x"
 *    name="Person"
 *    local-jndi-name="addressbook/ejb/PersonLocalHome"
 * 	  jndi-name="addressbook/ejb/PersonHome"
 *    view-type="both"
 *    primkey-field="personId"
 *
 * @ejb.finder
 *    signature="java.util.Collection findAll()"
 *    result-type-mapping="Local"
 *    method-intf="LocalHome"
 *    query="SELECT OBJECT(o) FROM Person o"
 *
 * @ejb.finder
 *    signature="java.util.Collection findByFirstName(java.lang.String firstName)"
 *    result-type-mapping="Local"
 *    method-intf="LocalHome"
 *    query="SELECT DISTINCT OBJECT(o) FROM Person o WHERE o.firstName = ?1"
 *    description="first_name is not indexed."
 *
 * @ejb.finder
 *    signature="java.util.Collection findByMiddleName(java.lang.String middleName)"
 *    result-type-mapping="Local"
 *    method-intf="LocalHome"
 *    query="SELECT DISTINCT OBJECT(o) FROM Person o WHERE o.middleName = ?1"
 *    description="middle_name is not indexed."
 *
 * @ejb.finder
 *    signature="java.util.Collection findByLastName(java.lang.String lastName)"
 *    result-type-mapping="Local"
 *    method-intf="LocalHome"
 *    query="SELECT DISTINCT OBJECT(o) FROM Person o WHERE o.lastName = ?1"
 *    description="last_name is not indexed."
 *
 * @ejb.persistence table-name="person"
 *
 * @weblogic.data-source-name address.database
 */
public abstract class PersonBean implements javax.ejb.EntityBean {

	/**
	 * Returns the personId
	 * @todo support OracleClob,OracleBlob on WLS
	 *
	 * @return the personId
	 *
	 * @ejb.pk-field
	 * @ejb.interface-method view-type="both"
	 * @ejb.persistence column-name="person_id"
	 */
	public abstract java.lang.Integer getPersonId();

	/**
	 * Sets the personId
	 *
	 * @param java.lang.Integer the new personId value
	 * @ejb.interface-method view-type="both"
	 */
	public abstract void setPersonId(java.lang.Integer personId);

	/**
	 * Returns the firstName
	 * @todo support OracleClob,OracleBlob on WLS
	 *
	 * @return the firstName
	 *
	 * @ejb.interface-method view-type="both"
	 * @ejb.persistence column-name="first_name"
	 */
	public abstract java.lang.String getFirstName();

	/**
	 * Sets the firstName
	 *
	 * @param java.lang.String the new firstName value
	 * @ejb.interface-method view-type="both"
	 */
	public abstract void setFirstName(java.lang.String firstName);

	/**
	 * Returns the middleName
	 * @todo support OracleClob,OracleBlob on WLS
	 *
	 * @return the middleName
	 *
	 * @ejb.interface-method view-type="both"
	 * @ejb.persistence column-name="middle_name"
	 */
	public abstract java.lang.String getMiddleName();

	/**
	 * Sets the middleName
	 *
	 * @param java.lang.String the new middleName value
	 * @ejb.interface-method view-type="both"
	 */
	public abstract void setMiddleName(java.lang.String middleName);

	/**
	 * Returns the lastName
	 * @todo support OracleClob,OracleBlob on WLS
	 *
	 * @return the lastName
	 *
	 * @ejb.interface-method view-type="both"
	 * @ejb.persistence column-name="last_name"
	 */
	public abstract java.lang.String getLastName();

	/**
	 * Sets the lastName
	 *
	 * @param java.lang.String the new lastName value
	 * @ejb.interface-method view-type="both"
	 */
	public abstract void setLastName(java.lang.String lastName);

	/**
	 * Returns the addressId
	 * @todo support OracleClob,OracleBlob on WLS
	 *
	 * @return the addressId
	 *
	 * @ejb.interface-method view-type="both"
	 * @ejb.persistence column-name="address_id"
	 */
	public abstract java.lang.Integer getAddressId();

	/**
	 * Sets the addressId
	 *
	 * @param java.lang.Integer the new addressId value
	 * @ejb.interface-method view-type="both"
	 */
	public abstract void setAddressId(java.lang.Integer addressId);

	/**
	 * This is a bi-directional one-to-one relationship CMR method
	 *
	 * @return the related address.interfaces.AddressLocal.
	 *
	 * @ejb.interface-method view-type="both"
	 *
	 * @ejb.relation
	 *    name="address-cmp20-person-cmp20"
	 *    role-name="person-cmp20-has-address-cmp20"
	 *
	 * @jboss.relation-mapping style="foreign-key"
	 *
	 * @weblogic.column-map
	 *    foreign-key-column="address_id"
	 *    key-column="address_id"
	 *
	 * @jboss.relation
	 *    fk-constraint="true"
	 *    fk-column="address_id"
	 *    related-pk-field="addressId"
	 *
	 */
	public abstract address.ejb.Address getAddress();

	/**
	 * Sets the related address.interfaces.AddressLocal
	 *
	 * @param address.interfaces.PersonLocal the related $target.variableName
	 *
	 * @ejb.interface-method view-type="both"
	 *
	 * @param address the new CMR value
	 */
	public abstract void setAddress(address.ejb.Address address);

	/**
	 * This create method takes only mandatory (non-nullable) parameters.
	 *
	 * 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: 
	 * <UL>
	 * <LI>Inserts the entity state into the database.</LI>
	 * <LI>Initializes the instance variables.</LI>
	 * <LI>Returns the primary key.</LI>
	 * </UL>
	 *
	 * @param address mandatory CMR field
	 * @return the primary key of the new instance
	 *
	 * @ejb.create-method
	 */
	public java.lang.Integer ejbCreate(address.ejb.Address address)
		throws javax.ejb.CreateException {
		// Use XDoclet's GUID generator. Only works for String fields
		// This requires <utilobject includeGUID="true"/> in ejbdoclet.

		// Set CMP fields
		// EJB 2.0 spec says return null for CMP ejbCreate methods.
		this.setPersonId(generatePrimaryKey());
		return null;
	}

	/**
	 * The container invokes thos method immediately after it calls ejbCreate. 
	 *
	 * @param address mandatory CMR field
	 */
	public void ejbPostCreate(address.ejb.Address address)
		throws javax.ejb.CreateException {
		setAddress(address);
	}

	/**
	 * This create method takes all parameters (both nullable and not nullable). 
	 *
	 * 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: 
	 * <UL>
	 * <LI>Inserts the entity state into the database.</LI>
	 * <LI>Initializes the instance variables.</LI>
	 * <LI>Returns the primary key.</LI>
	 * </UL>
	 *
	 * @param firstName the firstName value
	 * @param middleName the middleName value
	 * @param lastName the lastName value
	 * @param address CMR field
	 * @return the primary key of the new instance
	 *
	 * @ejb.create-method
	 */
	public java.lang.Integer ejbCreate(
		java.lang.String firstName,
		java.lang.String middleName,
		java.lang.String lastName,
		address.ejb.Address address)
		throws javax.ejb.CreateException {
		// Use Middlegen's Sequence Block PK generator. Only works for numeric fields
		// Use XDoclet's GUID generator. Only works for String fields
		// This requires <utilobject includeGUID="true"/> in ejbdoclet.

		this.setPersonId(generatePrimaryKey());
		// Set CMP fields
		setFirstName(firstName);
		setMiddleName(middleName);
		setLastName(lastName);
		// EJB 2.0 spec says return null for CMP ejbCreate methods.
		return null;
	}

	/**
	 * The container invokes thos method immediately after it calls ejbCreate. 
	 *
	 * @param firstName the firstName value
	 * @param middleName the middleName value
	 * @param lastName the lastName value
	 * @param address CMR field
	 */
	public void ejbPostCreate(
		java.lang.String firstName,
		java.lang.String middleName,
		java.lang.String lastName,
		address.ejb.Address address)
		throws javax.ejb.CreateException {
		// Set CMR fields
		setAddress(address);
	}

	public java.lang.Integer generatePrimaryKey() {
		return new Integer(this.hashCode());
	}
}
