]> git.mxchange.org Git - pizzaservice-core.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Tue, 23 Aug 2016 09:33:39 +0000 (11:33 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 24 Aug 2016 19:21:20 +0000 (21:21 +0200)
- detachAllContactPhoneEntries() was a bad idea, beter do it the old way.

src/org/mxchange/pizzaaplication/database/BasePizzaDatabaseBean.java

index 0d18b8545aa9f7dc96b42fb16f950cb19d40e3d5..1d2a559fa4da095ad305647e5685329de9d331c5 100644 (file)
@@ -38,11 +38,8 @@ import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper;
 import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
 import org.mxchange.jphone.utils.PhoneUtils;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserUtils;
@@ -110,79 +107,6 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                }
        }
 
-       /**
-        * Detaches all contact's phone instances.
-        * <p>
-        * @param contact Contact to set instances
-        */
-       protected void detachAllContactPhoneEntries (final Contact contact) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
-
-               // Both must be the same and not null
-               if (null == contact) {
-                       // Throw NPE
-                       throw new NullPointerException("contact is null"); //NOI18N
-               }
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact.contactMobileNumber={1}", this.getClass().getSimpleName(), contact.getContactMobileNumber())); //NOI18N
-
-               // Is contact cellphone set?
-               if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
-                       // Fetch it from entity manager
-                       DialableMobileNumber fetchedNumber = this.getEntityManager().getReference(MobileNumber.class, contact.getContactMobileNumber().getPhoneId());
-
-                       // Get detached number
-                       DialableMobileNumber detachedNumber = this.getDetached(contact.getContactMobileNumber(), fetchedNumber);
-
-                       // Is it null?
-                       if (detachedNumber instanceof DialableMobileNumber) {
-                               // Copy mobile number
-                               contact.setContactMobileNumber(detachedNumber);
-                       }
-               }
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact.contactLandLineNumber={1}", this.getClass().getSimpleName(), contact.getContactLandLineNumber())); //NOI18N
-
-               // Is the land-line number set?
-               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
-                       // Fetch it from entity manager
-                       DialableLandLineNumber fetchedNumber = this.getEntityManager().getReference(LandLineNumber.class, contact.getContactLandLineNumber().getPhoneId());
-
-                       // Get detached number
-                       DialableLandLineNumber detachedNumber = this.getDetached(contact.getContactLandLineNumber(), fetchedNumber);
-
-                       // Is it null?
-                       if (detachedNumber instanceof DialableLandLineNumber) {
-                               // Copy mobile number
-                               contact.setContactLandLineNumber(detachedNumber);
-                       }
-               }
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.detachAllContactPhoneEntries: contact.contactFaxNumber={1}", this.getClass().getSimpleName(), contact.getContactFaxNumber())); //NOI18N
-
-               // Is the fax number set?
-               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
-                       // Fetch it from entity manager
-                       DialableFaxNumber fetchedNumber = this.getEntityManager().getReference(FaxNumber.class, contact.getContactFaxNumber().getPhoneId());
-
-                       // Get detached number
-                       DialableFaxNumber detachedNumber = this.getDetached(contact.getContactFaxNumber(), fetchedNumber);
-
-                       // Is it null?
-                       if (detachedNumber instanceof DialableFaxNumber) {
-                               // Copy mobile number
-                               contact.setContactFaxNumber(detachedNumber);
-                       }
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.detachAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
-       }
-
        /**
         * Updates all contacts's phone entry's created timestamps
         * <p>
@@ -238,14 +162,14 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
        }
 
        /**
-        * Returnes a detached instance from given cellphone instance
+        * Returnes a managed instance from given mobile number
         * <p>
-        * @param mobileNumber Mobile instance
-        * @param fetchedNumber Found cellphone number in database
+        * @param mobileNumber Mobile number
+        * @param fetchedNumber Found mobile number in database
         * <p>
-        * @return Detached instance
+        * @return Managed instance
         */
-       protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
+       protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
 
@@ -264,37 +188,31 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
 
-               // Init query instance
-               DialableMobileNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: foundNumber={1}", this.getClass().getSimpleName(), foundNumber)); //NOI18N
-
                // Default is null
-               DialableMobileNumber detachedNumber = null;
+               DialableMobileNumber managedNumber = null;
 
                // Is there a difference?
                if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
                        // Merge this entry
-                       detachedNumber = this.getEntityManager().merge(foundNumber);
+                       managedNumber = this.getEntityManager().merge(fetchedNumber);
                }
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
 
                // Return it
-               return detachedNumber;
+               return managedNumber;
        }
 
        /**
-        * Returnes a detached instance from given land-line instance
+        * Returnes a managed instance from given land-line number
         * <p>
-        * @param landLineNumber Land-line instance
+        * @param landLineNumber Land-line number
         * @param fetchedNumber Found land-line number in database
         * <p>
-        * @return Detached instance
+        * @return Managed instance
         */
-       protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
+       protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N
 
@@ -313,37 +231,31 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
 
-               // Init query instance
-               DialableLandLineNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: foundNumber={1}", this.getClass().getSimpleName(), foundNumber)); //NOI18N
-
                // Default is null
-               DialableLandLineNumber detachedNumber = null;
+               DialableLandLineNumber managedNumber = null;
 
                // Is there a difference?
                if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
                        // Merge this entry
-                       detachedNumber = this.getEntityManager().merge(foundNumber);
+                       managedNumber = this.getEntityManager().merge(fetchedNumber);
                }
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
 
                // Return it
-               return detachedNumber;
+               return managedNumber;
        }
 
        /**
-        * Returnes a detached instance from given fax instance
+        * Returnes a managed instance from given fax number
         * <p>
-        * @param faxNumber Fax instance
+        * @param faxNumber Fax number
         * @param fetchedNumber Found fax number in database
         * <p>
-        * @return Detached instance
+        * @return Managed instance
         */
