// CategoryBean.java
// Entity Bean

package Category;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Vector;
import javax.ejb.CreateException;
import javax.ejb.DuplicateKeyException;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.ejb.EJBObject;
import javax.ejb.deployment.ControlDescriptor;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.NotSupportedException;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

import org.objectweb.jonas.common.Trace;


/**
 *
 */
public class CategoryBean implements EntityBean {

    static private final int trace = Trace.DB_1;
    EntityContext ejbContext;

    // ------------------------------------------------------------------
    // State of the bean. 
    // They must be public for Container Managed Persistance.
    // ------------------------------------------------------------------
    public int Ncat;
    public String cat;

    // ------------------------------------------------------------------
    // EntityBean implementation
    // ------------------------------------------------------------------

    /**
     * Set the associated entity context. The container invokes this method 
     * on an instance after the instance has been created.
     * This method is called in an unspecified transaction context. 
     * 
     * @param ctx - An EntityContext interface for the instance. The instance
     * should store the reference to the context in an instance variable.
     * @throws EJBException Thrown by the method to indicate a failure caused by a
     * system-level error.
     */
    public void setEntityContext(EntityContext ctx) {
	Trace.outln(trace, "CategoryBean setEntityContext");
	ejbContext = ctx;
    }

    /**
     * Unset the associated entity context. The container calls this method
     * before removing the instance. 
     * This is the last method that the container invokes on the instance.
     * The Java garbage collector will eventually invoke the finalize() method
     * on the instance.
     * This method is called in an unspecified transaction context.
     *
     * @throws EJBException Thrown by the method to indicate a failure caused by a
     * system-level error.
     */
    public void unsetEntityContext() {
	Trace.outln(trace, "CategoryBean setEntityContext");
	ejbContext = null;
    }
    
    /**
     * A container invokes this method before it removes the EJB object
     * that is currently associated with the instance. This method is
     * invoked when a client invokes a remove operation on the enterprise Bean's
     * home interface or the EJB object's remote interface. This method
     * transitions the instance from the ready state to the pool of available
     * instances. 
     *
     * This method is called in the transaction context of the remove operation.
     * @throws RemoveException  The enterprise Bean does not allow destruction of the object.
     * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
     * error.
     */
    public void ejbRemove() throws RemoveException {
	Trace.outln(trace, "CategoryBean ejbRemove");
    }

    /**
     * A container invokes this method to instruct the instance to synchronize
     * its state by loading it state from the underlying database. 
     * This method always executes in the proper transaction context.
     *
     * @throws EJBException Thrown by the method to indicate a failure caused by
     * a system-level error.
     */
    public void ejbLoad() {
	Trace.outln(trace, "CategoryBean ejbLoad");
    }

    /**
     * A container invokes this method to instruct the instance to synchronize
     * its state by storing it to the underlying database. 
     * This method always executes in the proper transaction context.
     *
     * @throws EJBException Thrown by the method to indicate a failure caused by
     * a system-level error.
     */
    public void ejbStore() {
	Trace.outln(trace, "CategoryBean ejbStore");
    }
	
    /**
     * There must be an ejbPostCreate par ejbCreate method
     *
     * @throws CreateException Failure to create an entity EJB object.
     */
    public void ejbPostCreate() throws CreateException {
	Trace.outln(trace, "CategoryBean ejbPostCreate");
    }
	
    /**
     * The Entity bean can define 0 or more ejbCreate methods.
     *
     * @throws CreateException Failure to create an entity EJB object.
     * @throws DuplicateKeyException An object with the same key already exists. 
     */
    public java.lang.Object ejbCreate() throws CreateException, DuplicateKeyException {
	Trace.outln(trace, "CategoryBean ejbCreate");

	// Init here the bean fields
	Ncat = 0;
	cat = " ";


	// In CMP, should return null.
	return null;
    }

    /**
     * This method is not called in the current JOnAS version.
     */
    public void ejbPassivate() {
    }

    /**
     * This method is not called in the current JOnAS version.
     */
    public void ejbActivate() {
    }
    
    // ------------------------------------------------------------------
    // Category implementation
    // ------------------------------------------------------------------

    /**
     * method1
     */
    public int GetNcat() {
	return Ncat;    }

    /**
     * method2
     */
    public void SetNcat(int n) {
	   Ncat = n;

    }
	 public String GetCat() {
	return cat;    }

    /**
     * method2
     */
    public void SetCat(java.lang.String s) {
	   cat = s; }
}
