1 package org.objectweb.jonas.jtests.beans.ejbql; 2 3 import javax.ejb.FinderException ; 4 import javax.ejb.EJBException ; 5 import javax.ejb.EntityContext ; 6 import javax.ejb.CreateException ; 7 import javax.naming.InitialContext ; 8 import javax.naming.NamingException ; 9 10 import java.util.ArrayList ; 11 import java.util.Collection ; 12 import java.util.Date ; 13 import java.util.Iterator ; 14 import java.util.Set ; 15 import java.util.Vector ; 16 import java.rmi.RemoteException ; 17 18 public abstract class CustomerBean implements javax.ejb.EntityBean { 19 20 private CruiseHomeLocal cruiseHomeLocal = null; 21 22 private CustomerHomeLocal customerHomeLocal = null; 23 24 private CreditCardHomeLocal creditCardHomeLocal = null; 25 26 private CreditCompanyHomeLocal creditCompanyHomeLocal = null; 27 28 private AddressHomeLocal addressHomeLocal = null; 29 30 public Integer ejbCreate(Integer id) throws javax.ejb.CreateException { 31 this.setId(id); 32 return null; 33 } 34 35 public void ejbPostCreate(Integer id) { 36 } 37 38 39 41 public Name getName() { 42 Name name = new Name(getLastName(), getFirstName()); 43 return name; 44 } 45 public void setName(Name name) { 46 setLastName(name.getLastName()); 47 setFirstName(name.getFirstName()); 48 } 49 50 public void setAddress(String street, String city, String state, String zip) 51 throws EJBException { 52 53 AddressLocal addr = this.getHomeAddress(); 54 55 try { 56 57 if (addr == null) { 58 InitialContext cntx = new InitialContext (); 60 AddressHomeLocal addrHome = 61 (AddressHomeLocal) cntx.lookup("java:comp/env/ejb/AddressHomeLocal"); 62 addr = addrHome.createAddress(street, city, state, zip); 63 this.setHomeAddress(addr); 64 } else { 65 addr.setStreet(street); 67 addr.setCity(city); 68 addr.setState(state); 69 addr.setZip(zip); 70 } 71 } catch (NamingException ne) { 72 throw new EJBException (ne); 73 } catch (CreateException ce) { 74 throw new EJBException (ce); 75 } 76 } 77 78 public void setAddress(AddressDO addrValue) throws CreateException , NamingException { 79 String street = addrValue.getStreet(); 80 String city = addrValue.getCity(); 81 String state = addrValue.getState(); 82 String zip = addrValue.getZip(); 83 84 setAddress(street, city, state, zip); 85 } 86 87 88 public AddressDO getAddress() { 89 90 AddressLocal addrLocal = this.getHomeAddress(); 91 if (addrLocal == null) { 92 return null; 93 } 94 String street = addrLocal.getStreet(); 95 String city = addrLocal.getCity(); 96 String state = addrLocal.getState(); 97 String zip = addrLocal.getZip(); 98 AddressDO addrValue = new AddressDO(street, city, state, zip); 99 return addrValue; 100 } 101 102 public void addPhoneNumber(String number, byte type) 103 throws NamingException , CreateException , RemoteException { 104 InitialContext jndiEnc = new InitialContext (); 105 PhoneHomeLocal phoneHome = (PhoneHomeLocal) (jndiEnc.lookup("java:comp/env/ejb/PhoneHomeLocal")); 106 107 PhoneLocal phone = phoneHome.create(number, type); 108 Collection phoneNumbers = this.getPhoneNumbers(); 109 phoneNumbers.add(phone); 110 } 111 112 public void removePhoneNumber(byte typeToRemove) { 113 114 Collection phoneNumbers = this.getPhoneNumbers(); 115 Iterator iterator = phoneNumbers.iterator(); 116 117 while (iterator.hasNext()) { 118 PhoneLocal phone = (PhoneLocal) iterator.next(); 119 if (phone.getType() == typeToRemove) { 120 phoneNumbers.remove(phone); 121 break; 122 } 123 124 } 125 } 126 127 public void updatePhoneNumber(String number, byte typeToUpdate) { 128 129 130 Collection phoneNumbers = this.getPhoneNumbers(); 131 Iterator iterator = phoneNumbers.iterator(); 132 while (iterator.hasNext()) { 133 PhoneLocal phone = (PhoneLocal) iterator.next(); 134 if (phone.getType() == typeToUpdate) { 135 phone.setNumber(number); 136 break; 137 } 138 } 139 } 140 141 public Vector getPhoneList() { 142 143 Vector vv = new Vector (); 144 Collection phoneNumbers = this.getPhoneNumbers(); 145 146 Iterator iterator = phoneNumbers.iterator(); 147 while (iterator.hasNext()) { 148 PhoneLocal phone = (PhoneLocal) iterator.next(); 149 String ss = "Type=" + phone.getType() + " Number=" + phone.getNumber(); 150 vv.add(ss); 151 } 152 153 return vv; 154 } 155 156 public Collection ejbHomeCallFindOnCruise(Integer cruiseId) throws FinderException { 157 158 ArrayList customers_id = new ArrayList (); 159 CruiseLocal crloc = null; 160 if (cruiseId != null) { 161 crloc = cruiseHomeLocal.findByPrimaryKey(cruiseId); 162 } 163 Collection customers = customerHomeLocal.findOnCruise(crloc); 164 Iterator customer = customers.iterator(); 165 while (customer.hasNext()) { 166 CustomerLocal customer_local = (CustomerLocal) customer.next(); 167 customers_id.add(customer_local.getId()); 168 } 169 return customers_id; 170 } 171 172 public Collection ejbHomeCallFindByAddressLocal(Integer add) throws FinderException { 173 ArrayList customers_id = new ArrayList (); 174 AddressLocal addloc = null; 175 if (add != null) { 176 addloc = addressHomeLocal.findByPrimaryKey(add); 177 } 178 Collection customers = customerHomeLocal.findByAddressLocal(addloc); 179 Iterator customer = customers.iterator(); 180 while (customer.hasNext()) { 181 CustomerLocal customer_local = (CustomerLocal)customer.next(); 182 customers_id.add(customer_local.getId()); 183 } 184 return customers_id; 185 } 186 187 public Collection ejbHomeCallFindByParameterIsNull(Integer cc) throws FinderException { 188 ArrayList customers_id = new ArrayList (); 189 CreditCardLocal ccloc = null; 190 if (cc != null) { 191 ccloc = creditCardHomeLocal.findByPrimaryKey(cc); 192 } 193 Collection customers = customerHomeLocal.findByParameterIsNull(ccloc); 194 Iterator customer = customers.iterator(); 195 while (customer.hasNext()) { 196 CustomerLocal customer_local = (CustomerLocal)customer.next(); 197 customers_id.add(customer_local.getId()); 198 } 199 return customers_id; 200 } 201 202 public void setCreditCard(Date expCreditcard, String numbCreditcard, String nameCreditcard, String orgCreditcard , String nameCreditCompany, String streetAddress, String cityAddress, String stateAddress, String zipAddress ) { 203 204 try { 208 CreditCardLocal creditcard = creditCardHomeLocal.create(expCreditcard, numbCreditcard, nameCreditcard, orgCreditcard); 209 this.setCreditCard(creditcard); 210 CreditCompanyLocal creditcompany = creditCompanyHomeLocal.create(nameCreditCompany); 211 creditcard.setCreditCompany(creditcompany); 212 AddressLocal address = addressHomeLocal.createAddress(streetAddress, cityAddress, stateAddress, zipAddress); 213 creditcompany.setAddress(address); 214 } catch (CreateException e) { 215 System.out.println ("Probleme dans creation du CreditCompany/Address/CrediCard"); 216 e.printStackTrace(System.out); 217 } 218 219 } 220 221 223 public abstract AddressLocal getHomeAddress(); 224 public abstract void setHomeAddress(AddressLocal address); 225 226 public abstract CreditCardLocal getCreditCard(); 227 public abstract void setCreditCard(CreditCardLocal card); 228 229 public abstract java.util.Collection getPhoneNumbers( ); 230 public abstract void setPhoneNumbers(java.util.Collection phones); 231 232 public abstract Integer getId(); 234 public abstract void setId(Integer id); 235 236 public abstract String getLastName( ); 237 public abstract void setLastName(String lname); 238 239 public abstract String getFirstName( ); 240 public abstract void setFirstName(String fname); 241 242 public abstract boolean getHasGoodCredit(); 243 public abstract void setHasGoodCredit(boolean flag); 244 245 public abstract String ejbSelectAddrCity(Integer id) throws FinderException ; 247 public abstract String ejbSelectLastName(Integer id) throws FinderException ; 248 public abstract Set ejbSelectFirstName() throws FinderException ; 249 public abstract Collection ejbSelectDistinctFirstName() throws FinderException ; 250 public abstract AddressLocal ejbSelectAddr(Integer id) throws FinderException ; 251 public abstract Collection ejbSelectAllCreditCardAddr() throws FinderException ; 252 public abstract Collection ejbSelectRogerAddr() throws FinderException ; 253 public abstract long ejbSelectCountCreditCard() throws FinderException ; 254 public abstract Collection ejbSelectCreditCardNumbers() throws FinderException ; 255 public abstract long ejbSelectCountOfCustomersWithId1(Integer id) throws FinderException ; 256 public abstract long ejbSelectCountOfCustomersWithId2(int id) throws FinderException ; 257 public abstract long ejbSelectCountOfCustomersRingo() throws FinderException ; 258 259 public String ejbHomeSelectAddrCity(Integer id) throws FinderException { 262 return this.ejbSelectAddrCity(id); 263 } 264 public String ejbHomeSelectLastName(Integer id) throws FinderException { 265 return this.ejbSelectLastName(id); 266 } 267 public Set ejbHomeSelectFirstName() throws FinderException { 268 return this.ejbSelectFirstName(); 269 } 270 public Collection ejbHomeSelectDistinctFirstName() throws FinderException { 271 return this.ejbSelectDistinctFirstName(); 272 } 273 public Integer ejbHomeSelectAddr(Integer id) throws FinderException { 274 AddressLocal address = this.ejbSelectAddr(id); 275 return address.getId(); 276 } 277 public Collection ejbHomeSelectAllCreditCardAddr() throws FinderException { 278 Collection addresses = this.ejbSelectAllCreditCardAddr(); 279 ArrayList addresses_id = new ArrayList (); 280 Iterator iAddr = addresses.iterator(); 281 while (iAddr.hasNext()) { 282 AddressLocal address = (AddressLocal) iAddr.next(); 283 addresses_id.add(address.getId()); 284 } 285 return addresses_id; 286 } 287 public Collection ejbHomeSelectRogerAddr() throws FinderException { 288 Collection addresses = this.ejbSelectRogerAddr(); 289 ArrayList addresses_id = new ArrayList (); 290 Iterator iAddr = addresses.iterator(); 291 while (iAddr.hasNext()) { 292 AddressLocal address = (AddressLocal) iAddr.next(); 293 addresses_id.add(address.getId()); 294 } 295 return addresses_id; 296 } 297 public long ejbHomeGetCountCreditCard() throws FinderException { 298 return this.ejbSelectCountCreditCard(); 299 } 300 public Collection ejbHomeGetCreditCardNumbers() throws FinderException { 301 return this.ejbSelectCreditCardNumbers(); 302 } 303 public long ejbHomeGetCountCustomersWithId1(Integer id) throws FinderException { 304 return this.ejbSelectCountOfCustomersWithId1(id); 305 } 306 public long ejbHomeGetCountCustomersWithId2(int id) throws FinderException { 307 return this.ejbSelectCountOfCustomersWithId2(id); 308 } 309 public long ejbHomeGetCountCustomersRingo() throws FinderException { 310 return this.ejbSelectCountOfCustomersRingo(); 311 } 312 313 315 public void setEntityContext(EntityContext ec) { 316 try { 317 InitialContext cntx = new InitialContext (); 318 cruiseHomeLocal = 319 (CruiseHomeLocal) cntx.lookup("java:comp/env/ejb/CruiseHomeLocal"); 320 customerHomeLocal = 321 (CustomerHomeLocal) cntx.lookup("java:comp/env/ejb/CustomerHomeLocal"); 322 creditCardHomeLocal = 323 (CreditCardHomeLocal) cntx.lookup("java:comp/env/ejb/CreditCardHomeLocal"); 324 creditCompanyHomeLocal = 325 (CreditCompanyHomeLocal) cntx.lookup("java:comp/env/ejb/CreditCompanyHomeLocal"); 326 addressHomeLocal = 327 (AddressHomeLocal) cntx.lookup("java:comp/env/ejb/AddressHomeLocal"); 328 } catch (Exception e) { 329 throw new javax.ejb.EJBException (e); 330 } 331 } 332 333 public void unsetEntityContext() { } 334 public void ejbLoad() { } 335 public void ejbStore() { } 336 public void ejbActivate() { } 337 public void ejbPassivate() { } 338 public void ejbRemove() throws javax.ejb.RemoveException { } 339 340 } 341 | Popular Tags |