Beispiel #1
0
  /*
   * @see jgnash.engine.TransactionDAO#addTransaction(jgnash.engine.Transaction)
   */
  @Override
  public synchronized boolean addTransaction(final Transaction transaction) {
    boolean result = false;

    emLock.lock();

    try {
      Future<Boolean> future =
          executorService.submit(
              () -> {
                em.getTransaction().begin();
                em.persist(transaction);

                transaction.getAccounts().forEach(em::persist);
                em.getTransaction().commit();

                return true;
              });

      result = future.get();
    } catch (final InterruptedException | ExecutionException e) {
      logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      emLock.unlock();
    }

    return result;
  }
  @FXML
  @Override
  public void handleEnterAction() {
    if (validateForm()) {
      if (modTrans == null) { // new transaction
        Transaction newTrans = buildTransaction();

        ReconcileManager.reconcileTransaction(
            accountProperty.get(), newTrans, getReconciledState());

        newTrans = attachmentPane.buildTransaction(newTrans); // chain the transaction build

        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

        if (engine != null) {
          engine.addTransaction(newTrans);
        }
      } else {
        Transaction newTrans = buildTransaction();

        newTrans.setDateEntered(modTrans.getDateEntered());

        // restore the reconciled state of the previous old transaction
        for (final Account a : modTrans.getAccounts()) {
          if (!a.equals(accountProperty.get())) {
            ReconcileManager.reconcileTransaction(a, newTrans, modTrans.getReconciled(a));
          }
        }

        /*
         * Reconcile the modified transaction for this account.
         * This must be performed last to ensure consistent results per the ReconcileManager rules
         */
        ReconcileManager.reconcileTransaction(
            accountProperty.get(), newTrans, getReconciledState());

        newTrans = attachmentPane.buildTransaction(newTrans); // chain the transaction build

        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);

        if (engine != null && engine.removeTransaction(modTrans)) {
          engine.addTransaction(newTrans);
        }
      }
      clearForm();

      if (payeeTextField != null) {
        payeeTextField.requestFocus();
      } else {
        memoTextField.requestFocus();
      }
    }
  }