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

import javax.ejb.EntityContext;
import javax.naming.InitialContext;

public abstract class PhoneBean implements javax.ejb.EntityBean {
    private SequenceSessionLocalHome seqHome = null;
    private SequenceSessionLocal  seqLocal = null;

    public Object ejbCreate(String number, byte type) throws javax.ejb.CreateException {
	setNumber(number);
	setType(type);
        int id = seqLocal.getNextNumberInSequence("Phone");
	setId(new Integer(id));
	return null;
    }

    public void ejbPostCreate(String number, byte type) {
    }

    // persistent fields

    public abstract Integer getId();
    public abstract void setId(Integer id);
    public abstract String getNumber();
    public abstract void setNumber(String number);
    public abstract byte getType();
    public abstract void setType(byte type);

    // standard call back methods
    
    public void setEntityContext(EntityContext ec){
	try {
	    InitialContext cntx = new InitialContext( );
	    SequenceSessionLocalHome  seqHome  = 
		(SequenceSessionLocalHome)cntx.lookup("java:comp/env/ejb/SequenceSessionLocalHome");
	    seqLocal = seqHome.create();
	} catch(Exception e) {
	    throw new javax.ejb.EJBException(e);
	}
    }
    public void unsetEntityContext(){}
    public void ejbLoad(){}
    public void ejbStore(){}
    public void ejbActivate(){}
    public void ejbPassivate(){}
    public void ejbRemove() throws javax.ejb.RemoveException{}

}
