1 22 package org.jboss.test.banknew.ejb; 23 24 import java.rmi.RemoteException ; 25 import java.util.Collection ; 26 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBException ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 32 import org.jboss.test.banknew.interfaces.AccountData; 33 import org.jboss.test.banknew.interfaces.AccountSession; 34 import org.jboss.test.banknew.interfaces.AccountSessionHome; 35 import org.jboss.test.banknew.interfaces.BankException; 36 import org.jboss.test.banknew.interfaces.CustomerData; 37 import org.jboss.test.banknew.interfaces.CustomerSession; 38 import org.jboss.test.banknew.interfaces.CustomerSessionHome; 39 import org.jboss.test.util.ejb.SessionSupport; 40 41 65 public class TellerSessionBean 66 extends SessionSupport 67 { 68 69 private static final long serialVersionUID = -1977212418836289874L; 70 71 73 75 77 79 81 84 public void deposit( String pToAccountId, float pAmount ) 85 throws BankException 86 { 87 try { 88 getAccountSession().deposit( pToAccountId, pAmount ); 89 } 90 catch( Exception e ) { 91 sessionCtx.setRollbackOnly(); 92 throw new BankException( "Could not deposit " + pAmount + 93 " to " + pToAccountId, e ); 94 } 95 } 96 97 100 public void transfer( String pFromAccountId, String pToAccountId, float pAmount ) 101 throws BankException 102 { 103 try { 104 getAccountSession().transfer( pFromAccountId, pToAccountId, pAmount ); 105 } 106 catch( Exception e ) { 107 sessionCtx.setRollbackOnly(); 108 throw new BankException( "Could not transfer " + pAmount + 109 " from " + pFromAccountId + " to " + pToAccountId, e ); 110 } 111 } 112 113 116 public void withdraw( String pFromAccountId, float pAmount ) 117 throws BankException 118 { 119 try { 120 getAccountSession().withdraw( pFromAccountId, pAmount ); 121 } 122 catch( Exception e ) { 123 sessionCtx.setRollbackOnly(); 124 throw new BankException( "Could not withdraw " + pAmount + 125 " from " + pFromAccountId, e ); 126 } 127 } 128 129 132 public AccountData createAccount( String pCustomerId, int pType, float pInitialDeposit ) 133 throws BankException 134 { 135 try { 136 return getAccountSession().createAccount( pCustomerId, pType, pInitialDeposit ); 137 } 138 catch( Exception e ) { 139 sessionCtx.setRollbackOnly(); 140 e.printStackTrace(); 141 throw new BankException( "Could not create account", e ); 142 } 143 } 144 145 148 public void removeAccount( String pAccountId ) 149 throws BankException 150 { 151 try { 152 getAccountSession().removeAccount( pAccountId ); 153 } 154 catch( Exception e ) { 155 sessionCtx.setRollbackOnly(); 156 e.printStackTrace(); 157 throw new BankException( "Could not remove account", e ); 158 } 159 } 160 161 164 public void removeAccount( String pCustomerId, int pType ) 165 throws BankException 166 { 167 try { 168 getAccountSession().removeAccount( pCustomerId, pType ); 169 } 170 catch( Exception e ) { 171 sessionCtx.setRollbackOnly(); 172 e.printStackTrace(); 173 throw new BankException( "Could not remove account", e ); 174 } 175 } 176 177 180 public Collection getAccounts( String pCustomerId ) 181 throws BankException 182 { 183 try { 184 return getAccountSession().getAccounts( pCustomerId ); 185 } 186 catch( Exception e ) { 187 sessionCtx.setRollbackOnly(); 188 e.printStackTrace(); 189 throw new BankException( "Could not remove account", e ); 190 } 191 } 192 193 196 public AccountData getAccount( String pCustomerId, int pType ) 197 throws BankException 198 { 199 try { 200 return getAccountSession().getAccount( pCustomerId, pType ); 201 } 202 catch( Exception e ) { 203 sessionCtx.setRollbackOnly(); 204 e.printStackTrace(); 205 throw new BankException( "Could not remove account", e ); 206 } 207 } 208 209 212 public AccountData getAccount( String pAccountId ) 213 throws BankException 214 { 215 try { 216 return getAccountSession().getAccount( pAccountId ); 217 } 218 catch( Exception e ) { 219 sessionCtx.setRollbackOnly(); 220 e.printStackTrace(); 221 throw new BankException( "Could not remove account", e ); 222 } 223 } 224 225 228 public CustomerData createCustomer( String pBankId, String pName, float pInitialDeposit ) 229 throws BankException 230 { 231 try { 232 return getCustomerSession().createCustomer( pBankId, pName, pInitialDeposit ); 233 } 234 catch( Exception e ) { 235 sessionCtx.setRollbackOnly(); 236 e.printStackTrace(); 237 throw new BankException( "Could not create account", e ); 238 } 239 } 240 241 244 public void removeCustomer( String pCustomerId ) 245 throws BankException 246 { 247 try { 248 getCustomerSession().removeCustomer( pCustomerId ); 249 } 250 catch( Exception e ) { 251 sessionCtx.setRollbackOnly(); 252 e.printStackTrace(); 253 throw new BankException( "Could not remove account", e ); 254 } 255 } 256 257 260 public CustomerData getCustomer( String pCustomerId ) 261 throws BankException 262 { 263 try { 264 CustomerSession lSession = getCustomerSession(); 265 return lSession.getCustomer( pCustomerId ); 266 } 267 catch( Exception e ) { 268 e.printStackTrace(); 269 throw new BankException( "Could not get customer for " + pCustomerId, e ); 270 } 271 } 272 273 276 public Collection getCustomers( String pBankId ) 277 throws BankException 278 { 279 try { 280 return getCustomerSession().getCustomers( pBankId ); 281 } 282 catch( Exception e ) { 283 e.printStackTrace(); 284 throw new BankException( "Could not get customers for bank " + pBankId, e ); 285 } 286 } 287 288 private AccountSession getAccountSession() 289 throws RemoteException 290 { 291 try { 292 AccountSessionHome lHome = (AccountSessionHome) new InitialContext ().lookup( AccountSessionHome.COMP_NAME ); 293 return lHome.create(); 294 } 295 catch( NamingException ne ) { 296 throw new EJBException ( ne ); 297 } 298 catch( CreateException ce ) { 299 throw new EJBException ( ce ); 300 } 301 } 302 303 private CustomerSession getCustomerSession() 304 throws RemoteException 305 { 306 try { 307 CustomerSessionHome lHome = (CustomerSessionHome) new InitialContext ().lookup( CustomerSessionHome.COMP_NAME ); 308 return lHome.create(); 309 } 310 catch( NamingException ne ) { 311 throw new EJBException ( ne ); 312 } 313 catch( CreateException ce ) { 314 throw new EJBException ( ce ); 315 } 316 } 317 318 } 319 362 | Popular Tags |