package faqapp;

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

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

    public FAQBean() {
    }

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

    public abstract Integer getQuestionID();

    public abstract void setQuestionID(Integer questionID);

    public abstract String getQuestion();

    public abstract void setQuestion(String question);

    public abstract String getAnswer();

    public abstract void setAnswer(String answer);

    public abstract boolean getInternalFlag();

    public abstract void setInternalFlag(boolean internalFlag);

    public abstract String getProductVersion();

    public abstract void setProductVersion(String productVersion);

    public abstract String getCreatedBy();

    public abstract void setCreatedBy(String createdBy);

    public abstract Date getCreationDate();

    public abstract void setCreationDate(Date creationDate);

    public abstract String getModifiedBy();

    public abstract void setModifiedBy(String modifiedBy);

    public abstract Date getModificationDate();

    public abstract void setModificationDate(Date modificationDate);

    public abstract Collection getTopics();

    public abstract void setTopics(Collection topic);

    public abstract Collection getAreas();

    public abstract void setAreas(Collection areas);

    /* ------------------------------------------------------
    * 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 question, String answer, boolean internalFlag, String productVersion, String createdBy, Date creationDate, String modifiedBy, Date modificationDate, Collection topics, Collection areas) throws CreateException, NamingException, SQLException {
        /* Retrieve next PK value from OracleSequencePKGenerator */
        Integer questionID = OracleSequencePKGenerator.getInstance().getNextPKValue("FAQ");
        setQuestionID(questionID);
        setQuestion(question);
        setAnswer(answer);
        setInternalFlag(internalFlag);
        setProductVersion(productVersion);
        setCreatedBy(createdBy);
        setCreationDate(creationDate);
        setModifiedBy(modifiedBy);
        setModificationDate(modificationDate);
        return questionID;
    }

    /**
     * Called after ejbCreate(). Now the Bean can retrieve its EJBObject
     * from its context, and pass it as a 'this' argument.
     **/
    public void ejbPostCreate(String question, String answer, boolean internalFlag, String productVersion, String createdBy, Date creationDate, String modifiedBy, Date modificationDate, Collection topics, Collection areas) {
        setTopics(topics);
        setAreas(areas);
    }

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