KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > cmp > create > CourseBean


1 package example.cmp.create;
2
3 import javax.ejb.*;
4 import javax.naming.*;
5
6 import javax.sql.DataSource;
7 import java.io.Serializable;
8 import java.util.Enumeration;
9 import com.caucho.ejb.AbstractEntityBean;
10
11 /**
12  * Implementation class for the Course bean.
13  *
14  * The implementation class of the <code>Course</code> entity bean. Its methods
15  * will be called only by the EJB container, and not ever by any client programs
16  * that we write. Instead, we call methods in the Local Interface which will
17  * prompt the container to access methods in this class on our behalf.
18  *
19  * <p><code>AbstractEntityBean</code> is a convenience superclass that provides
20  * a set of methods required by the spec.
21  *
22  * <p>This CMP entity bean use the following schema:
23  *
24  * <code><pre>
25  * DROP TABLE create_courses;
26  * CREATE TABLE create_courses (
27  * course_id VARCHAR(250) NOT NULL,
28  * instructor VARCHAR(250),
29  *
30  * PRIMARY KEY(course_id)
31  * );
32  *
33  * INSERT INTO create_courses VALUES('Potions', 'Severus Snape');
34  * INSERT INTO create_courses VALUES('Transfiguration', 'Minerva McGonagall');
35  * INSERT INTO create_courses VALUES('Defense Against the Dark Arts', 'Remus Lupin');
36  * </pre></code>
37  */

38 public abstract class CourseBean extends AbstractEntityBean {
39
40   /**
41    * Creates a new Course entity.
42    * <p><code>ejbCreate</code> methods implement the <code>create</code> methods
43    * declared in the Home Interface. This is like a bean "constructor" where
44    * entity properties are initialized.
45    *
46    * @param courseId the name of the course to be created
47    * @param name of the instructor who will teach the new course
48    */

49   public String ejbCreate(String courseId, String instructor)
50     throws CreateException
51   {
52     setCourseId(courseId);
53     setInstructor(instructor);
54
55     // With CMP, always return null
56
return null;
57   }
58
59   /**
60    * required by ejbCreate(String, String)
61    * <p>The container will call <code>ejbPostCreate</code> after the corresponding
62    * <code>ejbCreate</code> has completed and the entity has a new identity.
63    * The method is not used in this example.
64    */

65   public void
66   ejbPostCreate(String courseId, String instructor)
67   {
68   }
69
70   /**
71    * returns the id of this course, which is also the name of the course (CMP field).
72    * <p>CMP accessor and mutator methods are left for Resin-CMP to implement.
73    * Each cmp-field described in the deployment descriptor needs to be matched
74    * in the implementation class by abstract setXXX and getXXX methods. The
75    * container will take care of implementing them.
76    * <p>Note that unless you make these methods available in the Local Interface,
77    * you will never be able to access them from an EJB client such as a servlet.
78    */

79   public abstract String getCourseId();
80
81   /**
82    * sets the id of this course (CMP field).
83    * <p>CMP accessor and mutator methods are left for Resin-CMP to implement.
84    *
85    * @param val new id
86    */

87   public abstract void setCourseId( String val );
88
89   /**
90    * returns the name of the instructor who is teaching this course (CMP field).
91    * <p>CMP accessor and mutator methods are left for Resin-CMP to implement.
92    */

93   public abstract String getInstructor();
94
95   /**
96    * sets the name of the instructor whi is teaching this course (CMP field).
97    * <p>CMP accessor and mutator methods are left for Resin-CMP to implement.
98    *
99    * @param val new instructor
100    */

101   public abstract void setInstructor( String val );
102 }
103
Popular Tags