Class SQLite

java.lang.Object
com.atmbanksimulator.SQLite

public class SQLite extends Object

ATM Simulator - SQLite Database: Memory

The SQLite class manages all direct interactions with the SQLite database. It provides methods to query and update account details, customer information, transaction history, PINs, plans, and withdrawal limits. It serves as the data layer for the entire ATM system, used by Bank and BankAccount.

Version:
3.0
Author:
D'Souza, C. J.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Establishes a connection to the SQLite database at the configured URL.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changeBalance(String accountNumber, float balance)
    Updates the balance for the given account number in the database.
    boolean
    checkAccountExist(String accountNumber)
    Checks whether an account with the given number exists in the AccountDetails table.
    getAccountDetails(String accountNumber)
    Retrieves all account and personal details for the given account number by joining the Customer, AccountDetails, and TransactionHistory tables.
    float
    getBalance(String accountNumber)
    Retrieves the current balance for the given account number.
    getName(String accountNumber)
    Retrieves the full name of the customer linked to the given account number, formed by joining the Customer and AccountDetails tables.
    getPasswd(String accountNumber)
    Retrieves the stored PIN for the given account number.
    Retrieves the full transaction history for the given account number, ordered by most recent first.
    float
    getWithdrawalLimit(String accountNumber)
    Retrieves the current one-time withdrawal limit for the given account number.
    void
    insertTransaction(String accountNumber, String type, Float amount)
    Inserts a new transaction record into the TransactionHistory table and updates the recentActivity timestamp on the associated account.
    void
    updatePin(String accountNumber, String pin)
    Updates the PIN for the given account number in the database.
    void
    updatePlan(String accountNumber, String type, String tier, float withdrawalLimit)
    Updates the account type, tier, and withdrawal limit for the given account number.
    void
    updateRecentActivity(String accountNumber, String dateTime)
    Updates the recentActivity timestamp for the given account number.
    void
    updateWithdrawalLimit(String accountNumber, float withdrawalLimit)
    Updates the one-time withdrawal limit for the given account number in the database.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SQLite

      public SQLite()
      Establishes a connection to the SQLite database at the configured URL. Prints "Success" to the console on a successful connection.
      Throws:
      RuntimeException - if the database connection fails
  • Method Details

    • checkAccountExist

      public boolean checkAccountExist(String accountNumber)
      Checks whether an account with the given number exists in the AccountDetails table.
      Parameters:
      accountNumber - the account number to search for
      Returns:
      true if found, false otherwise
      Throws:
      RuntimeException - if a database error occurs
    • getPasswd

      public String getPasswd(String accountNumber)
      Retrieves the stored PIN for the given account number.
      Parameters:
      accountNumber - the account number to query
      Returns:
      the PIN string, or an empty string if not found
      Throws:
      RuntimeException - if a database error occurs
    • getBalance

      public float getBalance(String accountNumber)
      Retrieves the current balance for the given account number.
      Parameters:
      accountNumber - the account number to query
      Returns:
      the balance in GBP (£), or -1 if not found
      Throws:
      RuntimeException - if a database error occurs
    • changeBalance

      public void changeBalance(String accountNumber, float balance)
      Updates the balance for the given account number in the database.
      Parameters:
      accountNumber - the account number to update
      balance - the new balance value in GBP (£)
      Throws:
      RuntimeException - if a database error occurs
    • getName

      public String getName(String accountNumber)
      Retrieves the full name of the customer linked to the given account number, formed by joining the Customer and AccountDetails tables.
      Parameters:
      accountNumber - the account number to look up
      Returns:
      the customer's full name in uppercase, or an empty string if not found
      Throws:
      RuntimeException - if a database error occurs
    • insertTransaction

      public void insertTransaction(String accountNumber, String type, Float amount)
      Inserts a new transaction record into the TransactionHistory table and updates the recentActivity timestamp on the associated account.
      Parameters:
      accountNumber - the account number the transaction belongs to
      type - the type of transaction (e.g. "Deposit", "Withdrawal")
      amount - the transaction amount in GBP (£)
      Throws:
      RuntimeException - if a database error occurs
    • updateRecentActivity

      public void updateRecentActivity(String accountNumber, String dateTime)
      Updates the recentActivity timestamp for the given account number. Called automatically after every transaction insertion.
      Parameters:
      accountNumber - the account number to update
      dateTime - the formatted datetime string to store
      Throws:
      RuntimeException - if a database error occurs
    • getTransactionHistory

      public ArrayList<ArrayList<String>> getTransactionHistory(String accountNumber)
      Retrieves the full transaction history for the given account number, ordered by most recent first.
      Parameters:
      accountNumber - the account number to query
      Returns:
      a list of transaction records, each containing transactionID, timeOfTransaction, typeOfTransaction, and amount as strings
      Throws:
      RuntimeException - if a database error occurs
    • getAccountDetails

      public ArrayList<String> getAccountDetails(String accountNumber)
      Retrieves all account and personal details for the given account number by joining the Customer, AccountDetails, and TransactionHistory tables. Returns only the most recent transaction record via LIMIT 1.
      Parameters:
      accountNumber - the account number to query
      Returns:
      a list of strings in fixed positional order: account number, customerID, name, DOB, phone, email, address, postcode, monthlyIncome, sortcode, accountType, accountTier, balance, recentActivity, lastTransactionType, withdrawalLimit
      Throws:
      RuntimeException - if a database error occurs
    • updatePin

      public void updatePin(String accountNumber, String pin)
      Updates the PIN for the given account number in the database.
      Parameters:
      accountNumber - the account number to update
      pin - the new PIN string
      Throws:
      RuntimeException - if a database error occurs
    • updatePlan

      public void updatePlan(String accountNumber, String type, String tier, float withdrawalLimit)
      Updates the account type, tier, and withdrawal limit for the given account number.
      Parameters:
      accountNumber - the account number to update
      type - the new account type — "Basic" or "Student"
      tier - the new account tier — "Normal", "Pro", or "Prime"
      withdrawalLimit - the new withdrawal limit in GBP (£)
      Throws:
      RuntimeException - if a database error occurs
    • getWithdrawalLimit

      public float getWithdrawalLimit(String accountNumber)
      Retrieves the current one-time withdrawal limit for the given account number.
      Parameters:
      accountNumber - the account number to query
      Returns:
      the withdrawal limit in GBP (£), or 0 if not found
      Throws:
      RuntimeException - if a database error occurs
    • updateWithdrawalLimit

      public void updateWithdrawalLimit(String accountNumber, float withdrawalLimit)
      Updates the one-time withdrawal limit for the given account number in the database.
      Parameters:
      accountNumber - the account number to update
      withdrawalLimit - the new withdrawal limit in GBP (£)
      Throws:
      RuntimeException - if a database error occurs