/*
 * Created on Oct 28, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package cmr;
import javax.ejb.*;

/**
 @ejb.bean
 *       type="CMP"
 *       cmp-version="2.x"
 *       name="User"
 *       schema="UserBean"
 *       local-jndi-name="UserLocal"
 *       view-type="local"
 *       primkey-field="email"
 *       
 * @ejb-interface generate="local"
 * @ejb.persistence  table-name="tbl_user" 
 *
 * @ejb.finder
 *     signature="Collection findAll()"
 *     unchecked="true"
 *     query="SELECT OBJECT(a) FROM UserBean AS a WHERE a.email IS NOT NULL"
 * 
 */
public abstract class UserBean implements EntityBean {
	
	protected EntityContext ctx;
	
	public UserBean() {}
	
	// Abstract sete/get methods
	/**
	 * @ejb.persistent-field
	 * @ejb.interface-method 
	 * @ejb.persistence colum-name="email"
	 * @ejb.pk-field
	 */
	public abstract String getEmail();
	
	// Email is read-only!
	public abstract void setEmail(String email);
	
	/**
	 * @ejb.persistent.field
	 * @ejb.interface-method
	 * @ejb.persistence column-name="password" 
     * 
	 */
	public abstract String getPassword();
	
	// password
	public abstract void setPassword(String password);

	/**
	 * @return return the User associated to this UserInfo
	 * @ejb.interface-method
	 * @ejb.transaction type="Required"
	 * @ejb.relation
	 *      name="UserHasUserInfo"
	 *      role-name="UserHasUserInfo"
	 * @weblogic.column-map
     *    foreign-key-column="email"
	 
	 */
	public abstract UserInfoLocal getUserInfo();

	/**
	 * @ejb.interface-method
	 */
	public abstract void setUserInfo(UserInfoLocal user);

	
	// End abstract get/set methods
	
	//--------------------------------------------
	// Begin EJB-required methods. The methods below are
	// called by the container and never called by client code.
	
	/**
	 * Called by container.
	 * Implementation can acquire needed resources.
	 */
	public void ejbActivate() {
		System.err.println("ejbActivate() called.");
	}
	
	/**
	 * EJB Container calls this method right before it removes
	 * the entity bean from the database. Corresponds to when
	 * the client calls remove()
	 */
	public void ejbRemove() throws RemoveException{
		System.err.println("ejbRemove() called.");
	}
	
	/**
	 * Called by the container.
	 * Releases held resources for passivation
	 */
	public void ejbPassivate() {
		System.err.println("ejbPassivate() called.");
	}
	
	/**
	 * Called from the container.Updates the entity bean
	 * instance to reflect the current value stored in the
	 * database.
	 */
	public void ejbLoad() {
		System.err.println("ejbLoad() called.");
	}
	
	/**
	 * CAlled by the container.Updates database to reflect the
	 * current values of this in-memory Entity Bean
	 * instance representation.
	 */
	public void ejbStore() {
		System.err.println("ejbStore() called.");
	}
	
	/**
	 * Called by the container. Associates this Bean with a
	 * particular context. Once done, we can query the Context
	 * for environment info.
	 */
	public void setEntityContext(EntityContext ctx) {
		System.err.println("setEntityContext() called.");
		this.ctx = ctx;
	}
	
	/**
	 * Called by the Container. Disassociated this Bean instance
	 * with a particular context environment.
	 */
	public void unsetEntityContext() {
		System.err.println("unsetEntityContext called.");
		this.ctx = null;
	}
	
	/**
	 * Called after ejbCreate().Now the bean can retrieve its
	 * EJBObject from its context and pass it as 'this' argument.
	 */
	public void ejbPostCreate(String email, String password) {
		System.err.println("ejbPostCreate() called.");						  	
	}
	
	/**
	 * This is the initialization method that corresponds
	 * to the create() method in the Home interface.
	 * 
	 * When the client calls the Home Object's create() method,
	 * the Home Object then calls this ejbCreate() method.
	 * @ejb.create-method
	 */
	public String ejbCreate(String email, String password) throws CreateException {
		System.err.println("ejbCreate() called.");
		setEmail(email);
		setPassword(password);
		
		return null;							
	}
	
	// -----------------------
	// No finder methods. They are implemented by
	// the Container.	
}
