Class BankRepository

java.lang.Object
clazzfish.sample.jdbc.BankRepository

public final class BankRepository extends Object
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 Details

    • setUpDB

      public static void setUpDB() throws SQLException
      This method can be used to set up the DB.
      Throws:
      SQLException - e.g. if the DB was set up already
    • getAccount

      public static Account getAccount(int number) throws SQLException
      Gets the account.
      Parameters:
      number - the number
      Returns:
      the account
      Throws:
      SQLException - the sQL exception
    • getAccounts

      public static Collection<Account> getAccounts() throws SQLException
      Gets a list of all accounts.
      Returns:
      a list of accounts
      Throws:
      SQLException - in case of DB problems
    • getAccountsFor

      public static Collection<Account> getAccountsFor(User user) throws SQLException
      Gets the accounts for.
      Parameters:
      user - the user
      Returns:
      the accounts for
      Throws:
      SQLException - the sQL exception
    • createAccountFor

      public static Account createAccountFor(User user) throws SQLException
      Creates the account for.
      Parameters:
      user - the user
      Returns:
      the account
      Throws:
      SQLException - the sQL exception
    • deleteAccount

      public static void deleteAccount(Account account) throws SQLException
      Delete acount.
      Parameters:
      account - the account
      Throws:
      SQLException - the SQL exception
    • save

      public static void save(Account account) throws SQLException
      Save.
      Parameters:
      account - the account
      Throws:
      SQLException - the SQL exception
    • transfer

      public static void transfer(Account from, int toNumber, BigDecimal amount) throws SQLException
      Transfer money from one account to another account.
      Parameters:
      from - the from
      toNumber - the to number
      amount - the amount
      Throws:
      SQLException - the sQL exception
    • transfer

      public static void transfer(Account from, Account to, BigDecimal amount) throws SQLException
      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 from
      to - the to
      amount - the amount
      Throws:
      SQLException - the SQL exception