KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > domain > order > ejb > Order


1 package xpetstore.domain.order.ejb;
2
3 import java.util.Collection JavaDoc;
4 import java.util.Date JavaDoc;
5 import java.util.Iterator JavaDoc;
6
7 import javax.ejb.CreateException JavaDoc;
8 import javax.ejb.EJBException JavaDoc;
9 import javax.ejb.FinderException JavaDoc;
10
11 import javax.annotation.EJB;
12
13 import javax.naming.NamingException JavaDoc;
14 import javax.persistence.CascadeType;
15 import javax.persistence.Column;
16 import javax.persistence.Entity;
17 import javax.persistence.EntityManager;
18 import javax.persistence.Id;
19 import javax.persistence.JoinColumn;
20 import javax.persistence.ManyToOne;
21 import javax.persistence.OneToMany;
22 import javax.persistence.PersistenceContext;
23 import javax.persistence.Table;
24
25 import xpetstore.domain.customer.ejb.Customer;
26 import xpetstore.domain.catalog.ejb.Item;
27
28 import xpetstore.util.uidgen.ejb.*;
29
30 /**
31  *
32  * @ ejb.bean
33  * name="Order"
34  * type="CMP"
35  * view-type="local"
36  * primkey-field="orderUId"
37  * schema="Order"
38  * cmp-version="${ejb.cmp.version}"
39  * @ ejb.value-object
40  * name="Order"
41  * match="*"
42  * @ ejb.transaction
43  * type="Required"
44  * @ ejb.persistence
45  * table-name="T_ORDER"
46  * @ ejb.finder
47  * signature="Collection findByCustomer(java.lang.String userId)"
48  * query="SELECT OBJECT(o) FROM Order AS o WHERE o.customer.userId = ?1"
49  * @ ejb.ejb-ref
50  * ejb-name="OrderItem"
51  * view-type="local"
52  * ref-name="ejb/OrderItemLocal"
53  * @ ejb.ejb-ref
54  * ejb-name="UIDGenerator"
55  * view-type="local"
56  * ref-name="ejb/UIDGeneratorLocal"
57  *
58  * @ jboss.persistence
59  * create-table="${jboss.create.table}"
60  * remove-table="${jboss.remove.table}"
61  */

