]> git.mxchange.org Git - pizzaservice-mailer-ejb.git/commitdiff
Continued a bit: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Tue, 16 Aug 2016 14:30:20 +0000 (16:30 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 16 Aug 2016 19:46:17 +0000 (21:46 +0200)
- implemented business methods findFaxNumberById() and findLandLineNumberById()
- sorted members
- fixed log message: cellphone -> mobile again and always use "number" suffix

src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java

index 43321a5a988518c634d67078018de9be19b1c206..747ae5843e79f040979ce1865167da937d04e6c8 100644 (file)
@@ -51,18 +51,18 @@ public class AddressbookPhoneSessionBean extends BaseDatabaseBean implements Pho
 
        @SuppressWarnings ("unchecked")
        @Override
-       public List<DialableMobileNumber> allMobileNumbers () {
+       public List<DialableFaxNumber> 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<DialableMobileNumber> list = query.getResultList();
+               List<DialableFaxNumber> 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 AddressbookPhoneSessionBean extends BaseDatabaseBean implements Pho
 
        @SuppressWarnings ("unchecked")
        @Override
-       public List<DialableFaxNumber> allFaxNumbers () {
+       public List<DialableLandLineNumber> 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<DialableFaxNumber> list = query.getResultList();
+               List<DialableLandLineNumber> 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 AddressbookPhoneSessionBean extends BaseDatabaseBean implements Pho
 
        @SuppressWarnings ("unchecked")
        @Override
-       public List<DialableLandLineNumber> allLandLineNumbers () {
+       public List<DialableMobileNumber> 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<DialableLandLineNumber> list = query.getResultList();
+               List<DialableMobileNumber> 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 AddressbookPhoneSessionBean extends BaseDatabaseBean implements Pho
                }
 
                // 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;