String fromAccountId, String toAccountId) throws
InvalidParameterException,
AccountNotFoundException, InsufficientFundsException,
InsufficientCreditException {
Account fromAccount = checkAccountArgs(amount, description,
fromAccountId);
Account toAccount = checkAccountArgs(amount, description,
toAccountId);
String fromType = fromAccount.getType();
BigDecimal fromBalance = fromAccount.getBalance();
if (DomainUtil.isCreditAccount(fromType)) {
BigDecimal fromNewBalance = fromBalance.add(amount);
if (fromNewBalance.compareTo(fromAccount.getCreditLine()) == 1)
throw new InsufficientCreditException();
executeTx(amount, description, fromAccountId,
fromNewBalance, fromAccount);
} else {
BigDecimal fromNewBalance = fromBalance.subtract(amount);
if (fromNewBalance.compareTo(bigZero) == -1)
throw new InsufficientFundsException();
executeTx(amount.negate(), description, fromAccountId,
fromNewBalance, fromAccount);
}
String toType = toAccount.getType();
BigDecimal toBalance = toAccount.getBalance();
if (DomainUtil.isCreditAccount(toType)) {
BigDecimal toNewBalance = toBalance.subtract(amount);
executeTx(amount.negate(), description, toAccountId,
toNewBalance, toAccount);