KickJava   Java API By Example, From Geeks To Geeks.

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


1 package example.cmp.many2one;
2
3 import java.util.*;
4 /**
5  * Implementation of the HouseBean. Each instance of HouseBean
6  * maps to a table entry of "student_house", where student_house is defined as
7  *
8  * <pre>
9  * CREATE TABLE student_house (
10  * name VARCHAR(250),
11  * points INTEGER
12  * )
13  * </pre>
14  *
15  * <p/>HouseBean is abstract since it's taking advantage of container-managed
16  * persistence. Resin-EJB will create the implementation of the abstract
17  * methods.
18  *
19  * <p/>HouseBean also takes advantage of the AbstractEntityBean implementation.
20  * AbstractEntityBean is just a stub EntityBean implementation with default
21  * methods to make life a little more sane for simple beans.
22  */

23 abstract public class HouseBean extends com.caucho.ejb.AbstractEntityBean {
24   /**
25    * Returns the house name. The name is the primary key.
26    */

27   abstract public String getName();
28   /**
29    * Returns the number of points for the house.
30    */

31   abstract public int getPoints();
32   /**
33    * Returns a collection of the students.
34    */

35   abstract public Collection getStudentList();
36   /**
37    * Adds a student to the house. If the student is already a member
38    * of another house, he will be removed from that house automatically.
39    */

40   public void addStudent(Student student)
41   {
42     getStudentList().add(student);
43   }
44   /**
45    * Removes a student from the house.
46    */

47   public void removeStudent(Student student)
48   {
49     getStudentList().remove(student);
50   }
51   /**
52    * Return a new ArrayList of the students since entity beans can't
53    * directly return the persistent collection.
54    */

55   public Collection getStudents()
56   {
57     return new ArrayList(getStudentList());
58   }
59 }
60
Popular Tags