Skip to content

Instantly share code, notes, and snippets.

@kubawieczorek
Created January 20, 2023 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubawieczorek/d7282fdda3301f1cd4c6e399d8b4cd0d to your computer and use it in GitHub Desktop.
Save kubawieczorek/d7282fdda3301f1cd4c6e399d8b4cd0d to your computer and use it in GitHub Desktop.
try (PreparedStatement selectAccountStatementFrom = connection.prepareStatement(SELECT_ACCOUNT_BY_OWNER_SQL);
PreparedStatement selectAccountStatementTo = connection.prepareStatement(SELECT_ACCOUNT_BY_OWNER_SQL);
PreparedStatement updateAccountStatement = connection.prepareStatement(UPDATE_ACCOUNT_SQL)) {
ResultSet accountFrom = findAccount(bankTransfer.getFrom(), selectAccountStatementFrom);
ResultSet accountTo = findAccount(bankTransfer.getTo(), selectAccountStatementTo);
BigDecimal amount = bankTransfer.getAmount();
if (dataPresent(accountFrom, accountTo)) {
if (sufficientAccountBalance(amount, accountFrom)) {
decreaseAccountBalance(updateAccountStatement, accountFrom, amount);
updateAccountStatement.executeUpdate();
increaseAccountBalance(updateAccountStatement, accountTo, amount);
updateAccountStatement.executeUpdate();
} else {
throw new BusinessException("Insufficient account balance");
}
} else {
throw new BusinessException("Incorrect account provided");
}
} catch (Exception e) {
throw new RuntimeException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment