Skip to main content

Introduction to Processed Transactions

Introduction to Processed Transactions

Processed transactions refer to transactions that have been completed and recorded in the system. The ProcessedTransaction class is responsible for handling various operations related to these transactions, such as retrieving, writing, and managing transaction records.

ProcessedTransaction Class

The ProcessedTransaction class includes methods for writing different types of transactions, such as debits, credits, transfers, and customer or account creation and deletion. It also includes methods for retrieving processed transactions from the database, processing transaction records, and managing transaction details like amount, description, and date. This class ensures that all transaction records are properly logged and stored in the database.


The ProcessedTransaction class extends HBankDataAccess, indicating it inherits database access functionalities.

public class ProcessedTransaction extends HBankDataAccess
{

Writing Transactions

The ProcessedTransaction class provides several methods to write different types of transactions to the database. These methods ensure that the transaction details are correctly formatted and stored.


The writeDebit method writes a debit transaction to the database. It logs the transaction, prepares the SQL insert statement, and executes it to store the transaction details.

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


The writeCredit method logs and writes a credit transaction to the database. It prepares the SQL insert statement and executes it to store the transaction details.

			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);
stmt.executeUpdate();


The writeTransferLocal method logs and writes a local transfer transaction to the database. It prepares the SQL insert statement and executes it to store the transaction details, including the target account and sort code.

	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 + ">");

Retrieving Transactions

The ProcessedTransaction class also provides methods to retrieve processed transactions from the database. These methods construct SQL queries to fetch the relevant records and process each transaction to set its details.


The getProcessedTransactions method retrieves processed transactions from the database based on the provided sort code, limit, and offset. It constructs a SQL query to fetch the relevant records and processes each transaction to set its details.

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

Processing Transfer Records

The processTransferRecord method processes transfer records by setting appropriate flags and details. This ensures that transfer transactions are correctly identified and managed.


The processTransferRecord method processes transfer records by setting appropriate flags and details. If the transaction type is a transfer, it sets the target account number and sort code, and marks the transaction as a transfer.

	private ProcessedTransaction processTransferRecord(
ProcessedTransaction processedTransaction)
{
// If we're a "Transfer between accounts" record, set flags
// appropriately
if (processedTransaction.getType().compareTo("TFR") == 0)
{
String targetSortcodeInRecord = processedTransaction
.getDescription().substring(26, 32);
String targetAccountInRecord = processedTransaction.getDescription()
.substring(32, 40);

processedTransaction.setTargetAccountNumber(targetAccountInRecord);
processedTransaction.setTargetSortcode(targetSortcodeInRecord);
processedTransaction.setTransfer(true);
}
return processedTransaction;
}

 

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