]> git.mxchange.org Git - jjobs-ejb.git/blobdiff - src/java/org/mxchange/jcountry/model/data/JobsAdminCountrySingletonBean.java
Please cherry-pick:
[jjobs-ejb.git] / src / java / org / mxchange / jcountry / model / data / JobsAdminCountrySingletonBean.java
index b4ee6da1a8f172c76f229437c9fd35873e5f6c09..5265d00160650d8c2e374607b602e66919ee00b9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 - 2018 Free Software Foundation
+ * Copyright (C) 2016 - 2020 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
  *
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+ */
 package org.mxchange.jcountry.model.data;
 
 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.jcountry.exceptions.CountryAlreadyAddedException;
-import org.mxchange.jjobs.beans.ejb.BaseJobsEnterpriseBean;
+import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
 
 /**
  * A stateless EJB for administrative country purposes
@@ -37,6 +37,12 @@ public class JobsAdminCountrySingletonBean extends BaseJobsEnterpriseBean implem
         */
        private static final long serialVersionUID = 15_846_983_298_691_208L;
 
+       /**
+        * Remote country EJB
+        */
+       @EJB (lookup = "java:global/jfinancials-ejb/country!org.mxchange.jcountry.model.data.CountrySingletonBeanRemote")
+       private CountrySingletonBeanRemote countryBean;
+
        /**
         * Default constructor
         */
@@ -107,22 +113,14 @@ public class JobsAdminCountrySingletonBean extends BaseJobsEnterpriseBean implem
                // Default is not found
                boolean isAdded = false;
 
-               // Get query instance
-               final Query query = this.getEntityManager().createNamedQuery("SearchCountryByCodeI18nKey", CountryData.class); //NOI18N
-
-               // Assign all parameters
-               query.setParameter("code", country.getCountryCode()); //NOI18N
-               query.setParameter("key", country.getCountryI18nKey()); //NOI18N
-
-               // Try to get a single result
-               try {
-                       // Get single result
-                       final Country foundCountry = (Country) query.getSingleResult();
-
-                       // Found it?
-                       isAdded = (foundCountry instanceof Country);
-               } catch (final NoResultException ex) {
-                       // Not found, don't log this
+               // Try to match code/i18n key (should be both unique!)
+               for (final Country currentCountry : this.countryBean.allCountries()) {
+                       // Is it matching
+                       if (Objects.equals(country, currentCountry)) {
+                               // Yes, then set flag and abort loop
+                               isAdded = true;
+                               break;
+                       }
                }
 
                // Return result