From 8da80d9bf345dd08bdfa45300339144c65ec5077 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 26 Jun 2019 05:29:57 +0200 Subject: [PATCH] Continued: - added *.copyAll() invocation for having all entity properties being "copied" - updated log messages with correct method name - updated TODOs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../database/BaseFinancialsDatabaseBean.java | 40 +++++------ .../BaseFinancialsProductDatabaseBean.java | 10 +-- .../model/user/FinancialsUserSessionBean.java | 71 ++++++++----------- 3 files changed, 54 insertions(+), 67 deletions(-) diff --git a/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java b/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java index e1056d2..c08b2c4 100644 --- a/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java +++ b/src/java/org/mxchange/jfinancials/database/BaseFinancialsDatabaseBean.java @@ -768,10 +768,10 @@ public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { // Is there a difference? if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + // Merge this entry detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all } // Trace message @@ -816,10 +816,10 @@ public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { // Is there a difference? if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + // Merge this entry detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all } // Trace message @@ -864,10 +864,10 @@ public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { // Is there a difference? if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) { + // @TODO Copy all to foundNumber, then merge + // Merge this entry detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all } // Trace message @@ -910,16 +910,16 @@ public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { 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("updateUserPersonalData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeContactData: foundContact.contactId={0}", foundContact.getContactId())); //NOI18N + + // Copy all + Contacts.copyAll(detachedContact, foundContact); // Merge contact instance final Contact managedContact = this.getEntityManager().merge(foundContact); - // Copy all - Contacts.copyAll(detachedContact, managedContact); - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - EXIT!", managedContact)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: managedContact={0} - EXIT!", managedContact)); //NOI18N // Return detached contact return managedContact; @@ -962,15 +962,15 @@ public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { // Should be there assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N + // Copy all + MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), foundMobile); + // Then merge it, too final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile); // Should be there assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N - // Copy all - MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile); - // Set it back detachedContact.setContactMobileNumber(managedMobile); } @@ -986,15 +986,15 @@ public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { // Should be there assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N + // Copy all + FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), foundFax); + // Then merge it, too final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax); // Should be there assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N - // Copy all - FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax); - // Set it back detachedContact.setContactFaxNumber(managedFax); } @@ -1010,15 +1010,15 @@ public abstract class BaseFinancialsDatabaseBean extends BaseEnterpriseBean { // Should be there assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N + // Copy all + LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), foundLandLine); + // Then merge it, too final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine); // Should be there assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N - // Copy all - LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine); - // Set it back detachedContact.setContactLandLineNumber(managedLandLine); } diff --git a/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java b/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java index f78f1d2..5e8f7df 100644 --- a/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java +++ b/src/java/org/mxchange/jfinancials/database/product/BaseFinancialsProductDatabaseBean.java @@ -151,16 +151,16 @@ public abstract class BaseFinancialsProductDatabaseBean extends BaseFinancialsDa assert (foundProduct instanceof Product) : MessageFormat.format("Product with id {0} not found, but should be.", detachedProduct.getProductId()); //NOI18N // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: foundProduct.productId={0}", foundProduct.getProductId())); //NOI18N + this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeProductData: foundProduct.productId={0}", foundProduct.getProductId())); //NOI18N + + // Copy all + Products.copyAll(detachedProduct, foundProduct); // Merge product instance final Product managedProduct = this.getEntityManager().merge(foundProduct); - // Copy all - Products.copyAll(detachedProduct, managedProduct); - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeProductData: detachedProduct={0} - EXIT!", managedProduct)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeProductData: managedProduct={0} - EXIT!", managedProduct)); //NOI18N // Return detached product return managedProduct; diff --git a/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java index 1b699b6..55f85dc 100644 --- a/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/FinancialsUserSessionBean.java @@ -410,36 +410,39 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem } @Override - public User updateUserData (final User user) { + public User updateUserData (final User detachedUser) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: detachedUser={1} - CALLED!", this.getClass().getSimpleName(), detachedUser)); //NOI18N // user should not be null - if (null == user) { + if (null == detachedUser) { // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { + throw new NullPointerException("detachedUser is null"); //NOI18N + } else if (detachedUser.getUserId() == null) { // Throw NPE again - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { + throw new NullPointerException("detachedUser.userId is null"); //NOI18N + } else if (detachedUser.getUserId() < 1) { // Not valid - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N - } else if (user.getUserAccountStatus() == null) { + throw new IllegalArgumentException(MessageFormat.format("detachedUser.userId={0} is not valid.", detachedUser.getUserId())); //NOI18N + } else if (detachedUser.getUserAccountStatus() == null) { // Throw NPE again - throw new NullPointerException("user.userAccountStatus is null"); //NOI18N - } else if (!this.ifUserExists(user)) { + throw new NullPointerException("detachedUser.userAccountStatus is null"); //NOI18N + } else if (!this.ifUserExists(detachedUser)) { // User does not exist - throw new EJBException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N + throw new EJBException(MessageFormat.format("User with id {0} does not exist.", detachedUser.getUserId())); //NOI18N } // Remove contact instance as this is not updated - user.setUserContact(null); + detachedUser.setUserContact(null); // Find the instance - final User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId()); + final User foundUser = this.getEntityManager().find(detachedUser.getClass(), detachedUser.getUserId()); // Should be found! - assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N + assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", detachedUser.getUserId()); //NOI18N + + // Copy all data + Users.copyAll(detachedUser, foundUser); // Merge user final User managedUser = this.getEntityManager().merge(foundUser); @@ -447,9 +450,6 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem // Should be found! assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", managedUser.getUserId()); //NOI18N - // Copy all data - Users.copyAll(managedUser, managedUser); - // Set as updated managedUser.setUserUpdated(new Date()); @@ -570,22 +570,9 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem // Set as updated managedUser.setUserUpdated(new Date()); - managedUser.getUserContact().setContactUpdated(new Date()); - - // Get contact from it and find it - final Contact foundContact = this.getEntityManager().find(managedUser.getUserContact().getClass(), managedUser.getUserContact().getContactId()); - // Should be found - assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", managedUser.getUserContact().getContactId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N - - // Merge contact instance - final Contact managedContact = this.getEntityManager().merge(foundContact); - - // Copy all - Contacts.copyAll(managedUser.getUserContact(), managedContact); + // Update user data + final Contact managedContact = this.mergeContactData(managedUser.getUserContact()); // Set it back in user managedUser.setUserContact(managedContact); @@ -607,15 +594,15 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem // Should be there assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N + // Copy all + MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), foundMobile); + // Then merge it, too final DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile); // Should be there assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N - // Copy all - MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), managedMobile); - // Set it back managedContact.setContactMobileNumber(managedMobile); } @@ -634,15 +621,15 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem // Should be there assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N + // Copy all + FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), foundFax); + // Then merge it, too final DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax); // Should be there assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N - // Copy all - FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), managedFax); - // Set it back managedContact.setContactFaxNumber(managedFax); } @@ -661,15 +648,15 @@ public class FinancialsUserSessionBean extends BaseFinancialsDatabaseBean implem // Should be there assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N + // Copy all + LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), foundLandLine); + // Then merge it, too final DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine); // Should be there assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N - // Copy all - LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine); - // Set it back managedContact.setContactLandLineNumber(managedLandLine); } -- 2.39.5