From baba4ba31eb7e41c18270b2534c7ce0a5f34eac1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 10 Oct 2019 23:30:08 +0200 Subject: [PATCH] Don't cherry-pick: - renamed BaseJobsDatabaseBean to BaseJobsEnterpriseBeans - also sorted members MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../ejb/BaseJobsEnterpriseBean.java} | 463 +++++++++--------- 1 file changed, 232 insertions(+), 231 deletions(-) rename src/java/org/mxchange/jjobs/{database/BaseJobsDatabaseBean.java => beans/ejb/BaseJobsEnterpriseBean.java} (97%) diff --git a/src/java/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java b/src/java/org/mxchange/jjobs/beans/ejb/BaseJobsEnterpriseBean.java similarity index 97% rename from src/java/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java rename to src/java/org/mxchange/jjobs/beans/ejb/BaseJobsEnterpriseBean.java index 1e567cb..c18d1bd 100644 --- a/src/java/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java +++ b/src/java/org/mxchange/jjobs/beans/ejb/BaseJobsEnterpriseBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jjobs.database; +package org.mxchange.jjobs.beans.ejb; import java.text.MessageFormat; import java.util.Date; @@ -29,16 +29,17 @@ import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.Contacts; +import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters; -import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter; +import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; -import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper; @@ -59,7 +60,7 @@ import org.mxchange.jusercore.model.user.Users; *

