]> git.mxchange.org Git - jjobs-core.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Mon, 22 Aug 2016 10:56:42 +0000 (12:56 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 24 Aug 2016 19:29:42 +0000 (21:29 +0200)
- fetch entity first with getReference(), then make it detached (maybe right?), then merge it
- added missing javadoc reference (URL)

Signed-off-by: Roland Häder <roland@mxchange.org>
lib/nblibraries.properties
src/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java

index 09266ab51ba16c77f3b822de555a34cb3e59db75..f508429b10ef4dcd1fe691a451f9b0defe383649 100644 (file)
@@ -9,4 +9,6 @@ libs.javaee-api-7.0.prop-maven-dependencies=javax:javaee-api:7.0:jar
 libs.jpa20-persistence.classpath=\
     ${base}/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar
 libs.jpa20-persistence.displayName=Persistence (JPA 2.1)
+libs.jpa20-persistence.javadoc=\
+    https://docs.oracle.com/javaee/7/api/
 libs.jpa20-persistence.prop-maven-dependencies=org.eclipse.persistence:javax.persistence:2.1.0:jar
index 52bd2573c1ea9e25d68d4ccf88e0e51bbbfa6f62..60bb7dc5a1398963d9321a451b229e5f381a7f3b 100644 (file)
@@ -38,8 +38,11 @@ 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;
@@ -127,8 +130,11 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
 
                // Is contact cellphone set?
                if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
-                       // Copy cellphone number
-                       contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), contact.getContactMobileNumber()));
+                       // Fetch it from entity manager
+                       DialableMobileNumber fetchedNumber = this.getEntityManager().getReference(MobileNumber.class, contact.getContactMobileNumber().getPhoneId());
+
+                       // Copy mobile number
+                       contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), fetchedNumber));
                }
 
                // Debug message
@@ -136,8 +142,11 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
 
                // 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());
+
                        // Copy land-line number
-                       contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), contact.getContactLandLineNumber()));
+                       contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), fetchedNumber));
                }
 
                // Debug message
@@ -145,8 +154,11 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
 
                // 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());
+
                        // Copy fax number
-                       contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), contact.getContactFaxNumber()));
+                       contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), fetchedNumber));
                }
 
                // Trace message
@@ -174,7 +186,7 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
                DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
 
                // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},cellphoneNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},mobileNumber={2}", landLineNumber, faxNumber, mobileNumber)); //NOI18N
 
                // Is a phone number instance set?
                if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
@@ -217,12 +229,15 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
         */
        protected DialableMobileNumber getDetached (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: cellphoneNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: mobileNumber={0},fetchedNumber={1} - CALLED!", mobileNumber, fetchedNumber)); //NOI18N
 
                // Should be valid
                if (null == mobileNumber) {
                        // Throw NPE
-                       throw new NullPointerException("cellphoneNumber is null"); //NOI18N
+                       throw new NullPointerException("mobileNumber is null"); //NOI18N
+               } else if (null == fetchedNumber) {
+                       // Throw NPE again
+                       throw new NullPointerException("fetchedNumber is null"); //NOI18N
                } else if (fetchedNumber.getPhoneId() == null) {
                        // ..and again
                        throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N
@@ -237,15 +252,13 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
 
-               // Default is null
-               DialableMobileNumber detachedNumber = null;
+               // Default is fetched number
+               DialableMobileNumber detachedNumber = fetchedNumber;
 
                // Is there a difference?
                if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
                        // Merge this entry
                        detachedNumber = this.getEntityManager().merge(foundNumber);
-
-                       // Copy all
                }
 
                // Trace message
@@ -673,12 +686,12 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
                // Get all phone instances
                DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
                DialableFaxNumber faxNumber = contact.getContactFaxNumber();
-               DialableMobileNumber cellphoneNumber = contact.getContactMobileNumber();
+               DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
 
                // Flags and instances must be constistent
-               if (isMobileUnlinked && cellphoneNumber instanceof DialableMobileNumber) {
+               if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
                        // Bad state
-                       throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but cellphoneNumber is set."); //NOI18N
+                       throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N
                } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
                        // Bad state
                        throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
@@ -706,12 +719,12 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
                }
 
                // Is a mobile number instance set?
-               if ((cellphoneNumber instanceof DialableMobileNumber) && (cellphoneNumber.getPhoneId() instanceof Long) && (cellphoneNumber.getPhoneId() > 0)) {
+               if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
                        // Debug message
                        this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ..."); //NOI18N
 
                        // Set updated timestamp
-                       cellphoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
+                       mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
                }
 
                // Trace message