/*
 * $Header: /var/cvsreps/projects/c450/2002/p01/src/ch/isbiel/oois/infocore/ejb/EventBean.java,v 1.2 2002/08/14 15:07:02 raucm Exp $
 *
 * OOIS - Online Orienteering Information System
 *
 * Copyright (c) 2002 by Michael Rauch, Mario Daepp,
 * University of Applied Sciences, Biel School of Engineering and Architecture
 *
 * OOIS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * OOIS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package ch.isbiel.oois.infocore.ejb;

import java.util.Set;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.naming.NamingException;

/**
 * This bean models an Event with its properties such as its name.
 *
 * @author $Author: raucm $
 * @version $Revision: 1.2 $ $Date: 2002/08/14 15:07:02 $
 *
 * @ejb:bean
 *     name="Event"
 *     display-name="EventEJB"
 *     type="CMP"
 *     cmp-version="2.x"
 *     local-jndi-name="local/oois/infocore/ejb/Event"
 *     view-type="local"
 *     reentrant="false"
 *     primkey-field="id"
 *
 * @ejb:pk
 *     class="java.lang.Integer"
 *
 * @ejb:ejb-ref
 *     ejb-name="SequenceSession"
 *     view-type="local"
 *
 * @ejb:util
 *     generate="physical"
 *
 * @ejb:finder
 *     signature="java.util.Collection findAll()"
 *     query="SELECT OBJECT(e) FROM Event AS e"
 */
public abstract class EventBean implements EntityBean {

  /**
   * Entity context for this bean
   */
  private EntityContext _entityCtx;

  /**
   * Cache for the SequenceSessionLocal, used to get the primary key
   */
  private SequenceSessionLocal _sequence;


  /**
   * Create event
   *
   * @ejb:create-method
   */
  public Integer ejbCreate(String name) throws CreateException {
    setId(_sequence.getNextNumberInSequence("EventBean"));
    setName(name);
    return null;
  }

  public void ejbPostCreate(String name) throws CreateException {
  }

 /**
   * An Event has many Competitions
   *
   * @ejb:relation
   *     name="Event-Competition"
   *     role-name="Event-has-many-Competitions"
   * @ejb:interface-method view-type="local"
   */
  public abstract Set getCompetitions();

  /**
   * @ejb:interface-method view-type="local"
   */
  public abstract void setCompetitions(Set competitions);


  /**
   * The ID of the event
   *
   * @ejb:persistent-field
   * @ejb:interface-method view-type="local"
   */
  public abstract Integer getId();

  /**
   * @ejb:interface-method view-type="local"
   */
  public abstract void setId(Integer id);

  /**
   * The name of the event
   *
   * @ejb:persistent-field
   * @ejb:interface-method view-type="local"
   */
  public abstract String getName();

  /**
   * @ejb:interface-method view-type="local"
   */
  public abstract void setName(String name);



  /**
   * Callback methods
   */
  public void setEntityContext(EntityContext ctx) {
    _entityCtx = ctx;

    SequenceSessionLocalHome sequence_home;
    EJBLocalHomeFactory homeFactory = EJBLocalHomeFactory.getInstance();
    try {
      sequence_home = (SequenceSessionLocalHome) homeFactory.
          lookUpLocalHome(SequenceSessionLocalHome.COMP_NAME);
      _sequence = sequence_home.create();
    } catch (NamingException nex) {
      throw new EJBException(nex);
    } catch (CreateException cex) {
      throw new EJBException(cex);
    }
  }

  public void unsetEntityContext() {
    _entityCtx = null;
  }

  public void ejbRemove() {
  }

  public void ejbActivate() {
  }

  public void ejbPassivate() {
  }

  public void ejbLoad() {
  }

  public void ejbStore() {
  }
}