-       protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
+       protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N
 
@@ -362,74 +274,68 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
 
-               // Init query instance
-               DialableFaxNumber foundNumber = this.getEntityManager().getReference(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: foundNumber={1}", this.getClass().getSimpleName(), foundNumber)); //NOI18N
-
                // Default is null
-               DialableFaxNumber detachedNumber = null;
+               DialableFaxNumber managedNumber = null;
 
                // Is there a difference?
                if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
                        // Merge this entry
-                       detachedNumber = this.getEntityManager().merge(foundNumber);
+                       managedNumber = this.getEntityManager().merge(fetchedNumber);
                }
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
 
                // Return it
-               return detachedNumber;
+               return managedNumber;
        }
 
        /**
-        * Merges given contact's data
+        * Merges given (detached) contact's data
         * <p>
-        * @param contact Contact instance to merge
+        * @param detachedContact Contact instance to merge
         * <p>
         * @return Detached contact instance
         */
-       protected Contact mergeContactData (final Contact contact) {
+       protected Contact mergeContactData (final Contact detachedContact) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
 
                // The contact instance must be valid
-               if (null == contact) {
+               if (null == detachedContact) {
                        // Throw NPE again
-                       throw new NullPointerException("contact is null"); //NOI18N
-               } else if (contact.getContactId() == null) {
+                       throw new NullPointerException("detachedContact is null"); //NOI18N
+               } else if (detachedContact.getContactId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
-               } else if (contact.getContactId() < 1) {
+                       throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
+               } else if (detachedContact.getContactId() < 1) {
                        // Not valid
-                       throw new IllegalStateException(MessageFormat.format("{0}.contact.contactId={1} is not valid.", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
                }
 
-               // Set updated timestamp
-               contact.setContactUpdated(new GregorianCalendar());
-
                // Get contact from it and find it
-               Contact foundContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId());
+               Contact foundContact = this.getEntityManager().getReference(detachedContact.getClass(), detachedContact.getContactId());
 
                // Should be found
-               assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N
+               assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N
 
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N
 
                // Merge contact instance
-               Contact detachedContact = this.getEntityManager().merge(foundContact);
+               Contact managedContact = this.getEntityManager().merge(foundContact);
+
+               // Set updated timestamp
+               managedContact.setContactUpdated(new GregorianCalendar());
 
                // Copy all
-               detachedContact.copyAll(contact);
+               managedContact.copyAll(detachedContact);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return detached contact
-               return detachedContact;
+               return managedContact;
        }
 
        /**
@@ -464,22 +370,16 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
 
                        // Then find it, too
-                       DialableMobileNumber foundMobile = this.getEntityManager().getReference(cellphone.getClass(), cellphone.getPhoneId());
+                       DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
 
                        // Should be there
                        assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
 
-                       // Then merge it, too
-                       DialableMobileNumber detachedMobile = this.getEntityManager().merge(foundMobile);
-
-                       // Should be there
-                       assert (detachedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", detachedMobile.getPhoneId()); //NOI18N
-
                        // Copy all
-                       detachedMobile.copyAll(detachedContact.getContactMobileNumber());
+                       foundMobile.copyAll(detachedContact.getContactMobileNumber());
 
                        // Set it back
-                       detachedContact.setContactMobileNumber(detachedMobile);
+                       detachedContact.setContactMobileNumber(foundMobile);
                }
 
                // Is there a  fax instance set?
@@ -488,22 +388,13 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
 
                        // Then find it, too
-                       DialableFaxNumber foundFax = this.getEntityManager().getReference(fax.getClass(), fax.getPhoneId());
-
-                       // Should be there
-                       assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
-
-                       // Then merge it, too
-                       DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
-
-                       // Should be there
-                       assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
+                       DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
 
                        // Copy all
-                       detachedFax.copyAll(detachedContact.getContactFaxNumber());
+                       foundFax.copyAll(detachedContact.getContactFaxNumber());
 
                        // Set it back
-                       detachedContact.setContactFaxNumber(detachedFax);
+                       detachedContact.setContactFaxNumber(foundFax);
                }
 
                // Is there a  fax instance set?
@@ -512,22 +403,16 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
 
                        // Then find it, too
-                       DialableLandLineNumber foundLandLine = this.getEntityManager().getReference(landLine.getClass(), landLine.getPhoneId());
+                       DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
 
                        // Should be there
                        assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
 
-                       // Then merge it, too
-                       DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
-
-                       // Should be there
-                       assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
-
                        // Copy all
-                       detachedLandLine.copyAll(detachedContact.getContactLandLineNumber());
+                       foundLandLine.copyAll(detachedContact.getContactLandLineNumber());
 
                        // Set it back
-                       detachedContact.setContactLandLineNumber(detachedLandLine);
+                       detachedContact.setContactLandLineNumber(foundLandLine);
                }
 
                // Trace message
@@ -633,7 +518,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        // Is the fax number set?
                        if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
                                // Copy cellphone number
-                               contact.setContactMobileNumber(this.getDetached(other.getContactMobileNumber(), contact.getContactMobileNumber()));
+                               contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
                        } else {
                                // Null it
                                contact.setContactMobileNumber(null);
@@ -651,7 +536,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        // Is the land-line number set?
                        if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
                                // Copy land-line number
-                               contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
+                               contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
                        } else {
                                // Null it
                                contact.setContactLandLineNumber(null);
@@ -669,7 +554,7 @@ public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
                        // Is the fax number set?
                        if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
                                // Copy fax number
-                               contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
+                               contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
                        } else {
                                // Null it
                                contact.setContactFaxNumber(null);