KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > ejbql > ReservationBean


1 package org.objectweb.jonas.jtests.beans.ejbql;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.Date JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.Set JavaDoc;
8
9 import javax.ejb.CreateException JavaDoc;
10 import javax.ejb.EntityContext JavaDoc;
11 import javax.ejb.FinderException JavaDoc;
12 import javax.ejb.RemoveException JavaDoc;
13 import javax.naming.InitialContext JavaDoc;
14
15 public abstract class ReservationBean implements javax.ejb.EntityBean JavaDoc {
16
17     private SequenceSessionLocalHome seqHome = null;
18
19     private SequenceSessionLocal seqLocal = null;
20
21     private CustomerHomeLocal customerhl = null;
22
23     private CruiseHomeLocal cruisehl = null;
24
25     private CabinHomeLocal cabinhl = null;
26
27     public Object JavaDoc ejbCreate(Integer JavaDoc cruiseId, Collection JavaDoc customers) throws CreateException JavaDoc {
28         int id = seqLocal.getNextNumberInSequence("Reservation");
29         setId(new Integer JavaDoc(id));
30         return null;
31     }
32
33     public void ejbPostCreate(Integer JavaDoc cruiseId, Collection JavaDoc customers) {
34
35         try {
36             CruiseLocal cruise = cruisehl.findByPrimaryKey(cruiseId);
37             setCruise(cruise);
38         } catch (FinderException JavaDoc e) {
39             System.out.println("Cruise not find :" + cruiseId);
40         }
41
42         Collection JavaDoc myCustomers = this.getCustomers();
43
44         ArrayList JavaDoc al;
45         if (customers == null)
46             al = new ArrayList JavaDoc();
47         else {
48             if (customers.size() == -1)
49                 al = new ArrayList JavaDoc();
50             else {
51                 al = new ArrayList JavaDoc(customers.size());
52                 for (Iterator JavaDoc it = customers.iterator(); it.hasNext();) {
53                     Integer JavaDoc customerid = new Integer JavaDoc("-1");
54                     try {
55                         customerid = (Integer JavaDoc) it.next();
56                         CustomerLocal customer = customerhl.findByPrimaryKey(customerid);
57                         al.add(customer);
58                     } catch (FinderException JavaDoc e) {
59                         System.out.println("Customer not found " + customerid);
60                     }
61                 }
62             }
63         }
64         myCustomers.addAll(al);
65     }
66
67     // relationship fields
68
public void setAllCabins(Set JavaDoc cabins) {
69
70         ArrayList JavaDoc al;
71         if (cabins == null)
72             al = new ArrayList JavaDoc();
73         else {
74             if (cabins.size() == -1)
75                 al = new ArrayList JavaDoc();
76             else {
77                 al = new ArrayList JavaDoc(cabins.size());
78                 for (Iterator JavaDoc it = cabins.iterator(); it.hasNext();) {
79                     Integer JavaDoc cabinid = new Integer JavaDoc("-1");
80                     try {
81                         cabinid = (Integer JavaDoc) it.next();
82                         CabinLocal cabin = cabinhl.findByPrimaryKey(cabinid);
83                         al.add(cabin);
84                     } catch (FinderException JavaDoc e) {
85                         System.out.println("Cabin not found " + cabinid);
86                     }
87                 }
88             }
89         }
90         this.getCabins().addAll(al);
91     }
92
93     // persistent fields getter and setter
94
public abstract CruiseLocal getCruise();
95
96     public abstract void setCruise(CruiseLocal cruise);
97
98     public abstract Set JavaDoc getCabins();
99
100     public abstract void setCabins(Set JavaDoc cabins);
101
102     public abstract Set JavaDoc getCustomers();
103
104     public abstract void setCustomers(Set JavaDoc customers);
105
106     public abstract Integer JavaDoc getId();
107
108     public abstract void setId(Integer JavaDoc id);
109
110     public abstract Date JavaDoc getDate();
111
112     public abstract void setDate(Date JavaDoc date);
113
114     public abstract double getAmountPaid();
115
116     public abstract void setAmountPaid(double amount);
117
118     // abstract ejbSelect() methods
119
public abstract long ejbSelectCountOfReservations() throws FinderException JavaDoc;
120
121     public abstract double ejbSelectMinAmountOfReservations() throws FinderException JavaDoc;
122
123     public abstract double ejbSelectMinAmountForCruise(String JavaDoc cName) throws FinderException JavaDoc;
124
125     public abstract Collection JavaDoc ejbSelectAmountsForCruise(String JavaDoc cName) throws FinderException JavaDoc;
126
127     public abstract double ejbSelectMaxAmountOfReservations() throws FinderException JavaDoc;
128
129     public abstract long ejbSelectCountOfReservationsForCustomer(CustomerLocal c) throws FinderException JavaDoc;
130
131     public abstract long ejbSelectAmountOfReservationsForCustomer(CustomerLocal c) throws FinderException JavaDoc;
132
133     // Public Home method required to test the private ejbSelectXXXX method
134
public long ejbHomeGetCountOfReservations() throws FinderException JavaDoc {
135         return this.ejbSelectCountOfReservations();
136     }
137
138     public double ejbHomeGetMinAmountOfReservations() throws FinderException JavaDoc {
139         return this.ejbSelectMinAmountOfReservations();
140     }
141
142     public double ejbHomeGetMinAmountForCruise(String JavaDoc cName) throws FinderException JavaDoc {
143         return this.ejbSelectMinAmountForCruise(cName);
144     }
145
146     public double ejbHomeGetMaxAmountOfReservations() throws FinderException JavaDoc {
147         return this.ejbSelectMaxAmountOfReservations();
148     }
149
150     public Collection JavaDoc ejbHomeGetAmountsForCruise(String JavaDoc cName) throws FinderException JavaDoc {
151         return this.ejbSelectAmountsForCruise(cName);
152     }
153
154     public long ejbHomeGetCountOfReservationsForCustomer(Integer JavaDoc custId) throws FinderException JavaDoc {
155         return this.ejbSelectCountOfReservationsForCustomer(customerhl.findByPrimaryKey(custId));
156     }
157
158     public double ejbHomeGetAmountOfReservationsForCustomer(Integer JavaDoc custId) throws FinderException JavaDoc {
159         return this.ejbSelectAmountOfReservationsForCustomer(customerhl.findByPrimaryKey(custId));
160     }
161
162     // standard call back methods
163
public void setEntityContext(EntityContext JavaDoc ec) {
164         try {
165             InitialContext JavaDoc cntx = new InitialContext JavaDoc();
166             seqHome = (SequenceSessionLocalHome) cntx.lookup("java:comp/env/ejb/SequenceSessionLocalHome");
167             customerhl = (CustomerHomeLocal) cntx.lookup("java:comp/env/ejb/CustomerLocalHome");
168             cruisehl = (CruiseHomeLocal) cntx.lookup("java:comp/env/ejb/CruiseLocalHome");
169             cabinhl = (CabinHomeLocal) cntx.lookup("java:comp/env/ejb/CabinLocalHome");
170             seqLocal = seqHome.create();
171         } catch (Exception JavaDoc e) {
172             throw new javax.ejb.EJBException JavaDoc(e);
173         }
174     }
175
176     public void unsetEntityContext() {
177     }
178
179     public void ejbLoad() {
180     }
181
182     public void ejbStore() {
183     }
184
185     public void ejbActivate() {
186     }
187
188     public void ejbPassivate() {
189     }
190
191     public void ejbRemove() throws RemoveException JavaDoc {
192     }
193
194 }
Popular Tags