/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jtests.beans.sequence;

import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;


/**
 * SequenceEC2 controls the sequence block requests.
 *
 */
public abstract class SequenceEC2 implements EntityBean {

    protected EntityContext  entCtx;

    /*
     * Method ejbCreate
     * @param id          Sequence identifier
     * @param firstNumber Starting number
     * @return null
     * @throws CreateException Create error
     */
    public String ejbCreate(String id, int firstNumber) throws CreateException {
        setId(id);
        setNextNumber(firstNumber);
        return null;
    }

    /**
     * Method ejbPostCreate
     * @param id          Sequence identifier
     * @param firstNumber First number
     */
    public void ejbPostCreate(String id, int firstNumber) {
    }

    /**
     * Method ejbRemove
     * @throws RemoveException Remove error
     */
    public void ejbRemove() throws RemoveException {
    }

    /**
     * Method getId
     * @return The sequence identifier
     */
    public abstract String getId();

    /**
     * Method setId
     * @param The sequence identifier
     */
    public abstract void setId(String id);

    /**
     * Method getNextNumber gets the next number
     * @return The next sequence number.
     */
    public abstract int getNextNumber();

    /**
     * Method setNextNumber gets the next number
     * @param The next sequence number.
     */
    public abstract void setNextNumber(int nextNumber);

    /**
     * Method ejbActivate
     */
    public void ejbActivate() {

    }

    /**
     * Method ejbPassivate
     */
    public void ejbPassivate() {

    }

    /**
     * Method ejbLoad
     */
    public void ejbLoad() {
    }

    /**
     * Method ejbStore
     */
    public void ejbStore() {

    }

    /**
     * Method setEntityContext
     * @param entCtx The context of this entity bean.
     */
    public void setEntityContext(EntityContext entCtx) {
        this.entCtx = entCtx;
    }

    /**
     * Method unsetEntityContext
     */
    public void unsetEntityContext() {
        this.entCtx = null;
    }

    /**
     * Get a unique PK number, and increment the count for next call.
     */
    public int getUniqPk() {
        int ret = getNextNumber();
        setNextNumber(++ret);
        return ret;
    }

}

