]> git.mxchange.org Git - addressbook-mailer-ejb.git/blobdiff - src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java
updated jar(s)
[addressbook-mailer-ejb.git] / src / java / org / mxchange / jcountry / data / AddressbookCountrySingletonBean.java
index 961502552d0a1434c11b416901663d00edb848f7..8d1f5a47b409a28875b65d9aa92987d7ed9bc723 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -23,25 +23,36 @@ import javax.ejb.Singleton;
 import javax.ejb.Startup;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException;
 
 /**
  * A singleton EJB for country informations
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
  */
 @Startup
-@Singleton (name = "country", mappedName = "ejb/addressbook-singleton-country", description = "A singleton session bean for country informations")
-public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements CountrySingletonBeanRemote {
+@Singleton (name = "country", description = "A singleton session-scoped bean for country informations")
+public class AddressbookCountrySingletonBean extends BaseAddressbookDatabaseBean implements CountrySingletonBeanRemote {
 
        /**
         * Serial number
         */
        private static final long serialVersionUID = 15_846_983_298_691_207L;
 
+       /**
+        * Default constructor
+        */
+       public AddressbookCountrySingletonBean () {
+               // Call super constructor
+               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
@@ -49,7 +60,7 @@ public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements
                } else if (country.getCountryCode().isEmpty()) {
                        // Code is not set
                        throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N
-               } else if (country.getCountryI18nkey().isEmpty()) {
+               } else if (country.getCountryI18nKey().isEmpty()) {
                        // I18n key is not set
                        throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N
                } else if (country.getCountryId() != null) {
@@ -69,6 +80,9 @@ public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements
                // Flush it to get id number back, maybe it is directly needed?
                this.getEntityManager().flush();
 
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - EXIT!", this.getClass().getSimpleName(), country)); //NOI18N
+
                // Return updated instance
                return country;
        }
@@ -76,11 +90,20 @@ public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements
        @Override
        @SuppressWarnings ("unchecked")
        public List<Country> allCountries () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
                // Init query
-               Query query = this.getEntityManager().createNamedQuery("AllCountries", List.class); //NOI18N
+               Query query = this.getEntityManager().createNamedQuery("AllCountries", CountryData.class); //NOI18N
+
+               // Get list
+               List<Country> countries = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: countries.size()={1} - EXIT!", this.getClass().getSimpleName(), countries.size())); //NOI18N
 
                // Return it
-               return query.getResultList();
+               return countries;
        }
 
        /**
@@ -98,7 +121,7 @@ public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements
                } else if (country.getCountryCode().isEmpty()) {
                        // Code is not set
                        throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N
-               } else if (country.getCountryI18nkey().isEmpty()) {
+               } else if (country.getCountryI18nKey().isEmpty()) {
                        // I18n key is not set
                        throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N
                } else if (country.getCountryId() != null) {
@@ -114,7 +137,7 @@ public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements
 
                // Assign all parameters
                query.setParameter("code", country.getCountryCode()); //NOI18N
-               query.setParameter("key", country.getCountryI18nkey()); //NOI18N
+               query.setParameter("key", country.getCountryI18nKey()); //NOI18N
 
                // Try to get a single result
                try {