java.lang.Object
com.atmbanksimulator.SQLite
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
ConstructorsConstructorDescriptionSQLite()Establishes a connection to the SQLite database at the configured URL. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeBalance(String accountNumber, float balance) Updates the balance for the given account number in the database.booleancheckAccountExist(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.floatgetBalance(String accountNumber) Retrieves the current balance for the given account number.Retrieves the full name of the customer linked to the given account number, formed by joining the Customer and AccountDetails tables.Retrieves the stored PIN for the given account number.getTransactionHistory(String accountNumber) Retrieves the full transaction history for the given account number, ordered by most recent first.floatgetWithdrawalLimit(String accountNumber) Retrieves the current one-time withdrawal limit for the given account number.voidinsertTransaction(String accountNumber, String type, Float amount) Inserts a new transaction record into the TransactionHistory table and updates the recentActivity timestamp on the associated account.voidUpdates the PIN for the given account number in the database.voidupdatePlan(String accountNumber, String type, String tier, float withdrawalLimit) Updates the account type, tier, and withdrawal limit for the given account number.voidupdateRecentActivity(String accountNumber, String dateTime) Updates the recentActivity timestamp for the given account number.voidupdateWithdrawalLimit(String accountNumber, float withdrawalLimit) Updates the one-time withdrawal limit for the given account number in the database.
-
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
Checks whether an account with the given number exists in the AccountDetails table.- Parameters:
accountNumber- the account number to search for- Returns:
trueif found,falseotherwise- Throws:
RuntimeException- if a database error occurs
-
getPasswd
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
Retrieves the current balance for the given account number.- Parameters:
accountNumber- the account number to query- Returns:
- the balance in GBP (£), or
-1if not found - Throws:
RuntimeException- if a database error occurs
-
changeBalance
Updates the balance for the given account number in the database.- Parameters:
accountNumber- the account number to updatebalance- the new balance value in GBP (£)- Throws:
RuntimeException- if a database error occurs
-
getName
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
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 totype- the type of transaction (e.g. "Deposit", "Withdrawal")amount- the transaction amount in GBP (£)- Throws:
RuntimeException- if a database error occurs
-
updateRecentActivity
Updates the recentActivity timestamp for the given account number. Called automatically after every transaction insertion.- Parameters:
accountNumber- the account number to updatedateTime- the formatted datetime string to store- Throws:
RuntimeException- if a database error occurs
-
getTransactionHistory
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
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
Updates the PIN for the given account number in the database.- Parameters:
accountNumber- the account number to updatepin- the new PIN string- Throws:
RuntimeException- if a database error occurs
-
updatePlan
Updates the account type, tier, and withdrawal limit for the given account number.- Parameters:
accountNumber- the account number to updatetype- 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
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
0if not found - Throws:
RuntimeException- if a database error occurs
-
updateWithdrawalLimit
Updates the one-time withdrawal limit for the given account number in the database.- Parameters:
accountNumber- the account number to updatewithdrawalLimit- the new withdrawal limit in GBP (£)- Throws:
RuntimeException- if a database error occurs
-