// CustomerEC2R.java
package org.objectweb.jonas.stests.appli;

import org.objectweb.jonas.common.Log;
import org.objectweb.util.monolog.api.Logger;
import org.objectweb.util.monolog.api.BasicLevel;

/**
 *
 */
public  abstract class CustomerEC2R implements javax.ejb.EntityBean {

    static private Logger logger = null;
    javax.ejb.EntityContext ejbContext;

	/**
     * Create a new Customer with minimal information.
	 * <p>
     * @param id Customer ID for the customer being created, must be unique
     * @param fN First name of the customer
     * @param lN Last name of the customer
     * @param phone Phone number of the customer
     * @return Customer
     * @exception javax.ejb.CreateException Creation Exception
     * @exception java.rmi.RemoteException Remote Exception
     */

    public String ejbCreate(Integer custID, String fN, String lN, String phone) 
        throws javax.ejb.CreateException{
        setCustomerID(custID);
        setFirstName(fN);
        setLastName(lN);
        setPhone(phone);
        setAddressLine1("unknown");
        setAddressLine2("unknown");
        setCity("unknown");
        setState("unknown");
        setZip("unknown");
        setCreditLimit(0);
        setBalance(0);
        setYearToDateBalance(0);
        return null;
    }

 	/**
     * Create a new Customer with all parameters, except balances which will automatically
     * be initialized to zero
	 * <p>
     * @param id Customer ID for the customer being created, must be unique
     * @param fN First name of the customer
     * @param lN Last name of the customer
     * @param inits Middle initials of the customer
     * @param phone Phone number of the customer
     * @param addr1 First address line of the customer
     * @param addr2 Second address line of the customer
     * @param city City of the customer's mailing address
     * @param state State of the customer's mailing address
     * @param zip Zip code of the customer's mailing address
     * @param creditLimit Credit limit allowed for this cusomter
     * @return Customer
     * @exception javax.ejb.CreateException Creation Exception
     * @exception java.rmi.RemoteException Remote Exception
	 */
    public String ejbCreate(Integer Id, String fN, String lN, String inits, 
                            String addr1, String addr2,
                            String city, String state, String zip,
                            String phone,
                           float creditLimit) throws javax.ejb.CreateException{
        logger.log(BasicLevel.DEBUG, "");

        // Init here the bean fields
        setCustomerID(Id);
        setFirstName(fN);
        setLastName(lN);
        setPhone(phone);
        setAddressLine1(addr1);
        setAddressLine2(addr2);
        setCity(city);
        setState(state);
        setZip(zip);
        setCreditLimit(creditLimit);
        setBalance(0);
        setYearToDateBalance(0);
        return null;
    }

    public void ejbPostCreate(Integer custID, String fN, String lN, String phone) {
        logger.log(BasicLevel.DEBUG, "");
    }

    public void ejbPostCreate(Integer Id, String fN, String lN, String inits, 
                              String addr1, String addr2,
                              String city, String state, String zip,
                              String phone,
                              float creditLimit) {
        logger.log(BasicLevel.DEBUG, "");
    }

    // ------------------------------------------------------------------
    // Persistent fields
    // 
    // ------------------------------------------------------------------
    public abstract Integer getCustomerID();
    public abstract void setCustomerID(Integer id);
    public abstract String getFirstName();
    public abstract void setFirstName(String fn);
    public abstract String getLastName();
    public abstract void setLastName(String ln);
    public abstract String getMiddleInitials();
    public abstract void setMiddleInitials(String mi);
    public abstract String getPhone();
    public abstract void setPhone(String phone);
    public abstract String getAddressLine1();
    public abstract void setAddressLine1(String line);
    public abstract String getAddressLine2();
    public abstract void setAddressLine2(String line);
    public abstract String getCity();
    public abstract void setCity(String city);
    public abstract String getState();
    public abstract void setState(String state);
    public abstract String getZip();
    public abstract void setZip(String zip);
    public abstract float getBalance();
    public abstract void setBalance(float balance);
    public abstract float getYearToDateBalance();
    public abstract void setYearToDateBalance(float ytdBalance);
    public abstract float getCreditLimit();
    public abstract void setCreditLimit(float limit);
    // ------------------------------------------------------------------
    // Standard call back methods
    // ------------------------------------------------------------------

 
    public void setEntityContext(javax.ejb.EntityContext ctx) {
        if (logger == null) {
            logger = Log.getLogger("org.objectweb.jonas_tests");
        }
        logger.log(BasicLevel.DEBUG, "");
        ejbContext = ctx;
    }


    public void unsetEntityContext() {
        logger.log(BasicLevel.DEBUG, "");
        ejbContext = null;
    }

    public void ejbRemove() throws javax.ejb.RemoveException {
        logger.log(BasicLevel.DEBUG, "");
    }

 
    public void ejbLoad() {
        logger.log(BasicLevel.DEBUG, "");
    }


    public void ejbStore() {
        logger.log(BasicLevel.DEBUG, "");
    }
        

    public void ejbPassivate() {
        logger.log(BasicLevel.DEBUG, "");
    }


    public void ejbActivate() {
        logger.log(BasicLevel.DEBUG, "");
    }   
 
	/**
     * Update the balance and year to date balance with the total amount from an order.
	 * <p>
     * @param orderAmount Order amount to update the balances with <i>(Mandatory)</i>
	 * @return void
     * @exception java.rmi.RemoteException Remote exception
	 */
	/*------------------------------------------------------------------*/
    public void updateBalance(float orderAmount) {
        float ytd = getYearToDateBalance();
        setYearToDateBalance(ytd + orderAmount);
        float balance = getBalance();
        setBalance(balance + orderAmount);
    }
}



