package faqapp;

import java.sql.SQLException;
import java.util.Collection;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.naming.NamingException;

/**
 * Topic Entity Bean (CMP).
 **/
public abstract class TopicBean implements EntityBean {
    protected EntityContext ctx;

    public TopicBean() {
    }

    /* -----------------------------
    * Begin abstract get/set methods
    * ----------------------------- */

    public abstract Integer getTopicID();

    public abstract void setTopicID(Integer topicID);

    public abstract String getTopicDesc();

    public abstract void setTopicDesc(String topicDesc);

    public abstract AreaLocal getArea();

    public abstract void setArea(AreaLocal area);

    public abstract void setFaqs(Collection faqs);

    public abstract Collection getFaqs();

    /* ------------------------------------------------------
    * Begin EJB-required methods. The methods below are called
    * by the container, and never called by client code.
    * ------------------------------------------------------- */

    /**
     * Called by container, associates this bean instance with particular context.
     * Once done, we can query the Context for environment information.
     **/
    public void setEntityContext(EntityContext ctx) {
        this.ctx = ctx;
    }

    /* Called by container, diassociates this bean instance with particular context. */
    public void unsetEntityContext() {
        this.ctx = null;
    }

    /* Called by container, implementation can acquire needed resources */
    public void ejbActivate() {
    }

    /* Called by container, releases held resources for passivation */
    public void ejbPassivate() {
    }

    /**
     * Called from the container, updates the entity bean instance to
     * reflect the current value stored in the database.
     * Since we're using CMP, we can leave this method blank.
     * Container will automatically load us in the subclass.
     **/
    public void ejbLoad() {
    }

    /**
     * Called from container, updates the db to reflect the current
     * values of this in-memory entity bean instance representation.
     * Since we're using CMP, we can leave this method blank.
     * Container will automatically save us in the subclass.
     **/
    public void ejbStore() {
    }

    /**
     * This is the initialization method that corresponds to the
     * create() method in the Home Interface.
     *
     * When the client calls the Home Object's create() method,
     * the Home Object then calls this ejbCreate() method.
     *
     * We need to initialize our Bean's fields with the parameters passed
     * from the client, so that the container can create the corresponding
     * database entries in the subclass after this method completes.
     **/
    public Integer ejbCreate(String topicDesc, AreaLocal area) throws CreateException, NamingException, SQLException {
        /* Retrieve next PK value from OracleSequencePKGenerator */
        Integer topicID = OracleSequencePKGenerator.getInstance().getNextPKValue("Topic");
        setTopicID(topicID);
        setTopicDesc(topicDesc);
        return topicID;
    }

    /**
     * Called after ejbCreate(). Now the Bean can retrieve its EJBObject
     * from its context, and pass it as a 'this' argument.
     **/
    public void ejbPostCreate(String topicDesc, AreaLocal area) {
        if (area != null) setArea(area);
    }

    /**
     * Called by container right before it removes the Entity Bean from
     * the database. Corresponds to when client calls home.remove().
     **/
    public void ejbRemove() {
    }

    /* No Finder Methods, they are implemented by Container */
}
