KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > cmp > id > QuidditchBean


1 package example.cmp.id;
2
3 import javax.ejb.CreateException;
4
5 /**
6  * Implementation class for the Quidditch bean.
7  *
8  * <p>Each instance of QuidditchBean maps to a table entry of "id_quidditch".
9  *
10  * <p>The Quidditch entry is tied to a Student, using the Student as
11  * its primary key.
12  *
13  * <p>StudentBean is abstract since it's taking advantage of container-managed
14  * persistence. Resin-CMP will create the implementation of the abstract
15  * methods.
16  *
17  * <p>StudentBean also takes advantage of the AbstractEntityBean
18  * implementation. AbstractEntityBean is just a stub
19  * EntityBean implementation with default methods to make life
20  * a little more sane for simple beans.
21  *
22  * <p>This CMP bean uses the following schema:
23  *
24  * <code><pre>
25  * CREATE TABLE id_quidditch (
26  * student VARCHAR(250) NOT NULL REFERENCES id_student(name),
27  *
28  * position VARCHAR(250),
29  * points INTEGER,
30  *
31  * PRIMARY KEY(student)
32  * );
33  * </pre></code>
34  */

35 abstract public class QuidditchBean extends com.caucho.ejb.AbstractEntityBean {
36   /**
37    * Returns the owning student. The student is also the primary
38    * key.
39    */

40   abstract public Student getStudent();
41   /**
42    * Sets the owning student. Since the student is the primary key,
43    * this method is only called from the ejbCreate method.
44    */

45   abstract public void setStudent(Student student);
46   /**
47    * Returns the position the student plays on the team.
48    */

49   abstract public String getPosition();
50   /**
51    * Sets the position the student plays on the team.
52    */

53   abstract public void setPosition(String position);
54   /**
55    * Returns the number of points the student has earned.
56    */

57   abstract public int getPoints();
58   /**
59    * Sets the number of points the student has earned.
60    */

61   abstract public void setPoints(int points);
62   /**
63    * Creates the student's scores, setting primary keys and fields.
64    */

65   public Student ejbCreate(Student student, String position)
66     throws CreateException
67   {
68     setStudent(student);
69     setPosition(position);
70
71     return student;
72   }
73   /**
74    * Sets any relations. This case has no relations.
75    */

76   public void ejbPostCreate(Student student, String position)
77   {
78   }
79 }
80
Popular Tags