Handling Debit and Credit Transactions
In this document, we will explain the process of handling debit and credit transactions. The process involves determining the type of transaction based on the amount and then processing it accordingly.
The flow starts by checking if the transaction amount is negative or positive. If the amount is negative, it is identified as a debit transaction and processed using the debit handling logic. If the amount is positive, it is identified as a credit transaction and processed using the credit handling logic. Both types of transactions involve preparing an SQL statement to insert a record into the database and executing it. If the insertion is successful, the transaction is considered complete; otherwise, an error is logged.
Flow drill down
Handling Debit and Credit Transactions
The writeInternal
writeDebit
writeCredit
public Response writeInternal(
ProcessedTransactionDebitCreditJSON proctranDbCr)
{
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransactionDB2 = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();
if (proctranDbCr.getAmount().compareTo(new BigDecimal(0)) < 0)
{
if (myProcessedTransactionDB2.writeDebit(
proctranDbCr.getAccountNumber(), proctranDbCr.getSortCode(),
proctranDbCr.getAmount()))
{
return Response.ok().build();
}
else
{
logger.severe("PROCTRAN Insert debit didn't work");
return Response.serverError().build();
}
}
else
{
Processing Debit Transactions
The writeDebit
public boolean writeDebit(String accountNumber, String sortcode,
BigDecimal amount2)
{
logger.entering(this.getClass().getName(), WRITE_DEBIT);
sortOutDateTimeTaskString();
openConnection();
logger.log(Level.FINE, () -> ABOUT_TO_INSERT + SQL_INSERT + ">");
try (PreparedStatement stmt = conn.prepareStatement(SQL_INSERT);)
{
stmt.setString(1, PROCTRAN.PROC_TRAN_VALID);
stmt.setString(2, sortcode);
stmt.setString(3,
String.format("%08d", Integer.parseInt(accountNumber)));
stmt.setString(4, dateString);
stmt.setString(5, timeString);
stmt.setString(6, taskRef);
stmt.setString(7, PROCTRAN.PROC_TY_DEBIT);
stmt.setString(8, "INTERNET WTHDRW");
Processing Credit Transactions
The writeCredit
writeDebit
public boolean writeCredit(String accountNumber, String sortcode,
BigDecimal amount2)
{
logger.entering(this.getClass().getName(), WRITE_CREDIT, false);
sortOutDateTimeTaskString();
openConnection();
logger.log(Level.FINE, () -> ABOUT_TO_INSERT + SQL_INSERT + ">");
try (PreparedStatement stmt = conn.prepareStatement(SQL_INSERT);)
{
stmt.setString(1, PROCTRAN.PROC_TRAN_VALID);
stmt.setString(2, sortcode);
stmt.setString(3,
String.format("%08d", Integer.parseInt(accountNumber)));
stmt.setString(4, dateString);
stmt.setString(5, timeString);
stmt.setString(6, taskRef);
stmt.setString(7, PROCTRAN.PROC_TY_CREDIT);
stmt.setString(8, "INTERNET RECVED");
stmt.setBigDecimal(9, amount2);
Opening Database Connection
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 "
Establishing Internal Database Connection
The openConnectionInternal
DB2
@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 multiple times in the codebase as represented in the following diagram:
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human