// StockEC2R.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 StockEC2R implements javax.ejb.EntityBean {

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

 
    public StockID  ejbCreate(String whID, Integer itemID, int stockQty) 
        throws javax.ejb.CreateException{
        logger.log(BasicLevel.DEBUG, "");

        // Init here the bean fields
        setWarehouseID(whID);
        setItemID(itemID);
        setStockQuantity(stockQty);
        setYearToDate(0);
        setOrderQuantity(0);
        setRemOrderQuantity(0);
        return null;
    }

    public void ejbPostCreate(String whID, Integer itemID, int stockQty) {
        logger.log(BasicLevel.DEBUG, "");
    }

    // ------------------------------------------------------------------
    // Persistent fields
    // 
    // ------------------------------------------------------------------
    public abstract String getWarehouseID();
    public abstract void setWarehouseID(String id);
    public abstract Integer getItemID();
    public abstract void setItemID(Integer id);
    public abstract int getStockQuantity();
    public abstract void setStockQuantity(int qty);
    public abstract int getYearToDate();
    public abstract void setYearToDate(int ytd);
    public abstract int getOrderQuantity();
    public abstract void setOrderQuantity(int oqty);
    public abstract int getRemOrderQuantity();
    public abstract void setRemOrderQuantity(int roqty);

    // ------------------------------------------------------------------
    // 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, "");
    }    

    public void increaseYearToDate(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: increaseYearToDate  quantity = "+qty);
        int ytd = getYearToDate();
        setYearToDate(ytd + qty);
    }
    public void decreaseYearToDate(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: decreaseYearToDate  quantity = "+qty);
        int ytd = getYearToDate();
        setYearToDate(ytd - qty);
 
    } 


    public void increaseStockQuantity(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: increaseStockQuantity  quantity = "+qty);
        int s =  getStockQuantity();
        setStockQuantity(s + qty);
    } 
    public void decreaseStockQuantity(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: decreaseStockQuantity  quantity = "+qty);
        int s =  getStockQuantity();
        setStockQuantity(s - qty);

    } 

    public void increaseRemOrderQuantity(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: increaseRemOrderQuantity  quantity = = "+qty);
        int s =  getRemOrderQuantity();
        setOrderQuantity(s + qty);
    }
    public void decreaseRemOrderQuantity(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: decreaseRemOrderQuantity  quantity = = "+qty);
        int s =  getRemOrderQuantity();
        setOrderQuantity(s -  qty);
    }


    public void increaseOrderQuantity(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: increaseOrderQuantity  quantity = "+qty);
        int s =  getOrderQuantity();
        setOrderQuantity(s +  qty);
    }
    public void decreaseOrderQuantity(int qty) {
        logger.log(BasicLevel.DEBUG,"StockBean: decreaseOrderQuantity  quantity = "+qty);
        int s =  getOrderQuantity();
        setOrderQuantity(s -  qty);
    } 
}