* @author Roland Häder */ -public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { +public abstract class BaseJobsEnterpriseBean extends BaseEnterpriseBean { /** * Serial number @@ -69,7 +70,7 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { /** * Protected constructor */ - protected BaseJobsDatabaseBean () { + protected BaseJobsEnterpriseBean () { // Call super constructor super(); } @@ -80,218 +81,11 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { * @param factoryJndi JNDI name for queue factory * @param queueJndi JNDI name for email queue */ - protected BaseJobsDatabaseBean (final String factoryJndi, final String queueJndi) { + protected BaseJobsEnterpriseBean (final String factoryJndi, final String queueJndi) { // Call super constructor super(factoryJndi, queueJndi); } - /** - * Updates all contact's phone entry's created timestamps - *

- * @param contact Contact instance to update - */ - protected void setAllContactPhoneEntriesCreated (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } - - // Get all phone instances - final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber(); - final DialableFaxNumber faxNumber = contact.getContactFaxNumber(); - final DialableMobileNumber mobileNumber = contact.getContactMobileNumber(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N - - // Is a phone number instance set? - if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - landLineNumber.setPhoneEntryCreated(new Date()); - } - - // Is a fax number instance set? - if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - faxNumber.setPhoneEntryCreated(new Date()); - } - - // Is a mobile number instance set? - if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - mobileNumber.setPhoneEntryCreated(new Date()); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - /** - * Returns a managed instance from given mobile number - *

- * @param mobileNumber Mobile instance - * @param fetchedNumber Found mobile number in database - *

- * @return Managed instance - */ - 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 - - // Should be valid - if (null == mobileNumber) { - // Throw NPE - 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 - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N - - // Init query instance - final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId()); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N - - // Default is null - DialableMobileNumber detachedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { - // Merge this entry - detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N - - // Return it - return detachedNumber; - } - - /** - * Returns a managed instance from given land-line number - *

- * @param landLineNumber Land-line instance - * @param fetchedNumber Found land-line number in database - *

- * @return Managed instance - */ - 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 - - // Should be valid - if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber 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("landLineNumber.phoneId is null"); //NOI18N - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N - - // Init query instance - final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId()); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N - - // Default is null - DialableLandLineNumber detachedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) { - // Merge this entry - detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N - - // Return it - return detachedNumber; - } - - /** - * Returns a managed instance from given fax number - *

- * @param faxNumber Fax instance - * @param fetchedNumber Found fax number in database - *

- * @return Managed instance - */ - 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 - - // Should be valid - if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber 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 - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N - - // Init query instance - final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId()); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N - - // Default is null - DialableFaxNumber detachedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) { - // Merge this entry - detachedNumber = this.getEntityManager().merge(foundNumber); - - // @TODO Copy all - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N - - // Return it - return detachedNumber; - } - /** * Get back a managed instance from given contact *

@@ -427,7 +221,7 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, headquarter.getBranchId()); // Should be there - assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N + assert (managedBranchOffice instanceof BranchOffice) : "managedBranchOffice is null"; //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N @@ -473,39 +267,39 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { } /** - * Get back a managed instance from given headquarters + * Get back a managed instance from given headquarter *

- * @param headquarters Unmanaged/detached headquarters instance + * @param headquarter Unmanaged/detached headquarter instance *

* @return Managed basic data instance */ - protected Headquarter createManaged (final Headquarter headquarters) { + protected Headquarter createManaged (final Headquarter headquarter) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N // user should not be null - if (null == headquarters) { + if (null == headquarter) { // Abort here throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarters.getHeadquartersId() == null) { + } else if (headquarter.getHeadquarterId() == null) { // Id is set - throw new NullPointerException("headquarter.headquartersId is null"); //NOI18N - } else if (headquarters.getHeadquartersId() < 1) { + throw new NullPointerException("headquarter.headquarterId is null"); //NOI18N + } else if (headquarter.getHeadquarterId() < 1) { // Id is set - throw new IllegalArgumentException(MessageFormat.format("headquarter.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is invalid", headquarter.getHeadquarterId())); //NOI18N } // Try to find it (should be there) - final Headquarter managedHeadquarters = this.getEntityManager().find(BusinessHeadquarters.class, headquarters.getHeadquartersId()); + final Headquarter managedHeadquarter = this.getEntityManager().find(BusinessHeadquarter.class, headquarter.getHeadquarterId()); // Should be there assert (managedHeadquarter instanceof Headquarter) : "managedHeadquarter is null"; //NOI18N // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarters={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarters)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarter={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarter)); //NOI18N // Return it - return managedHeadquarters; + return managedHeadquarter; } /** @@ -553,6 +347,60 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { return managedUser; } + /** + * Updates all contact's phone entry's created timestamps + *

+ * @param contact Contact instance to update + */ + protected void setAllContactPhoneEntriesCreated (final Contact contact) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N + + // The contact instance must be valid + if (null == contact) { + // Throw NPE again + throw new NullPointerException("contact is null"); //NOI18N + } + + // Get all phone instances + final DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber(); + final DialableFaxNumber faxNumber = contact.getContactFaxNumber(); + final DialableMobileNumber mobileNumber = contact.getContactMobileNumber(); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N + + // Is a phone number instance set? + if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N + + // Set updated timestamp + landLineNumber.setPhoneEntryCreated(new Date()); + } + + // Is a fax number instance set? + if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N + + // Set updated timestamp + faxNumber.setPhoneEntryCreated(new Date()); + } + + // Is a mobile number instance set? + if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for mobile number ...", this.getClass().getSimpleName())); //NOI18N + + // Set updated timestamp + mobileNumber.setPhoneEntryCreated(new Date()); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N + } + /** * Sets created timestamp on all opening times. *

@@ -702,14 +550,14 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { if (null == headquarter) { // Throw NPE again throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarter.getHeadquartersId() != null) { + } else if (headquarter.getHeadquarterId() != null) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("headquarter.branchId={0} is unexpected.", headquarter.getHeadquartersId())); + throw new IllegalArgumentException(MessageFormat.format("headquarter.headquarterId={0} is unexpected.", headquarter.getHeadquarterId())); } // Get all phone instances - final DialableLandLineNumber landLineNumber = headquarter.getHeadquartersLandLineNumber(); - final DialableFaxNumber faxNumber = headquarter.getHeadquartersFaxNumber(); + final DialableLandLineNumber landLineNumber = headquarter.getHeadquarterLandLineNumber(); + final DialableFaxNumber faxNumber = headquarter.getHeadquarterFaxNumber(); // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllPhoneEntriesCreated: landLineNumber={0},faxNumber={1}", landLineNumber, faxNumber)); //NOI18N @@ -933,6 +781,159 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { return detachedNumber; } + /** + * Returns a managed instance from given mobile number + *

+ * @param mobileNumber Mobile instance + * @param fetchedNumber Found mobile number in database + *

+ * @return Managed instance + */ + 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 + + // Should be valid + if (null == mobileNumber) { + // Throw NPE + 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 + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N + + // Init query instance + final DialableMobileNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId()); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N + + // Default is null + DialableMobileNumber detachedNumber = null; + + // Is there a difference? + if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { + // Merge this entry + detachedNumber = this.getEntityManager().merge(foundNumber); + + // @TODO Copy all + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N + + // Return it + return detachedNumber; + } + + /** + * Returns a managed instance from given land-line number + *

+ * @param landLineNumber Land-line instance + * @param fetchedNumber Found land-line number in database + *

+ * @return Managed instance + */ + 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 + + // Should be valid + if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber 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("landLineNumber.phoneId is null"); //NOI18N + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N + + // Init query instance + final DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId()); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N + + // Default is null + DialableLandLineNumber detachedNumber = null; + + // Is there a difference? + if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) { + // Merge this entry + detachedNumber = this.getEntityManager().merge(foundNumber); + + // @TODO Copy all + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N + + // Return it + return detachedNumber; + } + + /** + * Returns a managed instance from given fax number + *

+ * @param faxNumber Fax instance + * @param fetchedNumber Found fax number in database + *

+ * @return Managed instance + */ + 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 + + // Should be valid + if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber 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 + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N + + // Init query instance + final DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId()); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N + + // Default is null + DialableFaxNumber detachedNumber = null; + + // Is there a difference? + if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) { + // Merge this entry + detachedNumber = this.getEntityManager().merge(foundNumber); + + // @TODO Copy all + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N + + // Return it + return detachedNumber; + } + /** * Merges given contact's data *

-- 2.39.5