Skip to main content

Handling Local Transfer Requests

In this document, we will explain the process of handling a local transfer request. The process involves receiving the transfer request, processing the transaction data, writing the transfer to the database, and managing the database connection.

The flow starts with receiving a transfer request. The request is then processed internally, where the transaction data is checked and prepared for database insertion. The transfer details are written to the database, ensuring the data is correctly formatted. Finally, the database connection is managed, ensuring it is open and ready for use, and handling any exceptions that may occur during the connection process.

Flow drill down


Handling the Transfer Request

First, the writeTransferLocalExternal method handles the incoming transfer request. It processes the transaction data and delegates the task to writeTransferLocalInternal for further processing. After processing, it terminates the database access object.

	@POST
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/transferLocal")
public Response writeTransferLocalExternal(
ProcessedTransactionTransferLocalJSON proctranLocal)
{
Response myResponse = writeTransferLocalInternal(proctranLocal);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
return myResponse;
}


Processing the Transfer Internally

Next, the writeTransferLocalInternal method processes the transaction data by interacting with the ProcessedTransaction class. It checks if the transaction is successful and returns an appropriate response.

	public Response writeTransferLocalInternal(
ProcessedTransactionTransferLocalJSON proctranLocal)
{
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransactionDB2 = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();

if (myProcessedTransactionDB2.writeTransferLocal(
proctranLocal.getSortCode(), proctranLocal.getAccountNumber(),
proctranLocal.getAmount(),
proctranLocal.getTargetAccountNumber()))
{
return Response.ok().build();
}
else
{
return Response.serverError().build();
}
}


Writing the Transfer to the Database

Then, the writeTransferLocal method constructs the transfer description and prepares the SQL statement to insert the transaction data into the database. It ensures the data is correctly formatted and handles any SQL exceptions.

	public boolean writeTransferLocal(String sortCode2, String accountNumber2,
BigDecimal amount2, String targetAccountNumber2)
{
logger.entering(this.getClass().getName(), WRITE_TRANSFER_LOCAL);

sortOutDateTimeTaskString();

String transferDescription = "";
transferDescription = transferDescription
+ PROCTRAN.PROC_TRAN_DESC_XFR_FLAG;
transferDescription = transferDescription.concat(" ");

transferDescription = transferDescription
.concat(padSortCode(Integer.parseInt(sortCode2)));

transferDescription = transferDescription.concat(
padAccountNumber(Integer.parseInt(targetAccountNumber2)));

openConnection();

logger.log(Level.FINE, () -> ABOUT_TO_INSERT + SQL_INSERT + ">");


Opening the Database Connection

Moving to the openConnection method, it manages the database connection. It checks if a connection already exists or needs to be created, ensuring the connection is open and ready for use.

	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 the Internal Database Connection

Finally, the openConnectionInternal method establishes the actual connection to the database using JNDI lookup. It handles any exceptions that may occur during the connection process.

	@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);

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human