Class BankRepository
java.lang.Object
clazzfish.sample.jdbc.BankRepository
This class represents the repository (or DB) of a bank. As default the
dates are stored in a in-memory DB (jdbc:hsqldb:mem:testd). If you want to
use another DB set the system property "JDBC_URL", e.g as
java -DJDBC_URL="jdbc:proxy:hsqldb:file:/tmp/oli" ...
- Since:
- 1.0 (01.07.2019)
- Author:
- oboehm
-
Method Summary
Modifier and TypeMethodDescriptionstatic Account
createAccountFor
(User user) Creates the account for.static void
deleteAccount
(Account account) Delete acount.static Account
getAccount
(int number) Gets the account.static Collection
<Account> Gets a list of all accounts.static Collection
<Account> getAccountsFor
(User user) Gets the accounts for.static void
Save.static void
setUpDB()
This method can be used to set up the DB.static void
transfer
(Account from, int toNumber, BigDecimal amount) Transfer money from one account to another account.static void
transfer
(Account from, Account to, BigDecimal amount) Transfer money from one account to another account.
-
Method Details
-
setUpDB
This method can be used to set up the DB.- Throws:
SQLException
- e.g. if the DB was set up already
-
getAccount
Gets the account.- Parameters:
number
- the number- Returns:
- the account
- Throws:
SQLException
- the sQL exception
-
getAccounts
Gets a list of all accounts.- Returns:
- a list of accounts
- Throws:
SQLException
- in case of DB problems
-
getAccountsFor
Gets the accounts for.- Parameters:
user
- the user- Returns:
- the accounts for
- Throws:
SQLException
- the sQL exception
-
createAccountFor
Creates the account for.- Parameters:
user
- the user- Returns:
- the account
- Throws:
SQLException
- the sQL exception
-
deleteAccount
Delete acount.- Parameters:
account
- the account- Throws:
SQLException
- the SQL exception
-
save
Save.- Parameters:
account
- the account- Throws:
SQLException
- the SQL exception
-
transfer
Transfer money from one account to another account.- Parameters:
from
- the fromtoNumber
- the to numberamount
- the amount- Throws:
SQLException
- the sQL exception
-
transfer
Transfer money from one account to another account.NOTE: Remember, it is only a very simple demo. Normally we should put a transaction bracket around the transfer logic.
- Parameters:
from
- the fromto
- the toamount
- the amount- Throws:
SQLException
- the SQL exception
-