From 1c155f27856b7418f1f5a3f6734e4e7c7d7cc0a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 26 Apr 2020 21:33:56 +0200 Subject: [PATCH] Don't cherry-pick: - updated method names - fetching user's or receipt's receipt items can now be done without any extra JPQL, simply by invoking fetchAllReceiptItems() and iterating over all and taking matching elements into list MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../income/FinancialIncomeSessionBean.java | 2 +- .../receipt/FinancialReceiptSessionBean.java | 18 +++++---- .../FinancialReceiptItemSessionBean.java | 38 +++++++++++-------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java b/src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java index cfac2bc..dcc6d42 100644 --- a/src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java @@ -76,7 +76,7 @@ public class FinancialIncomeSessionBean extends BaseFinancialsEnterpriseBean imp } // Add created instance - income.setIncomeCreated(new Date()); + income.setIncomeEntryCreated(new Date()); // Persist it this.getEntityManager().persist(income); diff --git a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java index 25e9046..86dc5d0 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java @@ -18,6 +18,7 @@ package org.mxchange.jfinancials.model.receipt; import java.text.MessageFormat; import java.util.Date; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import javax.ejb.Stateless; @@ -127,14 +128,17 @@ public class FinancialReceiptSessionBean extends BaseFinancialsEnterpriseBean im throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N } - // Query all - final Query query = this.getEntityManager().createNamedQuery("SearchAllUserReceipts"); //NOI18N - - // Add parameter - query.setParameter("receiptUser", user); //NOI18N + // Init list + final List receipts = new LinkedList<>(); - // Get all - final List receipts = query.getResultList(); + // Iterate over all records + for (final BillableReceipt currentReceipt : this.fetchAllReceipts()) { + // Does the user match? + if (Objects.equals(user, currentReceipt.getReceiptUser())) { + // Yes, then add to list + receipts.add(currentReceipt); + } + } // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): receipts.size()={1} EXIT!", this.getClass().getSimpleName(), receipts.size())); //NOI18N diff --git a/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java b/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java index b566b84..ddb3dfa 100644 --- a/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java +++ b/src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java @@ -18,7 +18,9 @@ package org.mxchange.jfinancials.model.receipt_item; import java.text.MessageFormat; import java.util.Date; +import java.util.LinkedList; import java.util.List; +import java.util.Objects; import javax.ejb.Stateless; import javax.persistence.Query; import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean; @@ -110,19 +112,21 @@ public class FinancialReceiptItemSessionBean extends BaseFinancialsEnterpriseBea } @Override - @SuppressWarnings ("unchecked") public List fetchReceiptItemsByReceipt (final BillableReceipt receipt) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceiptItems(): receipt={1} - CALLED!", this.getClass().getSimpleName(), receipt)); //NOI18N - // Get named query - final Query query = this.getEntityManager().createNamedQuery("SearchAssignedReceiptItems"); //NOI18N - - // Set parameter - query.setParameter("itemReceipt", receipt); //NOI18N + // Init list + final List receiptItems = new LinkedList<>(); - // Get list - final List receiptItems = query.getResultList(); + // Iterate over all records + for (final BillableReceiptItem currentReceiptItem : this.fetchAllReceiptItems()) { + // Does the receipt match? + if (Objects.equals(receipt, currentReceiptItem.getItemReceipt())) { + // Yes, then add to list + receiptItems.add(currentReceiptItem); + } + } // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceiptItems(): receiptItems()={1} EXIT!", this.getClass().getSimpleName(), receiptItems.size())); //NOI18N @@ -132,19 +136,21 @@ public class FinancialReceiptItemSessionBean extends BaseFinancialsEnterpriseBea } @Override - @SuppressWarnings ("unchecked") public List fetchReceiptItemsByUserUser (final User user) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceiptItems(): user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - // Get named query - final Query query = this.getEntityManager().createNamedQuery("SearchAllUserReceiptItems"); //NOI18N - - // Set parameter - query.setParameter("receiptUser", user); //NOI18N + // Init list + final List receiptItems = new LinkedList<>(); - // Get list - final List receiptItems = query.getResultList(); + // Iterate over all records + for (final BillableReceiptItem currentReceiptItem : this.fetchAllReceiptItems()) { + // Does the user match? + if (Objects.equals(user, currentReceiptItem.getItemReceipt().getReceiptUser())) { + // Yes, then add to list + receiptItems.add(currentReceiptItem); + } + } // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceiptItems(): receiptItems()={1} EXIT!", this.getClass().getSimpleName(), receiptItems.size())); //NOI18N -- 2.39.5