62 @Entity(name = "Order")
63 @Table(name = "T_ORDER")
64 public class Order
65 {
66     public static final String JavaDoc COUNTER_NAME = "Order";
67     
68     private Integer JavaDoc orderUid;
69     private Date JavaDoc orderDate;
70     private String JavaDoc status;
71     private String JavaDoc street1;
72     private String JavaDoc street2;
73     private String JavaDoc city;
74     private String JavaDoc state;
75     private String JavaDoc zipcode;
76     private String JavaDoc country;
77     private String JavaDoc creditCardNumber;
78     private String JavaDoc creditCardType;
79     private String JavaDoc creditCardExpiryDate;
80     private Collection JavaDoc orderItems;
81     private Customer customer;
82     
83     public Order()
84     {
85     }
86
87     /**
88        * @ ejb.interface-method
89        */

90     public void addOrderItem( OrderItem orderItem )
91     {
92        if (orderItems == null)
93           orderItems = new java.util.ArrayList JavaDoc();
94        
95          orderItems.add(orderItem);
96     }
97
98     /**
99        * @ ejb.interface-method
100        */

101     public void changeStatus( String JavaDoc status )
102     {
103         setStatus( status );
104     }
105
106     /**
107        * @ ejb.interface-method
108        */

109     public double calculateTotal( )
110     {
111         double total = 0;
112         Iterator JavaDoc it = getOrderItems( ).iterator( );
113         while ( it.hasNext( ) )
114         {
115             total += ( ( OrderItem ) it.next( ) ).calculateSubTotal( );
116         }
117
118         return total;
119     }
120
121     /**
122        * @ ejb.pk-field
123        * @ ejb.persistence column-name="orderUId"
124        * @ ejb.interface-method
125        * @ ejb.transaction
126        * type="Supports"
127        */

128    @Id
129    @GeneratedValue(strategy= GenerationType.SEQUENCE)
130     @Column(name="orderUId")
131     public Integer JavaDoc getOrderUId( )
132     {
133        return orderUid;
134     }
135
136     public void setOrderUId( Integer JavaDoc orderUId )
137     {
138        this.orderUid = orderUId;
139     }
140
141     /**
142        * @ ejb.persistence column-name="orderDate"
143        */

144     @Column(name="orderDate")
145     public Date JavaDoc getOrderDate( )
146     {
147        return orderDate;
148     }
149
150     public void setOrderDate( Date JavaDoc orderDate )
151     {
152        this.orderDate = orderDate;
153     }
154
155     /**
156        * @ ejb.persistence column-name="status" jdbc-type="VARCHAR"
157        * sql-type="varchar(25)"
158        */

159     @Column(name="status", length=25)
160     public String JavaDoc getStatus( )
161     {
162        return status;
163     }
164
165     public void setStatus( String JavaDoc status )
166     {
167        this.status = status;
168     }
169
170     /**
171        * @ ejb.persistence column-name="street1" jdbc-type="VARCHAR"
172        * sql-type="varchar(50)"
173        */

174     @Column(name="street1", length=50)
175     public String JavaDoc getStreet1( )
176     {
177        return street1;
178     }
179
180     public void setStreet1( java.lang.String JavaDoc street1 )
181     {
182        this.street1 = street1;
183     }
184
185     /**
186        * @ ejb.persistence column-name="street2" jdbc-type="VARCHAR"
187        * sql-type="varchar(50)"
188        */

189     @Column(name="street2", length=50)
190     public String JavaDoc getStreet2( )
191     {
192        return street2;
193     }
194
195     public void setStreet2( String JavaDoc street2 )
196     {
197        this.street2 = street2;
198     }
199
200     /**
201        * @ ejb.persistence column-name="city" jdbc-type="VARCHAR"
202        * sql-type="varchar(25)"
203        */

204     @Column(name="city", length=25)
205     public java.lang.String JavaDoc getCity( )
206     {
207        return city;
208     }
209
210     public void setCity( String JavaDoc city )
211     {
212        this.city = city;
213     }
214
215     /**
216        * @ ejb.persistence column-name="state" jdbc-type="VARCHAR"
217        * sql-type="varchar(3)"
218        */

219     @Column(name="state", length=3)
220     public String JavaDoc getState( )
221     {
222        return state;
223     }
224
225     public void setState( String JavaDoc state )
226     {
227        this.state = state;
228     }
229
230     /**
231        * @ ejb.persistence column-name="zipcode" jdbc-type="VARCHAR"
232        * sql-type="varchar(10)"
233        */

234     @Column(name="zipcode", length=10)
235     public String JavaDoc getZipcode( )
236     {
237        return zipcode;
238     }
239
240     public void setZipcode( String JavaDoc zipcode )
241     {
242        this.zipcode = zipcode;
243     }
244
245     /**
246        * @ ejb.persistence column-name="country" jdbc-type="VARCHAR"
247        * sql-type="varchar(3)"
248        */

249     @Column(name="country", length=10)
250     public java.lang.String JavaDoc getCountry( )
251     {
252        return country;
253     }
254
255     public void setCountry( String JavaDoc country )
256     {
257        this.country = country;
258     }
259
260     /**
261        * @ ejb.persistence column-name="creditCardNumber" jdbc-type="VARCHAR"
262        * sql-type="varchar(25)"
263        */

264     @Column(name="creditCardNumber", length=25)
265     public String JavaDoc getCreditCardNumber( )
266     {
267        return creditCardNumber;
268     }
269
270     public void setCreditCardNumber( String JavaDoc creditCardNumber )
271     {
272        this.creditCardNumber = creditCardNumber;
273     }
274
275     /**
276        * @ ejb.persistence column-name="creditCardType" jdbc-type="VARCHAR"
277        * sql-type="varchar(25)"
278        */

279     @Column(name="creditCardType", length=25)
280     public String JavaDoc getCreditCardType( )
281     {
282        return creditCardType;
283     }
284
285     public void setCreditCardType( String JavaDoc creditCardType )
286     {
287        this.creditCardType = creditCardType;
288     }
289
290     /**
291        * @ ejb.persistence column-name="creditCardExpiryDate" jdbc-type="VARCHAR"
292        * sql-type="varchar(10)"
293        */

294     @Column(name="creditCardExpiryDate", length=10)
295     public String JavaDoc getCreditCardExpiryDate( )
296     {
297        return creditCardExpiryDate;
298     }
299
300     public void setCreditCardExpiryDate( String JavaDoc creditCardExpiryDate )
301     {
302        this.creditCardExpiryDate = creditCardExpiryDate;
303     }
304
305     /**
306        * @ ejb.interface-method
307        * @ ejb.relation name="order-customer"
308        * role-name="order-belongs_to-customer"
309        * target-ejb="Customer"
310        * target-role-name="customer-has-orders"
311        * target=multiple="yes"
312        * @ jboss.relation fk-column="customer_fk" related-pk-field="userId"
313        * @ weblogic.column-map foreign-key-column="customer_fk"
314        */

315     @ManyToOne(cascade={CascadeType.ALL})
316     @JoinColumn(name="CUSTOMER_ID")
317     public Customer getCustomer( )
318     {
319        return customer;
320     }
321
322     /**
323        * @ ejb.interface-method
324        */

325     public void setCustomer( Customer customer )
326     {
327        this.customer = customer;
328     }
329
330     /**
331        * @ ejb.interface-method
332        * @ ejb.relation name="order-orderItem" role-name="order-has-orderItems"
333        * target-ejb="OrderItem"
334        * target-role-name="orderItem-belongs_to-order"
335        * target-cascade-delete="yes"
336        * @ jboss.target-relation fk-column="order_fk" related-pk-field="orderUId"
337        * fk-contraint="${db.foreign.key}
338        * @ weblogic.target-column-map foreign-key-column="order_fk"
339        */

340     @OneToMany(targetEntity=OrderItem.class, cascade={CascadeType.ALL})
341     @JoinColumn(name="ORDER_ID")
342     public Collection JavaDoc getOrderItems( )
343     {
344        return orderItems;
345     }
346
347     public void setOrderItems( Collection JavaDoc orderItems )
348     {
349        this.orderItems = orderItems;
350     }
351    
352 }
353
Popular Tags