example.cmp.basic
Class CourseBean

example.cmp.basic.CourseBean

public abstract class CourseBean

Implementation class for the Course bean.

The implementation class of the Course entity bean. Its methods will be called only by the EJB container, never directly by clients. Clients always call methods in the local interface, calling methods in the Resin-CMP generated stub. The stub methods will call the CourseBean methods in the correct transaction context.

AbstractEntityBean is a convenience superclass that provides a set of methods required by the spec that we don't use in this example.

This CMP entity bean use the following schema:

 CREATE TABLE basic_courses (
   course_id VARCHAR(250) NOT NULL,

   instructor VARCHAR(250),
   PRIMARY KEY(course_id)
 );
 

The column names are generated from the field names. getCourseId becomes course_id and getInstructor becomes instructor. The table name is specified in the ejb deployment descriptor, cmp-basic.ejb.


Constructor Summary
CourseBean()
           
 
Method Summary
abstract  java.lang.String getCourseId()
          Returns the ID of the course, the primary key.
abstract  java.lang.String getInstructor()
          Returns the name of the instructor for this course.
abstract  void setCourseId(java.lang.String courseId)
          Sets the primary key of the course, only called from a create method.
abstract  void setInstructor(java.lang.String instructor)
          Sets the name of the instructor for this course.
 void swap(Course course)
          Swaps the instructors.
 

Constructor Detail

CourseBean

public CourseBean()
Method Detail

getCourseId

public abstract java.lang.String getCourseId()
Returns the ID of the course, the primary key.

All container-managed fields are abstract since Resin-CMP will generate the SQL and JDBC calls to manage them.

Each cmp-field described in the deployment descriptor needs to be matched in the implementation class by abstract setXXX and getXXX methods. The container will take care of implementing them.

Note that unless you make these methods available in the local interface, you will never be able to access them from an EJB client such as a servlet.


setCourseId

public abstract void setCourseId(java.lang.String courseId)
Sets the primary key of the course, only called from a create method. The primary key may only be set in an ejbCreate method. Tables that generate the primary key automatically will not define the setXXX method, only the getXXX method.
Parameters:
courseId - the courseId of the new course

getInstructor

public abstract java.lang.String getInstructor()
Returns the name of the instructor for this course. Since getInstructor is a container managed field (cmp-field), it must be abstract for Resin-CMP to implement.

Resin-CMP will automatically cache the value so most calls to getInstructor can avoid database calls.


setInstructor

public abstract void setInstructor(java.lang.String instructor)
Sets the name of the instructor for this course. Since setInstructor is a cmp-field, Resin-CMP will implement it. The value will be written to the database when the transaction completes.

swap

public void swap(Course course)
Swaps the instructors. Resin-CMP encapsulates all business methods a transaction to protect against concurrent access. So client code can call the business method without worrying about database consistency.

Because concurrent modifications can conflict, it's always possible for a business method to throw a transaction failure exception, a runtime exception. Depending on the business logic, clients can retry the transaction or just return an error message.

Parameters:
course - the course with the instructor to swap.
Throws:
javax.ejb.EJBException - if the transaction fails.