Package storage
Class CollectionStorage
java.lang.Object
storage.AbstractDataStorage
storage.CollectionStorage
- All Implemented Interfaces:
DataStorage
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<Integer, SavingsAccount> private int
private int
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
addCustomerToAccount
(int customerId, int accountNo, String role) Adds a customer to an existing account as joint holder.boolean
deleteAccount
(int accountNo) Deletes an account by account number.boolean
deleteCustomer
(int customerId) Deletes a customer by ID.boolean
depositToAccount
(int accountNo, BigDecimal amount) Deposits money to an account.getAccount
(int accountNo) Retrieves an account by account number.getAccountsByBranch
(int branchId) Gets all accounts for a specific branch.getAccountsByCustomer
(int customerId) getBranch
(int branchId) Retrieves a branch by ID.getCustomer
(int customerId) Retrieves a customer by ID.getCustomerByEmail
(String email) Retrieves a customer by email address.getCustomersByAccount
(int accountNo) Gets all customers who are holders of an account.getCustomersByBranch
(int branchId) Gets all customers for a specific branch.getEmployee
(int employeeId) Retrieves an employee by ID.getEmployeeByEmail
(String email) Retrieves an employee by email address.getManager
(int employeeId) getSaltForCustomer
(int customerId) Gets the password salt for a customer.getSaltForEmployee
(int employeeId) boolean
removeCustomerFromAccount
(int customerId, int accountNo) Removes a customer from a joint account.int
saveAccount
(SavingsAccount account) Saves a new account to storage.void
saveBranch
(Branch branch) Saves a branch to storage.int
saveCustomer
(Customer customer) Saves a new customer to storage.int
saveCustomerWithPassword
(Customer customer, String salt) Saves a new customer with password for login capability.int
saveEmployee
(Employee employee) Saves a new employee to storage.int
saveEmployeeWithPassword
(Employee employee, String salt) Saves a new employee with password for login capability.void
updateAccount
(SavingsAccount account) Updates an existing account.void
updateCustomer
(Customer customer) Updates an existing customer's information.boolean
withdrawFromAccount
(int accountNo, BigDecimal amount) Withdraws money from an account.Methods inherited from class storage.AbstractDataStorage
isValidEmail
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface storage.DataStorage
getTransactionHistory, getTransactionHistory, getTransactionHistoryByDateRange, logTransaction
-
Field Details
-
customers
-
employees
-
accounts
-
branches
-
customerSalts
-
employeeSalts
-
nextCustomerId
private int nextCustomerId -
nextEmployeeId
private int nextEmployeeId -
nextAccountId
private int nextAccountId
-
-
Constructor Details
-
CollectionStorage
public CollectionStorage()
-
-
Method Details
-
saveCustomer
Saves a new customer to storage.- Specified by:
saveCustomer
in interfaceDataStorage
- Specified by:
saveCustomer
in classAbstractDataStorage
- Parameters:
customer
- the customer to save- Returns:
- the generated customer ID
-
saveCustomerWithPassword
Saves a new customer with password for login capability.- Specified by:
saveCustomerWithPassword
in interfaceDataStorage
- Specified by:
saveCustomerWithPassword
in classAbstractDataStorage
- Parameters:
customer
- the customer to savesalt
- the password salt for security- Returns:
- the generated customer ID
-
getCustomer
Retrieves a customer by ID.- Specified by:
getCustomer
in interfaceDataStorage
- Specified by:
getCustomer
in classAbstractDataStorage
- Parameters:
customerId
- the customer ID- Returns:
- the customer or null if not found
-
getCustomerByEmail
Retrieves a customer by email address.- Specified by:
getCustomerByEmail
in interfaceDataStorage
- Specified by:
getCustomerByEmail
in classAbstractDataStorage
- Parameters:
email
- the customer's email- Returns:
- the customer or null if not found
-
deleteCustomer
public boolean deleteCustomer(int customerId) Deletes a customer by ID.- Specified by:
deleteCustomer
in interfaceDataStorage
- Specified by:
deleteCustomer
in classAbstractDataStorage
- Parameters:
customerId
- the customer ID to delete- Returns:
- true if deletion was successful, false otherwise
-
getCustomersByBranch
Gets all customers for a specific branch.- Specified by:
getCustomersByBranch
in interfaceDataStorage
- Specified by:
getCustomersByBranch
in classAbstractDataStorage
- Parameters:
branchId
- the branch ID- Returns:
- list of customers in the branch
-
getSaltForCustomer
Gets the password salt for a customer.- Specified by:
getSaltForCustomer
in interfaceDataStorage
- Specified by:
getSaltForCustomer
in classAbstractDataStorage
- Parameters:
customerId
- the customer ID- Returns:
- the password salt or null if not found
-
saveEmployee
Saves a new employee to storage.- Specified by:
saveEmployee
in interfaceDataStorage
- Specified by:
saveEmployee
in classAbstractDataStorage
- Parameters:
employee
- the employee to save- Returns:
- the generated employee ID
-
saveEmployeeWithPassword
Saves a new employee with password for login capability.- Specified by:
saveEmployeeWithPassword
in interfaceDataStorage
- Specified by:
saveEmployeeWithPassword
in classAbstractDataStorage
- Parameters:
employee
- the employee to savesalt
- the password salt for security- Returns:
- the generated employee ID
-
getEmployee
Retrieves an employee by ID.- Specified by:
getEmployee
in interfaceDataStorage
- Specified by:
getEmployee
in classAbstractDataStorage
- Parameters:
employeeId
- the employee ID- Returns:
- the employee or null if not found
-
getEmployeeByEmail
Retrieves an employee by email address.- Specified by:
getEmployeeByEmail
in interfaceDataStorage
- Specified by:
getEmployeeByEmail
in classAbstractDataStorage
- Parameters:
email
- the employee's email- Returns:
- the employee or null if not found
-
getManager
- Specified by:
getManager
in interfaceDataStorage
- Specified by:
getManager
in classAbstractDataStorage
-
getSaltForEmployee
- Specified by:
getSaltForEmployee
in interfaceDataStorage
- Specified by:
getSaltForEmployee
in classAbstractDataStorage
-
saveAccount
Saves a new account to storage.- Specified by:
saveAccount
in interfaceDataStorage
- Specified by:
saveAccount
in classAbstractDataStorage
- Parameters:
account
- the account to save- Returns:
- the generated account number
-
getAccount
Retrieves an account by account number.- Specified by:
getAccount
in interfaceDataStorage
- Specified by:
getAccount
in classAbstractDataStorage
- Parameters:
accountNo
- the account number- Returns:
- the account or null if not found
-
updateAccount
Updates an existing account.- Specified by:
updateAccount
in interfaceDataStorage
- Specified by:
updateAccount
in classAbstractDataStorage
- Parameters:
account
- the account to update
-
deleteAccount
public boolean deleteAccount(int accountNo) Deletes an account by account number.- Specified by:
deleteAccount
in interfaceDataStorage
- Specified by:
deleteAccount
in classAbstractDataStorage
- Parameters:
accountNo
- the account number to delete- Returns:
- true if deletion was successful, false otherwise
-
getAccountsByBranch
Gets all accounts for a specific branch.- Specified by:
getAccountsByBranch
in interfaceDataStorage
- Specified by:
getAccountsByBranch
in classAbstractDataStorage
- Parameters:
branchId
- the branch ID- Returns:
- list of accounts in the branch
-
getAccountsByCustomer
- Specified by:
getAccountsByCustomer
in interfaceDataStorage
- Specified by:
getAccountsByCustomer
in classAbstractDataStorage
-
saveBranch
Saves a branch to storage.- Specified by:
saveBranch
in interfaceDataStorage
- Specified by:
saveBranch
in classAbstractDataStorage
- Parameters:
branch
- the branch to save
-
getBranch
Retrieves a branch by ID.- Specified by:
getBranch
in interfaceDataStorage
- Specified by:
getBranch
in classAbstractDataStorage
- Parameters:
branchId
- the branch ID- Returns:
- the branch or null if not found
-
withdrawFromAccount
Withdraws money from an account.- Specified by:
withdrawFromAccount
in interfaceDataStorage
- Specified by:
withdrawFromAccount
in classAbstractDataStorage
- Parameters:
accountNo
- the account numberamount
- the amount to withdraw- Returns:
- true if withdrawal was successful, false otherwise
-
depositToAccount
Deposits money to an account.- Specified by:
depositToAccount
in interfaceDataStorage
- Specified by:
depositToAccount
in classAbstractDataStorage
- Parameters:
accountNo
- the account numberamount
- the amount to deposit- Returns:
- true if deposit was successful, false otherwise
-
updateCustomer
Updates an existing customer's information.- Specified by:
updateCustomer
in interfaceDataStorage
- Specified by:
updateCustomer
in classAbstractDataStorage
- Parameters:
customer
- the customer to update- Throws:
SQLException
- if database operation fails
-
addCustomerToAccount
Adds a customer to an existing account as joint holder. Default implementation throws UnsupportedOperationException.- Parameters:
customerId
- the customer ID to addaccountNo
- the account numberrole
- the customer's role (PRIMARY, JOINT)- Returns:
- the result status
- Throws:
UnsupportedOperationException
- if not supported by implementation
-
removeCustomerFromAccount
public boolean removeCustomerFromAccount(int customerId, int accountNo) Removes a customer from a joint account. Default implementation throws UnsupportedOperationException.- Parameters:
customerId
- the customer ID to removeaccountNo
- the account number- Returns:
- true if removal was successful, false otherwise
- Throws:
UnsupportedOperationException
- if not supported by implementation
-
getCustomersByAccount
Gets all customers who are holders of an account. Default implementation throws UnsupportedOperationException.- Parameters:
accountNo
- the account number- Returns:
- list of account holders
- Throws:
UnsupportedOperationException
- if not supported by implementation
-