From: Roland Häder Date: Tue, 16 Aug 2016 14:30:20 +0000 (+0200) Subject: Continued a bit: (please cherry-pick) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=df9d1d6d0c7a50d5cf96442e552060db7cf8d881;p=pizzaservice-ejb.git Continued a bit: (please cherry-pick) - implemented business methods findFaxNumberById() and findLandLineNumberById() - sorted members - fixed log message: cellphone -> mobile again and always use "number" suffix --- diff --git a/src/java/org/mxchange/jphone/phonenumbers/phone/PizzaPhoneSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/phone/PizzaPhoneSessionBean.java index 19bf926..6391115 100644 --- a/src/java/org/mxchange/jphone/phonenumbers/phone/PizzaPhoneSessionBean.java +++ b/src/java/org/mxchange/jphone/phonenumbers/phone/PizzaPhoneSessionBean.java @@ -51,18 +51,18 @@ public class PizzaPhoneSessionBean extends BasePizzaDatabaseBean implements Phon @SuppressWarnings ("unchecked") @Override - public List allMobileNumbers () { + public List allFaxNumbers () { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N // Get query - Query query = this.getEntityManager().createNamedQuery("AllCellphoneNumbers", MobileNumber.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("AllFaxNumbers", FaxNumber.class); //NOI18N // Get list from it - List list = query.getResultList(); + List list = query.getResultList(); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N // Return it return list; @@ -70,18 +70,18 @@ public class PizzaPhoneSessionBean extends BasePizzaDatabaseBean implements Phon @SuppressWarnings ("unchecked") @Override - public List allFaxNumbers () { + public List allLandLineNumbers () { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N // Get query - Query query = this.getEntityManager().createNamedQuery("AllFaxNumbers", FaxNumber.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("AllLandLineNumbers", LandLineNumber.class); //NOI18N // Get list from it - List list = query.getResultList(); + List list = query.getResultList(); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N // Return it return list; @@ -89,27 +89,105 @@ public class PizzaPhoneSessionBean extends BasePizzaDatabaseBean implements Phon @SuppressWarnings ("unchecked") @Override - public List allLandLineNumbers () { + public List allMobileNumbers () { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N // Get query - Query query = this.getEntityManager().createNamedQuery("AllLandLineNumbers", LandLineNumber.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N // Get list from it - List list = query.getResultList(); + List list = query.getResultList(); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N // Return it return list; } + @Override + public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), faxNumberId)); //NOI18N + + // The id number should be valid + if (null == faxNumberId) { + // Throw NPE + throw new NullPointerException("faxNumberId is null"); //NOI18N + } else if (faxNumberId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumberId={0} is not valid.", faxNumberId)); //NOI18N + } + + // Now find it + Query query = this.getEntityManager().createNamedQuery("SearchFaxNumberId", FaxNumber.class); //NOI18N + + // Set parameter + query.setParameter("faxNumberId", faxNumberId); //NOI18N + + // Init instance + DialableFaxNumber faxNumber = null; + + // Try to get a result + try { + // Get a single result + faxNumber = (DialableFaxNumber) query.getSingleResult(); + } catch (NoResultException ex) { + // The entry was not found, so throw it again + throw new PhoneEntityNotFoundException(faxNumberId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Return found instance + return faxNumber; + } + + @Override + public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), landLineNumberId)); //NOI18N + + // The id number should be valid + if (null == landLineNumberId) { + // Throw NPE + throw new NullPointerException("landLineNumberId is null"); //NOI18N + } else if (landLineNumberId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is not valid.", landLineNumberId)); //NOI18N + } + + // Now find it + Query query = this.getEntityManager().createNamedQuery("SearchLandLineNumberId", LandLineNumber.class); //NOI18N + + // Set parameter + query.setParameter("landLineNumberId", landLineNumberId); //NOI18N + + // Init instance + DialableLandLineNumber landLineNumber = null; + + // Try to get a result + try { + // Get a single result + landLineNumber = (DialableLandLineNumber) query.getSingleResult(); + } catch (NoResultException ex) { + // The entry was not found, so throw it again + throw new PhoneEntityNotFoundException(landLineNumberId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N + + // Return found instance + return landLineNumber; + } + @Override public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCellphoneById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), mobileNumberId)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), mobileNumberId)); //NOI18N // The id number should be valid if (null == mobileNumberId) { @@ -139,7 +217,7 @@ public class PizzaPhoneSessionBean extends BasePizzaDatabaseBean implements Phon } // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCellphoneById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), cellphone)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), cellphone)); //NOI18N // Return found instance return cellphone;