From e91140e69c19ae7af44f9392720123bec4233d75 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 11 Apr 2016 16:59:17 +0200 Subject: [PATCH] Continued a bit: - implemented business method addCountry() - updated jar(s) --- lib/jcountry-core.jar | Bin 7870 -> 9970 bytes lib/jcountry-lib.jar | Bin 1446 -> 1542 bytes .../data/AddressbookCountrySingletonBean.java | 82 ++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/lib/jcountry-core.jar b/lib/jcountry-core.jar index 38df2036331e7e4b7a90686ddb8d425f98de1623..3b26377fa896aaca3df2df69ef7b74c4533e677a 100644 GIT binary patch delta 1727 zcma)6U2GIp6#nkaZfAEo+n+7$58Z9IMVH-e*)1)!_GhIFX#`tJlOjodfJ}EM%fhfr z+HIpTT21tcm`KLQeK64w9|e?(#5N%zCL{#oi!spf;>h9ScGLze5?1C6JSktB04IN+r78JcJoAlU=Gc%tj6EbX zjA}@xyA2^_WXO0?LezylGLgrc5l6y>J{kSkD*29s&5adNy`wMr9%7>l1Y z!kq!*v=Z%Usd+F{D&`s7I*F62zM`4PSB;Hbr`OO!B_UIJwo?7u`;EqL9I zZy_&;1YRTb{MTq+hq9UI`wE^bL@bgcKooA8`|189NgF^1RdI;!aTNRM9mXuiFpqI` z63S;eMBl@-BG*jE>Hm}74)G}&3lh2|L;&v|ilYa;W;E20Qlv1#ITK&P^93n951{MH zHxHWhiUp|BGwe1|FW9g0wfp{uqL8i__c}*;!;?dkT+D<9xOgXIZr%tT;;X+yuWZu{ zUkk?ut#X)~X2K59YORe;vxknho;Ezl++xNf|L*=qgU|oC=e{ihe8isPNq+Vo6UZPy zO-?a>412jVzlB4B()7>n-Y#E+pIO&y>nK_R1P;#HDtAj&T5YP)tGZrSM|mpPNV&B& on9aPAa(!`1`H+I-<8U42!!Dwn^36>aFkoU}FkqTIpV3QNgq=Zvok5VDL5PuoD={U-IlnZoq^OdS!AoOuJ(CKf zCWsUO%DGk~rxuiC=I0f&GYC(%Vwz(l83a_CnVTAxS)7@alj@k4mtT?yR>8<1;?fuEg0fRTYKF(t)0zcjC;sFIOEUBhQ`4x{vB z1tw0xFrb`kMRICENoIatF*}3c allCountries () { @@ -46,4 +80,52 @@ public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements return query.getResultList(); } + /** + * Checks whether given country is already added by i18n key or country + * code, what comes first. + *

+ * @param country Country instance to check + *

+ * @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; + } + } -- 2.39.5