]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 19:33:56 +0000 (21:33 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 19:33:56 +0000 (21:33 +0200)
- 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

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/model/income/FinancialIncomeSessionBean.java
src/java/org/mxchange/jfinancials/model/receipt/FinancialReceiptSessionBean.java
src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java

index cfac2bc213bebe5b2c56e20562fb2543846bba51..dcc6d4281de607bd3df57d36c65bb89dad5c9b45 100644 (file)
@@ -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);
index 25e9046a4096f309015fb07a7f5d8262f647c1f1..86dc5d000f156cf48f41b6352c50d2cefba3a427 100644 (file)
@@ -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<BillableReceipt> receipts = new LinkedList<>();
 
-               // Get all
-               final List<BillableReceipt> 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
index b566b841675b34768d1947879426bb754312ee89..ddb3dfa4d48112a60f7beeadb744fa9401634a81 100644 (file)
@@ -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<BillableReceiptItem> 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<BillableReceiptItem> receiptItems = new LinkedList<>();
 
-               // Get list
-               final List<BillableReceiptItem> 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<BillableReceiptItem> 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<BillableReceiptItem> receiptItems = new LinkedList<>();
 
-               // Get list
-               final List<BillableReceiptItem> 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