1 package example.cmp.basic; 2 3 import javax.ejb.*; 4 5 /** 6 * Local interface for a course taught at Hogwarts, providing 7 * methods to view and change it. 8 * 9 * <code><pre> 10 * CREATE TABLE basic_courses ( 11 * course_id VARCHAR(250) NOT NULL, 12 * teacher VARCHAR(250), 13 * 14 * PRIMARY KEY(course_id) 15 * ); 16 * </pre></code> 17 * 18 * <p>All Course instances are obtained from the CourseHome interface, and 19 * all access to the Course table occurs through the Course interface. 20 * Clients can never use the CourseBean implementation directly or directly 21 * access the database for the course table. Because Resin-CMP has 22 * complete control over the database's course entries, it can more 23 * effectively cache results, often avoiding slow database access. 24 * 25 * <p>CourseId is the bean's primary key. Every entity bean must have 26 * a primary key. 27 * 28 * There is a <code>setInstructor</code> mutator, but no 29 * <code>setCourseId</code> mutator because clients can't set the primary key. 30 * Resin-CMP needs to implement the <code> 31 * setCourseId</code> method that has been defined in the implementation 32 * class,<code>CourseBean.java</code>. But the Implementation Class is 33 * not associated with any particular entities -- it is only used by the 34 * container to implement the Local Interface. If you want to use a method from 35 * the implementation class when calling from a client, it has to be made 36 * available explicitly in the Local Interface. 37 * 38 */ 39 public interface Course extends EJBLocalObject { 40 /** 41 * Returns the ID of the course (CMP field). This is also the primary 42 * key as defined in ejb-jar.xml. There's no corresponding setCourseId 43 * method in the local interface because clients must not change the 44 * primary key. 45 */ 46 public String getId(); 47 48 /** 49 * Returns the instructor's name (CMP field). More sophisticated 50 * applications will create a separate entity bean for the instructor 51 * instead of using a string. The more sophisticated application will 52 * use a relationship field to manage the instructor for a course. 53 * 54 * @see example.cmp.one2one 55 */ 56 public String getInstructor(); 57 58 /** 59 * Sets the instructor's name (CMP field). 60 * 61 * @param instructor the name of the new instructor. 62 */ 63 public void setInstructor(String instructor); 64 65 /** 66 * Swaps the instructor for a course. This business method will run in 67 * a transaction, like all business methods in an entity bean. 68 * The transaction protects the database from inconsistency when 69 * several clients try to modify the database simultaneously. 70 * 71 * @param course the course which will swap instructors. 72 */ 73 public void swap(Course course); 74 } 75