FileDocCategorySizeDatePackage
TellerBean.javaAPI DocJBoss 4.2.15843Fri Jul 13 20:53:28 BST 2007org.jboss.ejb3.test.bank

TellerBean

public class TellerBean extends Object implements Teller
see
author
$Author: wolfc $
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
private javax.ejb.TimerService
ts
private TransactionManager
tm
private Bank
bank
private boolean
constructed
private String
defaultValue
Constructors Summary
Methods Summary
public AccountcreateAccount(Customer customer, float balance)

      try
      {
        Bank bank = (Bank) new InitialContext()
               .lookup(Bank.JNDI_NAME);

         return null;
      } catch (Exception e)
      {
         log.debug("failed", e);
         throw new BankException("Could not create account", e);
      }
   
public voidexcludedMethod()


   
public AccountgetAccount(Customer customer, float balance)

      try
      {
         // Check for existing account
         Collection accounts = customer.getAccounts();
         if (accounts.size() > 0)
         {
            Iterator i = accounts.iterator();
            Account acct = (Account) i.next();
            // Set balance
            acct.withdraw(acct.getBalance() - balance);

            return acct;
         } else
         {
            // Create account
            return createAccount(customer, balance);
         }
      } catch (Exception e)
      {
         log.debug("failed", e);
         throw new BankException("Could not get account for " + customer, e);
      }
   
public CustomergetCustomer(java.lang.String name)

      try
      {
         // Check for existing customer

         return null;
      } catch (Exception e)
      {
         log.debug("failed", e);
         throw new BankException("Could not get customer for " + name, e);
      }
   
public java.lang.StringgetDefaultValue()

      return defaultValue;
   
public java.lang.StringgreetChecked(java.lang.String greeting)

      if (tm.getTransaction() == null) throw new Exception("method has no tx set");
      return greeting;
   
public java.lang.StringgreetUnchecked(java.lang.String greeting)

      if (tm.getTransaction() == null) throw new Exception("method has no tx set");
      return greeting;
   
public java.lang.StringgreetWithNotSupportedTransaction(java.lang.String greeting)

      if (tm.getTransaction() != null) throw new Exception("method has tx set");
      return greeting;
   
public java.lang.StringgreetWithRequiredTransaction(java.lang.String greeting)

      if (tm.getTransaction() == null) throw new Exception("method has no tx set");
      return greeting;
   
public java.lang.StringgreetWithServiceTimer(java.lang.String greeting)

      if (ts == null) throw new Exception("TimerService @Inject failed");
      return greeting;
   
public booleanisConstructed()


     
   
      return constructed;
   
public voidpostConstruct()

      constructed = true;
   
public java.lang.StringretrieveCustomerId()

      return bank.retrieveCustomerId();
   
public voidsetTransactionManager(javax.transaction.TransactionManager tm)

      this.tm = tm;
      System.out.println("TransactionManager set: " + tm);
   
public voidstoreCustomerId(java.lang.String customerId)

      bank.storeCustomerId(customerId);
   
public voidtestTransactionTimeout()

      boolean exceptionCaught = false;
      try
      {
         log.info("************* calling bank.testTransactionTimeout()");
         bank.testTransactionTimeout();
         log.info("************* finished calling bank.testTransactionTimeout()");
      }
      catch (Exception e)
      {
         log.info("********** caught exception");
         exceptionCaught = true;
      }
      if (!exceptionCaught) throw new RuntimeException("Failed to catch transactionTimeout");
   
public voidtransfer(Account from, Account to, float amount)

      try
      {
         from.withdraw(amount);
         to.deposit(amount);
      } catch (Exception e)
      {
         throw new BankException("Could not transfer " + amount + " from "
                                 + from + " to " + to, e);
      }
   
public voidtransferTest(Account from, Account to, float amount, int iter)

      for (int i = 0; i < iter; i++)
      {
         from.withdraw(amount);
         to.deposit(amount);
      }