Handling Debit and Credit Operations
In this document, we will explain the process of handling debit and credit operations on a bank account. The process involves retrieving account details, opening a database connection, and updating the account balance.
The flow starts by logging the entry and retrieving the account details. If the account is found, it opens a connection to the database and prepares SQL statements for querying and updating the account balance. The method then updates the account's actual and available balances and executes the update SQL statement. If the account is not found, it logs a warning and exits.
Flow drill down
Handling account debit and credit operations
First, the debitCredit
getAccount
public boolean debitCredit(BigDecimal apiAmount)
{
logger.entering(this.getClass().getName(), DEBIT_CREDIT_ACCOUNT);
Account temp = this.getAccount(
Integer.parseInt(this.getAccountNumber()),
Integer.parseInt(this.getSortcode()));
if (temp == null)
{
logger.log(Level.WARNING,
() -> "Unable to find account " + this.getAccountNumber());
logger.exiting(this.getClass().getName(), DEBIT_CREDIT_ACCOUNT,
false);
return false;
}
openConnection();
String accountNumberString = temp.getAccountNumber();
String sortCodeString = padSortCode(
Integer.parseInt(this.getSortcode()));
String sql1 = SQL_SELECT;
Retrieving account details
Next, the getAccount
Account
public Account getAccount(int accountNumber, int sortCode)
{
logger.entering(this.getClass().getName(), GET_ACCOUNT + accountNumber);
openConnection();
Account temp = null;
String sortCodeString = padSortCode(sortCode);
String sql9999 = "SELECT * from ACCOUNT where ACCOUNT_EYECATCHER LIKE 'ACCT' AND ACCOUNT_SORTCODE like ? order by ACCOUNT_NUMBER DESC";
String sql = SQL_SELECT;
try (PreparedStatement stmt9999 = conn.prepareStatement(sql9999);
PreparedStatement stmt = conn.prepareStatement(sql);)
{
if (accountNumber == 99999999)
{
logger.log(Level.FINE, () -> PRE_SELECT_MSG + sql9999 + ">");
stmt9999.setString(1, sortCodeString);
ResultSet rs = stmt9999.executeQuery();
if (rs.next())
{
Opening a database connection
Then, the openConnection
DB2
openConnectionInternal
protected void openConnection()
{
// Open a connection to the DB2 database
logger.entering(this.getClass().getName(), "openConnection()");
Integer taskNumberInteger = Task.getTask().getTaskNumber();
String db2ConnString = DB2CONN.concat(taskNumberInteger.toString());
logger.log(Level.FINE,
() -> "Attempting to get DB2CONN for task number "
+ taskNumberInteger.toString());
this.conn = (Connection) cornedBeef.get(db2ConnString);
if (this.conn == null)
{
HBankDataAccess.incrementConnCount();
logger.log(Level.FINE,
() -> "Attempting to create DB2CONN for task number "
+ taskNumberInteger.toString());
// Attempt to open a connection
openConnectionInternal();
logger.log(Level.FINE,
() -> "Creation succcessful for DB2CONN for task number "
Creating a new database connection
Finally, the openConnectionInternal
@SuppressWarnings("unchecked")
void openConnectionInternal()
{
logger.entering(this.getClass().getName(), "openConnectionInternal");
String jndiString = "jdbc/defaultCICSDataSource";
Context ctx;
try
{
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiString);
logger.log(Level.FINE, () -> "jndi string is " + jndiString);
// If there is no current connection
if (this.conn == null)
{
logger.log(Level.FINE,
() -> "About to attempt to get DB2 connection");
// Try and get a connection
this.conn = ds.getConnection();
this.conn.setTransactionIsolation(
Connection.TRANSACTION_READ_UNCOMMITTED);
Where is this flow used?
This flow is used once, in a flow starting from transferLocalExternal
as represented in the following diagram:
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human