KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > ejb > AddressBean


1 /*
2  * $Id: AddressBean.java,v 1.12 2004/08/15 20:14:42 pilhuhn Exp $
3  */

4
5 package test.ejb;
6
7 import test.interfaces.AddressValue;
8 import test.interfaces.AddressUtil;
9
10 import javax.ejb.CreateException JavaDoc;
11 import javax.ejb.EntityBean JavaDoc;
12 import javax.ejb.FinderException JavaDoc;
13
14 /**
15  * @ejb.bean
16  * name="Address"
17  * jndi-name="ejb/addr/Address"
18  * view-type="local"
19  * primkey-field="id"
20  *
21  * @ejb.finder
22  * signature="Collection findByStreet(java.lang.String street)"
23  * unchecked="true"
24  *
25  * @ejb.finder
26  * signature="Collection findByCity(java.lang.String city)"
27  *
28  * @ejb.finder
29  * signature="Collection findByOwner(test.interfaces.Customer owner)"
30  *
31  * @ejb.value-object
32  * name="Address"
33  * match="*"
34  *
35  * @ejb.persistence
36  * table-name="address"
37  *
38  * @jonas.bean
39  * ejb-name="Address"
40  * jndi-name="AddressHome"
41  * @jonas.jdbc-mapping
42  * jndi-name="jdbc_1"
43  * jdbc-table-name="address"
44  * @jonas.finder-method-jdbc-mapping
45  * method-name="findByStreet"
46  * jdbc-where-clause="street = ?"
47  * @jonas.finder-method-jdbc-mapping
48  * method-name="findByCity"
49  * jdbc-where-clause="city = ?"
50  *
51  * @author <a HREF="mailto:youremail@yourdomain.com">youremail@yourdomain.com</a>
52  */

53 public abstract class AddressBean extends BaseEntityBean implements EntityBean JavaDoc {
54     /** @ejb.create-method */
55     public String JavaDoc ejbCreate(AddressValue v) throws CreateException JavaDoc {
56         setId(AddressUtil.generateGUID(this));
57         return null;
58     }
59
60     public void ejbPostCreate(AddressValue v) throws CreateException JavaDoc {
61         // CMR relations must be set in ejbPostCreate
62
setAddressValue(v);
63     }
64
65     //========== VALUE OBJECT ==========//
66

67     /** @ejb.interface-method */
68     public abstract AddressValue getAddressValue();
69
70     /**
71      * @ejb.interface-method
72      * @ejb.transaction
73      * type="RequiresNew"
74      */

75     public abstract void setAddressValue(AddressValue v);
76
77     //========== ATTRIBUTES ==========//
78

79     /**
80      * @ejb.pk-field
81      * @ejb.persistent-field
82      * @ejb.persistence
83      * column-name="id"
84      * sql-type="VARCHAR"
85      *
86      * @jonas.cmp-field-jdbc-mapping
87      * field-name="id"
88      * jdbc-field-name="id"
89      */

90     public abstract String JavaDoc getId();
91
92     /**
93      * No interface method for setId(..). See page 130 of the EJB 2.0 specification:
94      * "Once the primary key for an entity bean has been set, the Bean Provider must
95      * not attempt to change it by use of set accessor methods on the primary key
96      * cmp-fields. The Bean provider should therefore not expose the set accessor
97      * methods for the primary key cmp-fields in the component interface of the
98      * entity bean.". A work around would be to remove and then an re-create the bean.
99      */

100     public abstract void setId(String JavaDoc id);
101
102     /**
103      * @ejb.persistent-field
104      * @ejb.persistence
105      * column-name="street"
106      * sql-type="VARCHAR"
107      *
108      * @jonas.cmp-field-jdbc-mapping
109      * field-name="street"
110      * jdbc-field-name="street"
111      */

112     public abstract String JavaDoc getStreet();
113
114     /**
115      * @ejb.persistent-field
116      * @ejb.persistence
117      * column-name="city"
118      * sql-type="VARCHAR"
119      *
120      * @jonas.cmp-field-jdbc-mapping
121      * field-name="city"
122      * jdbc-field-name="city"
123      */

124     public abstract String JavaDoc getCity();
125
126     /** @ejb.select query="SELECT a.street FROM Address AS a WHERE a.street = 'Cinnamon Street'" */
127     public abstract String JavaDoc ejbSelectMostCrowdedStreet() throws FinderException JavaDoc;
128
129     /**
130      * Check to see if read-only is set for jboss
131      * @ejb.interface-method
132      * @ejb.persistence read-only="true"
133      *
134      * @return
135      */

136     public abstract int getReadOnly();
137 }
138
Popular Tags