Skip to main content

Transaction Data Retrieval and Processing Flow

In this document, we will explain the process of retrieving and processing transaction data. The process involves initiating the retrieval, handling core logic, executing an SQL query, and ensuring a database connection.

The flow starts by calling a method to initiate the retrieval of transaction data. This method then calls another method to handle the core logic, which includes setting default values and fetching the transaction data. The data is retrieved by executing an SQL query, and each transaction is processed and formatted. Finally, the database connection is ensured to be open and properly managed throughout the process.

Flow drill down


Retrieving and processing transaction data

First, the getProcessedTransactionExternal method is called to initiate the process of retrieving transaction data. This method calls getProcessedTransactionInternal to handle the core logic and then terminates the database connection.

	@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getProcessedTransactionExternal(
@QueryParam(LIMIT) Integer limit,
@QueryParam(OFFSET) Integer offset)
{
Response myResponse = getProcessedTransactionInternal(limit, offset);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
return myResponse;
}


Next, the getProcessedTransactionInternal method sets default values for limit and offset if they are not provided. It retrieves the sort code and calls getProcessedTransactions to fetch the transaction data. If the data is not accessible, it returns an error response. Otherwise, it processes each transaction, formats the data, and returns it in a JSON response.

	public Response getProcessedTransactionInternal(
@QueryParam(LIMIT) Integer limit,
@QueryParam(OFFSET) Integer offset)
{

if (offset == null)
{
offset = 0;
}
if (limit == null)
{
limit = 250000;
}
JSONObject response = new JSONObject();
JSONArray processedTransactionsJSON = null;
int numberOfProcessedTransactions = 0;
Integer sortCode = this.getSortCode();

com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransaction = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction[] processedTransactions = null;



Then, the getProcessedTransactions method constructs and executes an SQL query to retrieve transactions from the database. It processes each transaction record, handling different transaction types, and returns an array of ProcessedTransaction objects.

	public ProcessedTransaction[] getProcessedTransactions(int sortCode,
Integer limit, Integer offset)
{
logger.entering(this.getClass().getName(), GET_PROCESSED_TRANSACTIONS);

ProcessedTransaction[] temp = new ProcessedTransaction[limit];

this.offset = offset.intValue();
this.limit = limit.intValue();

StringBuilder myStringBuilder = new StringBuilder();

for (int i = Integer.toString(sortCode).length(); i < SORT_CODE_LENGTH; i++)
{
myStringBuilder.append('0');
}

myStringBuilder.append(Integer.toString(sortCode));
String sortCodeString = myStringBuilder.toString();

openConnection();


Moving to the openConnection method, it ensures a connection to the DB2 database is open. If the connection is closed or does not exist, it calls openConnectionInternal to establish a new connection.

	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 "


Finally, the openConnectionInternal method attempts to get a connection from the data source. If successful, it sets the transaction isolation level and stores the connection for reuse.

	@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