예제 #1
0
 @TransactionAttribute(TransactionAttributeType.REQUIRED)
 public long openAccount(String name, float initialBalance) throws NegativeBalanceException {
   checkForPositiveBalance(initialBalance);
   Account account = new Account();
   account.setBalance(initialBalance);
   account.setName(name);
   entityManager.persist(account);
   return account.getId();
 }
예제 #2
0
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public float deposit(long accountNumber, float amount)
      throws NegativeBalanceException, AccountNotFoundException {
    checkForPositiveBalance(amount);
    Account account = findAccount(accountNumber);
    float newBalance = account.getBalance() + amount;
    account.setBalance(newBalance);

    entityManager.merge(account);

    return newBalance;
  }
예제 #3
0
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public float withdraw(long accountNumber, float amount)
      throws NegativeBalanceException, InsufficientBalanceException, AccountNotFoundException {
    checkForPositiveBalance(amount);
    Account account = findAccount(accountNumber);

    if (account.getBalance() < amount) {
      throw new InsufficientBalanceException();
    }
    float newBalance = account.getBalance() - amount;
    account.setBalance(newBalance);

    entityManager.merge(account);

    return newBalance;
  }