Skip to main content

Creating a New Account Flow

In this document, we will explain the process of creating a new account. The process involves receiving account details, processing these details, and inserting the new account information into the database.

The flow starts with receiving the account details in JSON format. These details are then processed to ensure they are correct and complete. After processing, the account information is inserted into the database. If the insertion is successful, a confirmation response is sent back; otherwise, an error response is returned.

Flow drill down


writeCreateAccountExternal

First, the writeCreateAccountExternal method is called to initiate the account creation process. It receives the account details in JSON format and calls the writeCreateAccountInternal method to process these details. After processing, it terminates the database access object.

	@POST
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/createAccount")

public Response writeCreateAccountExternal(
ProcessedTransactionAccountJSON myCreatedAccount)
{
Response myResponse = writeCreateAccountInternal(myCreatedAccount);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
return myResponse;
}


writeCreateAccountInternal

Next, the writeCreateAccountInternal method processes the account details by calling the writeCreateAccount method. It checks if the account creation was successful and returns an appropriate response.

	public Response writeCreateAccountInternal(
ProcessedTransactionAccountJSON myCreatedAccount)
{
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransactionDB2 = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();
if (myProcessedTransactionDB2.writeCreateAccount(
myCreatedAccount.getSortCode(),
myCreatedAccount.getAccountNumber(),
myCreatedAccount.getActualBalance(),
myCreatedAccount.getLastStatement(),
myCreatedAccount.getNextStatement(),
myCreatedAccount.getCustomerNumber(),
myCreatedAccount.getType()))
{
return Response.ok().build();
}
else
{
return Response.serverError().build();
}

}


writeCreateAccount

Then, the writeCreateAccount method handles the actual database operations. It prepares the account details, opens a database connection, and inserts the new account information into the database. If the insertion is successful, it returns true; otherwise, it returns false.

	public boolean writeCreateAccount(String sortCode2, String accountNumber,
BigDecimal actualBalance, Date lastStatement, Date nextStatement,
String customerNumber, String accountType)
{
logger.entering(this.getClass().getName(), WRITE_CREATE_ACCOUNT);

sortOutDateTimeTaskString();

PROCTRAN myPROCTRAN = new PROCTRAN();

Calendar myCalendar = Calendar.getInstance();
myCalendar.setTime(lastStatement);

myPROCTRAN.setProcDescDelaccLastDd(myCalendar.get(Calendar.DATE));
myPROCTRAN.setProcDescDelaccLastMm(myCalendar.get(Calendar.MONTH) + 1);
myPROCTRAN.setProcDescDelaccLastYyyy(myCalendar.get(Calendar.YEAR));

myCalendar.setTime(nextStatement);
myPROCTRAN.setProcDescDelaccNextDd(myCalendar.get(Calendar.DATE));
myPROCTRAN.setProcDescDelaccNextMm(myCalendar.get(Calendar.MONTH) + 1);
myPROCTRAN.setProcDescDelaccNextYyyy(myCalendar.get(Calendar.YEAR));


openConnection

Going into the openConnection method, it ensures that a connection to the DB2 database is established. If a connection already exists, it reuses it; otherwise, it creates a new one by calling 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 "


openConnectionInternal

Finally, the openConnectionInternal method attempts to get a new database connection using JNDI lookup. 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