]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Tue, 23 Aug 2016 12:13:53 +0000 (14:13 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 24 Aug 2016 19:22:27 +0000 (21:22 +0200)
- implemented business methods for deleting/updating fax/land-line numbers
- better this way: managedBla = em.find(Bla.class, bla.getBlaId()); and then managedBla.setBlaSomeFoo(someFooValue);

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

index a2c297e7d0f84e7d4755b1554aa13b1f07c14e27..154c881427ce1d5e290dfbf3ce198f1f66f75cc5 100644 (file)
@@ -19,6 +19,8 @@ package org.mxchange.jphone.phonenumbers.phone;
 import java.text.MessageFormat;
 import java.util.GregorianCalendar;
 import javax.ejb.Stateless;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
 import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 
@@ -35,6 +37,102 @@ public class PizzaAdminPhoneSessionBean extends BasePizzaDatabaseBean implements
         */
        private static final long serialVersionUID = 18_597_165_817_401_853L;
 
+       @Override
+       public void deleteFaxData (final DialableFaxNumber faxNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
+
+               // Is all data set
+               if (faxNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("faxNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+               } else if (faxNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
+               } else if (faxNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Get a managed instance
+               DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId());
+
+               // Remove it from database
+               this.getEntityManager().remove(managedNumber);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
+       }
+
+       @Override
+       public void deleteLandLineData (final DialableLandLineNumber landLineNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
+
+               // Is all data set
+               if (landLineNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("landLineNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+               } else if (landLineNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Get a managed instance
+               DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId());
+
+               // Remove it from database
+               this.getEntityManager().remove(managedNumber);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
+       }
+
        @Override
        public void deleteMobileData (final DialableMobileNumber mobileNumber) {
                // Trace message
@@ -67,7 +165,7 @@ public class PizzaAdminPhoneSessionBean extends BasePizzaDatabaseBean implements
                        throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Merge it to get a managed entity back
+               // Get a managed instance
                DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId());
 
                // Remove it from database
@@ -77,6 +175,120 @@ public class PizzaAdminPhoneSessionBean extends BasePizzaDatabaseBean implements
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName()));
        }
 
+       @Override
+       public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
+
+               // Is all data set
+               if (faxNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("faxNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+               } else if (faxNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
+               } else if (faxNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Get contact from it and find it
+               DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
+
+               // Should be found
+               assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
+
+               // Set updated timestamp
+               managedNumber.setPhoneEntryUpdated(new GregorianCalendar());
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
+
+               // Return it
+               return managedNumber;
+       }
+
+       @Override
+       public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
+
+               // Is all data set
+               if (landLineNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("landLineNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+               } else if (landLineNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Get contact from it and find it
+               DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
+
+               // Should be found
+               assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
+
+               // Set updated timestamp
+               landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
+
+               // Return it
+               return managedNumber;
+       }
+
        @Override
        public DialableMobileNumber updateMobileData (final DialableMobileNumber mobileNumber) {
                // Trace message
@@ -109,29 +321,23 @@ public class PizzaAdminPhoneSessionBean extends BasePizzaDatabaseBean implements
                        throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Set updated timestamp
-               mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
-
                // Get contact from it and find it
-               DialableMobileNumber foundNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId());
+               DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
 
                // Should be found
-               assert (foundNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N
+               assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N
 
                // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: foundNumber.phoneId={1}", this.getClass().getSimpleName(), foundNumber.getPhoneId())); //NOI18N
-
-               // Merge contact instance
-               DialableMobileNumber detachedNumber = this.getEntityManager().merge(foundNumber);
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
 
                // Set updated timestamp
-               detachedNumber.setPhoneEntryUpdated(new GregorianCalendar());
+               mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
 
                // Return it
-               return detachedNumber;
+               return managedNumber;
        }
 
 }