if (source.getBalance().compareTo(amount) > 0) {
// transfer allowed
getAccountDao().updateBalance(sourceAccount, amount.negate());
getAccountDao().updateBalance(targetAccount, amount);
History history = new History();
history.setAccount(sourceAccount);
history.setAmount(amount);
history.setOperation("Paid out");
history.setTargetAccount(target);
history.setTransactionDate(new Date());
getHistoryDao().insert(history);
history = new History();
history.setAccount(targetAccount);
history.setAmount(amount);
history.setOperation("Paid in");
history.setTargetAccount(source);
history.setTransactionDate(new Date());
getHistoryDao().insert(history);
} else {
throw new RuntimeException("Not enough money");
}
}