1 22 package org.jboss.test.banknew.ejb; 23 24 import java.rmi.RemoteException ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 29 import javax.ejb.CreateException ; 30 import javax.ejb.EJBException ; 31 import javax.ejb.FinderException ; 32 import javax.ejb.RemoveException ; 33 import javax.ejb.SessionContext ; 34 import javax.naming.InitialContext ; 35 import javax.naming.NamingException ; 36 37 import org.jboss.test.banknew.interfaces.Bank; 38 import org.jboss.test.banknew.interfaces.BankData; 39 import org.jboss.test.banknew.interfaces.BankHome; 40 import org.jboss.test.banknew.interfaces.BankPK; 41 import org.jboss.test.banknew.interfaces.CustomerData; 42 import org.jboss.test.banknew.interfaces.CustomerSession; 43 import org.jboss.test.banknew.interfaces.CustomerSessionHome; 44 import org.jboss.test.util.ejb.SessionSupport; 45 46 70 public class BankSessionBean 71 extends SessionSupport 72 { 73 74 76 78 80 82 84 85 private static final long serialVersionUID = -4732008507323917820L; 86 87 90 public BankData createBank( String pName, String pAddress ) 91 throws CreateException , RemoteException 92 { 93 Bank lBank = getBankHome().create( pName, pAddress ); 94 return lBank.getData(); 95 } 96 97 100 public void removeBank( String pBankId ) 101 throws RemoveException , RemoteException 102 { 103 try { 104 getBankHome().findByPrimaryKey( 105 new BankPK( pBankId ) 106 ).remove(); 107 } 108 catch( FinderException fe ) { 109 } 110 } 111 112 115 public Collection getBanks() 116 throws FinderException , RemoteException 117 { 118 Collection lBanks = getBankHome().findAll(); 119 Collection lList = new ArrayList ( lBanks.size() ); 120 Iterator i = lBanks.iterator(); 121 while( i.hasNext() ) { 122 lList.add( ( (Bank) i.next() ).getData() ); 123 } 124 return lList; 125 } 126 127 130 public CustomerData getCustomer( String pCustomerId ) 131 throws FinderException , RemoteException 132 { 133 return getCustomerSession().getCustomer( pCustomerId ); 134 } 135 136 139 public Collection getCustomers( String pBankId ) 140 throws FinderException , RemoteException 141 { 142 return getCustomerSession().getCustomers( pBankId ); 143 } 144 145 148 public CustomerData createCustomer( String pBankId, String pName, float pInitialDeposit ) 149 throws CreateException , RemoteException 150 { 151 return getCustomerSession().createCustomer( 152 pBankId, 153 pName, 154 pInitialDeposit 155 ); 156 } 157 158 161 public void removeCustomer( String pCustomerId ) 162 throws RemoveException , RemoteException 163 { 164 getCustomerSession().removeCustomer( 165 pCustomerId 166 ); 167 } 168 169 private BankHome getBankHome() { 170 try { 171 return (BankHome) new InitialContext ().lookup( BankHome.COMP_NAME ); 172 } 173 catch( NamingException ne ) { 174 throw new EJBException ( ne ); 175 } 176 } 177 178 private CustomerSession getCustomerSession() 179 throws RemoteException 180 { 181 try { 182 return ( (CustomerSessionHome) new InitialContext ().lookup( CustomerSessionHome.COMP_NAME ) ).create(); 183 } 184 catch( NamingException ne ) { 185 throw new EJBException ( ne ); 186 } 187 catch( CreateException ce ) { 188 throw new EJBException ( ce ); 189 } 190 } 191 192 public void setSessionContext(SessionContext context) 194 { 195 super.setSessionContext(context); 196 } 197 } 198 199 242 | Popular Tags |