Example #1
0
  private void transfer(final Date date, final Account account1, final Account account2) {
    persistence.runInTransaction(
        em -> {
          BigDecimal amount1 = randomExpenseAmount(account1, date, 0.5);
          if (BigDecimal.ZERO.compareTo(amount1) >= 0) return;

          BigDecimal amount2 = transferAmount(account1, account2, amount1);

          Operation operation = metadata.create(Operation.class);
          operation.setOpType(OperationType.TRANSFER);
          operation.setOpDate(date);
          operation.setAcc1(account1);
          operation.setAmount1(amount1);
          operation.setAcc2(account2);
          operation.setAmount2(amount2);
          em.persist(operation);

          log.info(
              "Transfer: "
                  + date
                  + ", "
                  + account1.getName()
                  + ", "
                  + amount1
                  + ", "
                  + account2.getName()
                  + ", "
                  + amount2);
        });
  }
Example #2
0
  private void createCategories(final Context context) {
    persistence.runInTransaction(
        em -> {
          Category category;

          category = metadata.create(Category.class);
          category.setName("Housekeeping");
          category.setCatType(CategoryType.EXPENSE);
          em.persist(category);
          context.expenseCategories.add(category);

          category = metadata.create(Category.class);
          category.setName("Hobby");
          category.setCatType(CategoryType.EXPENSE);
          em.persist(category);
          context.expenseCategories.add(category);

          category = metadata.create(Category.class);
          category.setName("Travel");
          category.setCatType(CategoryType.EXPENSE);
          em.persist(category);
          context.expenseCategories.add(category);

          category = metadata.create(Category.class);
          category.setName("Food");
          category.setCatType(CategoryType.EXPENSE);
          em.persist(category);
          context.expenseCategories.add(category);

          category = metadata.create(Category.class);
          category.setName("Clothes");
          category.setCatType(CategoryType.EXPENSE);
          em.persist(category);
          context.expenseCategories.add(category);

          category = metadata.create(Category.class);
          category.setName("Car");
          category.setCatType(CategoryType.EXPENSE);
          em.persist(category);
          context.expenseCategories.add(category);

          category = metadata.create(Category.class);
          category.setName("Salary");
          category.setCatType(CategoryType.INCOME);
          em.persist(category);
          context.salaryCategory = category;

          category = metadata.create(Category.class);
          category.setName("Other");
          category.setCatType(CategoryType.INCOME);
          em.persist(category);
          context.otherIncomeCategory = category;
        });
  }
Example #3
0
  private void income(
      final Date date, final Account account, final Category category, final BigDecimal amount) {
    persistence.runInTransaction(
        em -> {
          Operation operation = metadata.create(Operation.class);
          operation.setOpType(OperationType.INCOME);
          operation.setOpDate(date);
          operation.setAcc2(account);
          operation.setCategory(category);
          operation.setAmount2(amount);
          em.persist(operation);

          log.info("Income: " + date + ", " + account.getName() + ", " + amount);
        });
  }
Example #4
0
  private void createCurrencies(final Context context) {
    persistence.runInTransaction(
        em -> {
          Currency currency = metadata.create(Currency.class);
          currency.setCode("rub");
          currency.setName("Russian Rubles");
          em.persist(currency);
          context.rubCurrency = currency;

          currency = metadata.create(Currency.class);
          currency.setCode("usd");
          currency.setName("US Dollars");
          em.persist(currency);
          context.usdCurrency = currency;

          currency = metadata.create(Currency.class);
          currency.setCode("eur");
          currency.setName("Euro");
          em.persist(currency);
          context.eurCurrency = currency;
        });
  }
Example #5
0
  private void expense(final Date date, final Account account, final Context context) {
    persistence.runInTransaction(
        em -> {
          int categoryIdx =
              (int) Math.round(Math.random() * (context.expenseCategories.size() - 1));
          Category category = context.expenseCategories.get(categoryIdx);
          if (category == null) return;

          int categoryWeight = context.expenseCategories.size() - categoryIdx;
          BigDecimal amount = randomExpenseAmount(account, date, 0.1 + (categoryWeight * 0.05));
          if (BigDecimal.ZERO.compareTo(amount) >= 0) return;

          Operation operation = metadata.create(Operation.class);
          operation.setOpType(OperationType.EXPENSE);
          operation.setOpDate(date);
          operation.setAcc1(account);
          operation.setCategory(category);
          operation.setAmount1(amount);
          em.persist(operation);

          log.info("Expense: " + date + ", " + account.getName() + ", " + amount);
        });
  }
Example #6
0
  private void createAccounts(final Context context) {
    persistence.runInTransaction(
        em -> {
          Account account;

          account = metadata.create(Account.class);
          account.setName("Credit card");
          account.setCurrency(context.rubCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Cash");
          account.setCurrency(context.rubCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Deposit");
          account.setCurrency(context.rubCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Deposit USD");
          account.setCurrency(context.usdCurrency);
          em.persist(account);
          context.accounts.add(account);

          account = metadata.create(Account.class);
          account.setName("Deposit EUR");
          account.setCurrency(context.eurCurrency);
          em.persist(account);
          context.accounts.add(account);
        });
  }
Example #7
0
 private void cleanupTable(String table) throws SQLException {
   QueryRunner runner = new QueryRunner(persistence.getDataSource());
   runner.update("delete from " + table);
 }