1 25 26 package org.objectweb.jonas.jtests.beans.ejbql; 27 28 import javax.ejb.CreateException ; 29 import javax.ejb.EJBException ; 30 import javax.ejb.SessionBean ; 31 import javax.ejb.SessionContext ; 32 import javax.naming.InitialContext ; 33 34 import org.objectweb.jonas.common.Log; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 import org.objectweb.util.monolog.api.Logger; 37 38 39 43 public class SessionTestBean implements SessionBean { 44 45 static protected Logger logger = null; 46 protected SessionContext ctx = null; 47 protected CustomerHomeLocal hCustomer = null; 48 protected PhoneHomeLocal hPhone = null; 49 50 public void setSessionContext(SessionContext ctx) { 52 if (logger == null) { 53 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 54 } 55 logger.log(BasicLevel.DEBUG, ""); 56 this.ctx = ctx; 57 try { 58 InitialContext inctx = new InitialContext (); 59 hCustomer = (CustomerHomeLocal) inctx.lookup("java:comp/env/ejb/CustomerHomeLocal"); 60 hPhone = (PhoneHomeLocal) inctx.lookup("java:comp/env/ejb/PhoneHomeLocal"); 61 } catch (Exception e) { 62 throw new javax.ejb.EJBException (e); 63 } 64 } 65 66 public void ejbCreate() throws CreateException { 67 logger.log(BasicLevel.DEBUG, ""); 68 } 69 70 public void ejbRemove() { 71 logger.log(BasicLevel.DEBUG, ""); 72 } 73 74 public void ejbPassivate() { 75 logger.log(BasicLevel.DEBUG, ""); 76 } 77 78 public void ejbActivate() { 79 logger.log(BasicLevel.DEBUG, ""); 80 } 81 82 public Integer getCustomerWithPhone(String phoneNumber) throws EJBException { 84 try { 85 PhoneLocal phone = hPhone.findByNumber(phoneNumber); 86 CustomerLocal customer = hCustomer.findCustomerWithPhone(phone); 87 return customer.getId(); 88 } catch (Exception e) { 89 logger.log(BasicLevel.ERROR, "Cannot get the customer with phone " + phoneNumber, e); 90 throw new EJBException ("Cannot get the customer with phone " + phoneNumber, e); 91 } 92 } 93 } 94 95 | Popular Tags |