From 254c30bca294848487e38a1b4f44e48b1cf644e5 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Thu, 9 Apr 2020 00:39:04 +0200
Subject: [PATCH] Please cherry-pick: - rewrote to AllContacts + iteration of
 whole list to avoid SearchContact JPQL
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder <roland@mxchange.org>
---
 .../FinancialsAdminContactSessionBean.java    | 34 +++++++++----------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/java/org/mxchange/jcontacts/model/contact/FinancialsAdminContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/FinancialsAdminContactSessionBean.java
index e88e2b3..02d0216 100644
--- a/src/java/org/mxchange/jcontacts/model/contact/FinancialsAdminContactSessionBean.java
+++ b/src/java/org/mxchange/jcontacts/model/contact/FinancialsAdminContactSessionBean.java
@@ -18,9 +18,9 @@ package org.mxchange.jcontacts.model.contact;
 
 import java.text.MessageFormat;
 import java.util.Date;
+import java.util.Objects;
+import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
 import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
@@ -38,6 +38,12 @@ public class FinancialsAdminContactSessionBean extends BaseFinancialsEnterpriseB
 	 */
 	private static final long serialVersionUID = 542_145_347_916L;
 
+	/**
+	 * EJB for general contact purposes
+	 */
+	@EJB (lookup = "java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
+	private ContactSessionBeanRemote contactBean;
+
 	/**
 	 * Default constructor
 	 */
@@ -120,25 +126,19 @@ public class FinancialsAdminContactSessionBean extends BaseFinancialsEnterpriseB
 		// Trace message
 		this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactRegistered: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
 
-		// Create query
-		final Query query = this.getEntityManager().createNamedQuery("SearchContact"); //NOI18N
-
-		// Set parameter
-		query.setParameter("contact", contact); //NOI18N
-		query.setMaxResults(1);
-
 		// Default is not found
 		boolean isFound = false;
 
-		// Try it
-		try {
-			// Try to find instance
-			final Contact dummy = (Contact) query.getSingleResult();
+		// Fest all entries and iterate over them
+		for (final Contact currentContact : this.contactBean.allContacts()) {
+			// Is found?
+			if (Objects.equals(contact, currentContact)) {
+				// Yes, found the same
+				isFound = true;
 
-			// Mark as found
-			isFound = true;
-		} catch (final NoResultException e) {
-			// No result found
+				// Abort loop
+				break;
+			}
 		}
 
 		// Trace message
-- 
2.39.5