1 package org.objectweb.jonas.jtests.beans.ejbql; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.Date ; 6 import java.util.Iterator ; 7 import java.util.Set ; 8 9 import javax.ejb.CreateException ; 10 import javax.ejb.EntityContext ; 11 import javax.ejb.FinderException ; 12 import javax.ejb.RemoveException ; 13 import javax.naming.InitialContext ; 14 15 public abstract class ReservationBean implements javax.ejb.EntityBean { 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 ejbCreate(Integer cruiseId, Collection customers) throws CreateException { 28 int id = seqLocal.getNextNumberInSequence("Reservation"); 29 setId(new Integer (id)); 30 return null; 31 } 32 33 public void ejbPostCreate(Integer cruiseId, Collection customers) { 34 35 try { 36 CruiseLocal cruise = cruisehl.findByPrimaryKey(cruiseId); 37 setCruise(cruise); 38 } catch (FinderException e) { 39 System.out.println("Cruise not find :" + cruiseId); 40 } 41 42 Collection myCustomers = this.getCustomers(); 43 44 ArrayList al; 45 if (customers == null) 46 al = new ArrayList (); 47 else { 48 if (customers.size() == -1) 49 al = new ArrayList (); 50 else { 51 al = new ArrayList (customers.size()); 52 for (Iterator it = customers.iterator(); it.hasNext();) { 53 Integer customerid = new Integer ("-1"); 54 try { 55 customerid = (Integer ) it.next(); 56 CustomerLocal customer = customerhl.findByPrimaryKey(customerid); 57 al.add(customer); 58 } catch (FinderException e) { 59 System.out.println("Customer not found " + customerid); 60 } 61 } 62 } 63 } 64 myCustomers.addAll(al); 65 } 66 67 public void setAllCabins(Set cabins) { 69 70 ArrayList al; 71 if (cabins == null) 72 al = new ArrayList (); 73 else { 74 if (cabins.size() == -1) 75 al = new ArrayList (); 76 else { 77 al = new ArrayList (cabins.size()); 78 for (Iterator it = cabins.iterator(); it.hasNext();) { 79 Integer cabinid = new Integer ("-1"); 80 try { 81 cabinid = (Integer ) it.next(); 82 CabinLocal cabin = cabinhl.findByPrimaryKey(cabinid); 83 al.add(cabin); 84 } catch (FinderException e) { 85 System.out.println("Cabin not found " + cabinid); 86 } 87 } 88 } 89 } 90 this.getCabins().addAll(al); 91 } 92 93 public abstract CruiseLocal getCruise(); 95 96 public abstract void setCruise(CruiseLocal cruise); 97 98 public abstract Set getCabins(); 99 100 public abstract void setCabins(Set cabins); 101 102 public abstract Set getCustomers(); 103 104 public abstract void setCustomers(Set customers); 105 106 public abstract Integer getId(); 107 108 public abstract void setId(Integer id); 109 110 public abstract Date getDate(); 111 112 public abstract void setDate(Date date); 113 114 public abstract double getAmountPaid(); 115 116 public abstract void setAmountPaid(double amount); 117 118 public abstract long ejbSelectCountOfReservations() throws FinderException ; 120 121 public abstract double ejbSelectMinAmountOfReservations() throws FinderException ; 122 123 public abstract double ejbSelectMinAmountForCruise(String cName) throws FinderException ; 124 125 public abstract Collection ejbSelectAmountsForCruise(String cName) throws FinderException ; 126 127 public abstract double ejbSelectMaxAmountOfReservations() throws FinderException ; 128 129 public abstract long ejbSelectCountOfReservationsForCustomer(CustomerLocal c) throws FinderException ; 130 131 public abstract long ejbSelectAmountOfReservationsForCustomer(CustomerLocal c) throws FinderException ; 132 133 public long ejbHomeGetCountOfReservations() throws FinderException { 135 return this.ejbSelectCountOfReservations(); 136 } 137 138 public double ejbHomeGetMinAmountOfReservations() throws FinderException { 139 return this.ejbSelectMinAmountOfReservations(); 140 } 141 142 public double ejbHomeGetMinAmountForCruise(String cName) throws FinderException { 143 return this.ejbSelectMinAmountForCruise(cName); 144 } 145 146 public double ejbHomeGetMaxAmountOfReservations() throws FinderException { 147 return this.ejbSelectMaxAmountOfReservations(); 148 } 149 150 public Collection ejbHomeGetAmountsForCruise(String cName) throws FinderException { 151 return this.ejbSelectAmountsForCruise(cName); 152 } 153 154 public long ejbHomeGetCountOfReservationsForCustomer(Integer custId) throws FinderException { 155 return this.ejbSelectCountOfReservationsForCustomer(customerhl.findByPrimaryKey(custId)); 156 } 157 158 public double ejbHomeGetAmountOfReservationsForCustomer(Integer custId) throws FinderException { 159 return this.ejbSelectAmountOfReservationsForCustomer(customerhl.findByPrimaryKey(custId)); 160 } 161 162 public void setEntityContext(EntityContext ec) { 164 try { 165 InitialContext cntx = new InitialContext (); 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 e) { 172 throw new javax.ejb.EJBException (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 { 192 } 193 194 } | Popular Tags |