KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > cmp > one2many > HouseBean


1 package example.cmp.one2many;
2
3 import java.util.*;
4
5 /**
6  * Implementation class for the House bean.
7  *
8  * Each instance of StudentBean maps to a table entry of "one2many_houses",
9  * where student is defined.
10  *
11  * <p>HouseBean is abstract since it's taking advantage of container-managed
12  * persistence. Resin-CMP will create the implementation of the abstract
13  * methods.
14  *
15  * <p>HouseBean also takes advantage of the AbstractEntityBean
16  * implementation. AbstractEntityBean is just a stub
17  * EntityBean implementation with default methods to make life
18  * a little more sane for simple beans.
19  *
20  * <p>This CMP bean uses the following schema:
21  *
22  * <code><pre>
23  * CREATE TABLE one2many_houses (
24  * name VARCHAR(250) NOT NULL,
25  *
26  * PRIMARY KEY(name)
27  * );
28  * </pre></code>
29  */

30 abstract public class HouseBean extends com.caucho.ejb.AbstractEntityBean {
31
32   /**
33    * returns the name of the house (CMP field). The name is the primary key as defined
34    * in the deployment descriptor.
35    */

36   abstract public String getName();
37
38   /**
39    * returns a <code>Collection</code> of all <code>Students</code>s managed by
40    * the container (CMR field).
41    * <p>This method needs to exist
42    * because the field <code>studentList</code> is defined as a CMR field.
43    */

44   abstract public Collection getStudentList();
45
46   /**
47    * Adds a student to the house. If the student is already a member
48    * of another house, he will be removed from that house automatically.
49    */

50   public void addStudent(Student student)
51   {
52     getStudentList().add(student);
53   }
54
55   /**
56    * Removes a student from the house.
57    */

58   public void removeStudent(Student student)
59   {
60     getStudentList().remove(student);
61   }
62
63 }
64
Popular Tags