+ 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
+ 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
+ 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;