Package com.apress.prospring.ch12.domain

Examples of com.apress.prospring.ch12.domain.History


  private ApplicationContext context;
 
  private void run() {
    System.out.println("Initializing application");
    context = new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml", "applicationContext-local.xml" });
    AccountManager manager = (AccountManager)context.getBean("accountManager");
   
    int count = manager.count();
    int failures = 0;
    int attempts = 100;
   
    for (int i = 0; i < attempts; i++) {
      Account a = new Account();
      a.setBalance(new BigDecimal(10));
      a.setNumber("123 " + i);
      a.setSortCode("xxx " + i);
      try {
        manager.insert(a);
      } catch (RuntimeException ex) {
        System.out.println("Failed to insert account " + ex.getMessage());
        failures++;
      }
    }
   
    System.out.println("Attempts  : " + attempts);
    System.out.println("Failures  : " + failures);
    System.out.println("Prev count: " + count);
    System.out.println("New count : " + manager.count());
   
    System.out.println("Done");
  }
View Full Code Here


    int count = manager.count();
    int failures = 0;
    int attempts = 100;
   
    for (int i = 0; i < attempts; i++) {
      Account a = new Account();
      a.setBalance(new BigDecimal(10));
      a.setNumber("123 " + i);
      a.setSortCode("xxx " + i);
      try {
        manager.insert(a);
      } catch (RuntimeException ex) {
        System.out.println("Failed to insert account " + ex.getMessage());
        failures++;
View Full Code Here

    int count = accountManager.count();
    int failures = 0;
    int attempts = 100;
    for (int i = 0; i < attempts; i++) {
      Account account = new Account();
      account.setBalance(new BigDecimal(0));
      account.setNumber("" + System.currentTimeMillis());
      account.setSortCode("dfgdfg");
      try {
        accountManager.insert(account);
      } catch (Exception ex) {
        failures++;
      }
View Full Code Here

    getAccountDao().updateBalance(accountId, amount);
    getHistoryDao().insert(history);
  }

  protected void doTransfer(int sourceAccount, int targetAccount, BigDecimal amount) {
    Account source = getAccountDao().getById(sourceAccount);
    Account target = getAccountDao().getById(targetAccount);

    if (source.getBalance().compareTo(amount) > 0) {
      // transfer allowed
      getAccountDao().updateBalance(sourceAccount, amount.negate());
      getAccountDao().updateBalance(targetAccount, amount);
View Full Code Here

  private AccountDao accountDao;
  private HistoryDao historyDao;

  protected void doInsert(Account account) {
    getAccountDao().insert(account);
    History history = new History();
    history.setAccount(account.getAccountId());
    history.setAmount(account.getBalance());
    history.setOperation("Initial deposit");
    history.setTargetAccount(null);
    history.setTransactionDate(new Date());
    getHistoryDao().insert(history);
  }
View Full Code Here

    history.setTransactionDate(new Date());
    getHistoryDao().insert(history);
  }

  protected void doDeposit(int accountId, BigDecimal amount) {
    History history = new History();
    history.setAccount(accountId);
    history.setAmount(amount);
    history.setOperation("Deposit");
    history.setTargetAccount(null);
    history.setTransactionDate(new Date());

    getAccountDao().updateBalance(accountId, amount);
    getHistoryDao().insert(history);
  }
View Full Code Here

    if (source.getBalance().compareTo(amount) > 0) {
      // transfer allowed
      getAccountDao().updateBalance(sourceAccount, amount.negate());
      getAccountDao().updateBalance(targetAccount, amount);

      History history = new History();
      history.setAccount(sourceAccount);
      history.setAmount(amount);
      history.setOperation("Paid out");
      history.setTargetAccount(target);
      history.setTransactionDate(new Date());
      getHistoryDao().insert(history);

      history = new History();
      history.setAccount(targetAccount);
      history.setAmount(amount);
      history.setOperation("Paid in");
      history.setTargetAccount(source);
      history.setTransactionDate(new Date());
      getHistoryDao().insert(history);
    } else {
      throw new RuntimeException("Not enough money");
    }
  }
View Full Code Here

TOP

Related Classes of com.apress.prospring.ch12.domain.History

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.