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); }); }
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); }); }