]> git.mxchange.org Git - jfinancials-ejb.git/blobdiff - src/java/org/mxchange/jcountry/model/data/FinancialsCountrySingletonBean.java
Please cherry-pick:
[jfinancials-ejb.git] / src / java / org / mxchange / jcountry / model / data / FinancialsCountrySingletonBean.java
index bcdfe50c6025608920cac6395a5b325295d2ffd1..db6025dc1915f968d37098b0e49e161295ee48a8 100644 (file)
 */
 package org.mxchange.jcountry.model.data;
 
-import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
-import org.mxchange.jcountry.model.data.CountryData;
-import org.mxchange.jcountry.model.data.Country;
 import java.text.MessageFormat;
-import java.util.GregorianCalendar;
 import java.util.List;
 import javax.ejb.Singleton;
 import javax.ejb.Startup;
-import javax.persistence.NoResultException;
 import javax.persistence.Query;
-import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException;
 import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
 
 /**
@@ -51,42 +45,6 @@ public class FinancialsCountrySingletonBean extends BaseFinancialsDatabaseBean i
                super();
        }
 
-       @Override
-       public Country addCountry (final Country country) throws CountryAlreadyAddedException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
-
-               // Is it already there?
-               if (null == country) {
-                       // Throw NPE
-                       throw new NullPointerException("country is null"); //NOI18N
-               } else if (country.getCountryCode().isEmpty()) {
-                       // Code is not set
-                       throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N
-               } else if (country.getCountryI18nKey().isEmpty()) {
-                       // I18n key is not set
-                       throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N
-               } else if (country.getCountryId() != null) {
-                       // Should be null
-                       throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N
-               } else if (this.isCountryAdded(country)) {
-                       // Yes, then abort here
-                       throw new CountryAlreadyAddedException(country);
-               }
-
-               // Add timestamp
-               country.setCountryEntryCreated(new GregorianCalendar());
-
-               // It is not added, so persist it
-               this.getEntityManager().persist(country);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - EXIT!", this.getClass().getSimpleName(), country)); //NOI18N
-
-               // Return updated instance
-               return country;
-       }
-
        @Override
        @SuppressWarnings ("unchecked")
        public List<Country> allCountries () {
@@ -106,52 +64,4 @@ public class FinancialsCountrySingletonBean extends BaseFinancialsDatabaseBean i
                return countries;
        }
 
-       /**
-        * Checks whether given country is already added by i18n key or country
-        * code, what comes first.
-        * <p>
-        * @param country Country instance to check
-        * <p>
-        * @return Whether the country was found
-        */
-       private boolean isCountryAdded (final Country country) {
-               if (null == country) {
-                       // Throw NPE
-                       throw new NullPointerException("country is null"); //NOI18N
-               } else if (country.getCountryCode().isEmpty()) {
-                       // Code is not set
-                       throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N
-               } else if (country.getCountryI18nKey().isEmpty()) {
-                       // I18n key is not set
-                       throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N
-               } else if (country.getCountryId() != null) {
-                       // Should be null
-                       throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N
-               }
-
-               // 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
-               }
-
-               // Return result
-               return isAdded;
-       }
-
 }