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

import java.util.Date;

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

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

    public Object ejbCreate(Date exp, String numb, String name, String org) 
	throws javax.ejb.CreateException {


	setExpirationDate(exp);
	setNumber(numb);
	setNameOnCard(name);
	setCreditOrganization(org);
        int id = seqLocal.getNextNumberInSequence("CreditCard");
	setId(new Integer(id));
	return null;
    }

    public void ejbPostCreate(Date exp, String numb, String name, String org) {
    }

	// relationship fields

    public abstract CustomerLocal getCustomer( );	
    public abstract void setCustomer(CustomerLocal cust);	

    public abstract CreditCompanyLocal getCreditCompany( );	
    public abstract void setCreditCompany(CreditCompanyLocal cc);   // persistent fields


    public abstract Integer getId();
    public abstract void setId(Integer id);
    public abstract Date getExpirationDate();
    public abstract void setExpirationDate(Date date);
    public abstract String getNumber();
    public abstract void setNumber(String number);
    public abstract String getNameOnCard();
    public abstract void setNameOnCard(String name);
    public abstract String getCreditOrganization();
    public abstract void setCreditOrganization(String org);

    // 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{}

}
