KickJava   Java API By Example, From Geeks To Geeks.

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


1 package example.cmp.select;
2
3 import javax.ejb.*;
4 import java.util.*;
5
6 /**
7  * Implementation class for the House bean.
8  *
9  * <code><pre>
10  * CREATE TABLE select_house (
11  * name VARCHAR(250) NOT NULL,
12  *
13  * PRIMARY KEY(name)
14  * );
15  * </pre></code>
16  *
17  * <p>HouseBean is abstract since it's taking advantage of container-managed
18  * persistence. Resin-CMP will create the implementation of the abstract
19  * methods.
20  *
21  * <p>HouseBean also takes advantage of the AbstractEntityBean
22  * implementation. AbstractEntityBean is just a stub
23  * EntityBean implementation with default methods to make life
24  * a little more sane for simple beans.
25  */

26 abstract public class HouseBean extends com.caucho.ejb.AbstractEntityBean {
27
28   /**
29    * Returns the name of the house. The name is the primary key as
30    * defined in the deployment descriptor.
31    */

32   abstract public String getName();
33
34   /**
35    * returns a <code>Collection</code> of all Students living in this House
36    * (CMR field).
37    */

38   public abstract Collection getStudentList();
39
40   /**
41    * Returns a <code>Collection</code> of <code>String</code>s of all
42    * Student's names who are boys. Since the ejbSelect method can't be
43    * exposed in the local interface, we need to add a business method
44    * to return the names.
45    *
46    * <p>As the example shows, ejbSelect methods can return collections
47    * and values of any type storable in the database. In contrast, find
48    * methods must always return the local interface of entity beans.
49    *
50    * <p>The ORDER BY clause is a Resin-CMP extension to the EJB-QL spec.
51    * A later version of the EJB spec will almost certainly contain
52    * similar functionality.
53    *
54    * <code><pre>
55    * SELECT student.name
56    * FROM select_house house, IN(house.studentList) student
57    * WHERE student.gender='Boy' AND house=?1
58    * ORDER BY student.name
59    * </pre></code>
60    */

61   public abstract Collection ejbSelectAllBoys(House house)
62     throws FinderException;
63
64   /**
65    * The business method to find the boys in this house. Because ejbSelect
66    * methods can only be called by the bean implementation, we need a
67    * business method to return the names.
68    */

69   public List getAllBoyNamesSorted()
70   {
71     ArrayList list = null;
72     
73     try {
74       House house = (House) getEntityContext().getEJBLocalObject();
75       
76       list = (ArrayList) ejbSelectAllBoys(house);
77     } catch (Exception e) {
78       e.printStackTrace();
79     }
80
81     return list;
82   }
83
84 }
85
Popular Tags