Skip to main content

Deleting a Customer Record Flow

In this document, we will explain the process of deleting a customer record. The process involves several steps including initiating the deletion, handling internal logic, performing the actual deletion in the database, and ensuring a connection to the database is established.

The flow starts with initiating the deletion process by receiving customer details. Then, the internal logic processes these details and calls the method to perform the actual deletion in the database. Before executing the deletion query, a connection to the database is established. If a new connection is needed, it retrieves the data source and sets up the connection parameters.

Flow drill down


Deleting a Customer Record

First, the writeDeleteCustomerExternal method is called to initiate the deletion process. It receives the customer details and calls writeDeleteCustomerInternal to handle the internal logic.

	@POST
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/deleteCustomer")
public Response writeDeleteCustomerExternal(
ProcessedTransactionDeleteCustomerJSON myDeletedCustomer)
{
Response myResponse = writeDeleteCustomerInternal(myDeletedCustomer);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
return myResponse;
}


Internal Deletion Logic

Next, the writeDeleteCustomerInternal method processes the customer details and calls the writeDeleteCustomer method to perform the actual deletion in the database.

	public Response writeDeleteCustomerInternal(
ProcessedTransactionDeleteCustomerJSON myDeletedCustomer)
{
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransactionDB2 = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();

if (myProcessedTransactionDB2.writeDeleteCustomer(
myDeletedCustomer.getSortCode(),
myDeletedCustomer.getAccountNumber(), 0.00,
myDeletedCustomer.getCustomerDOB(),
myDeletedCustomer.getCustomerName(),
myDeletedCustomer.getCustomerNumber()))
{
return Response.ok().build();
}
else
{
return Response.serverError().build();
}

}


Database Deletion

Then, the writeDeleteCustomer method constructs the SQL query to delete the customer record from the database. It formats the customer details and executes the query.

	public boolean writeDeleteCustomer(String sortCode2, String accountNumber,
double amountWhichWillAlwaysBeZero, Date customerDOB,
String customerName, String customerNumber)
{
logger.entering(this.getClass().getName(), WRITE_DELETE_CUSTOMER);

sortOutDateTimeTaskString();
String customerDOBString = sortOutCustomerDOB(customerDOB);
String deleteCustomerDescription = "";

StringBuilder myStringBuilder = new StringBuilder();
for (int z = sortCode2.length(); z < 6; z++)
{
myStringBuilder = myStringBuilder.append("0");
}
myStringBuilder.append(sortCode2);


deleteCustomerDescription = deleteCustomerDescription.concat(myStringBuilder.toString());

deleteCustomerDescription = deleteCustomerDescription


Opening Database Connection

Moving to the openConnection method, it ensures that a connection to the DB2 database is established before executing the deletion query.

	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 Connection

Finally, the openConnectionInternal method is called if a new connection needs to be established. It retrieves the data source and sets up the connection parameters.

	@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