-<?xml version="1.0" encoding="UTF-8"?>\r
-<!-- You may freely edit this file. See commented blocks below for -->\r
-<!-- some examples of how to customize the build. -->\r
-<!-- (If you delete it and reopen the project it will be recreated.) -->\r
-<!-- By default, only the Clean and Build commands use this build script. -->\r
-<!-- Commands such as Run, Debug, and Test only use this build script if -->\r
-<!-- the Compile on Save feature is turned off for the project. -->\r
-<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->\r
-<!-- in the project's Project Properties dialog box.-->\r
-<project name="addressbook-core" default="default" basedir=".">\r
- <description>Builds, tests, and runs the project addressbook-core.</description>\r
- <import file="nbproject/build-impl.xml"/>\r
- <!--\r
-\r
- There exist several targets which are by default empty and which can be \r
- used for execution of your tasks. These targets are usually executed \r
- before and after some main targets. They are: \r
-\r
- -pre-init: called before initialization of project properties\r
- -post-init: called after initialization of project properties\r
- -pre-compile: called before javac compilation\r
- -post-compile: called after javac compilation\r
- -pre-compile-single: called before javac compilation of single file\r
- -post-compile-single: called after javac compilation of single file\r
- -pre-compile-test: called before javac compilation of JUnit tests\r
- -post-compile-test: called after javac compilation of JUnit tests\r
- -pre-compile-test-single: called before javac compilation of single JUnit test\r
- -post-compile-test-single: called after javac compilation of single JUunit test\r
- -pre-jar: called before JAR building\r
- -post-jar: called after JAR building\r
- -post-clean: called after cleaning build products\r
-\r
- (Targets beginning with '-' are not intended to be called on their own.)\r
-\r
- Example of inserting an obfuscator after compilation could look like this:\r
-\r
- <target name="-post-compile">\r
- <obfuscate>\r
- <fileset dir="${build.classes.dir}"/>\r
- </obfuscate>\r
- </target>\r
-\r
- For list of available properties check the imported \r
- nbproject/build-impl.xml file. \r
-\r
-\r
- Another way to customize the build is by overriding existing main targets.\r
- The targets of interest are: \r
-\r
- -init-macrodef-javac: defines macro for javac compilation\r
- -init-macrodef-junit: defines macro for junit execution\r
- -init-macrodef-debug: defines macro for class debugging\r
- -init-macrodef-java: defines macro for class execution\r
- -do-jar: JAR building\r
- run: execution of project \r
- -javadoc-build: Javadoc generation\r
- test-report: JUnit report generation\r
-\r
- An example of overriding the target for project execution could look like this:\r
-\r
- <target name="run" depends="addressbook-core-impl.jar">\r
- <exec dir="bin" executable="launcher.exe">\r
- <arg file="${dist.jar}"/>\r
- </exec>\r
- </target>\r
-\r
- Notice that the overridden target depends on the jar target and not only on \r
- the compile target as the regular run target does. Again, for a list of available \r
- properties which you can use, check the target you are overriding in the\r
- nbproject/build-impl.xml file. \r
-\r
- -->\r
-</project>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See commented blocks below for -->
+<!-- some examples of how to customize the build. -->
+<!-- (If you delete it and reopen the project it will be recreated.) -->
+<!-- By default, only the Clean and Build commands use this build script. -->
+<!-- Commands such as Run, Debug, and Test only use this build script if -->
+<!-- the Compile on Save feature is turned off for the project. -->
+<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
+<!-- in the project's Project Properties dialog box.-->
+<project name="jjobs-core" default="default" basedir=".">
+ <description>Builds, tests, and runs the project jjobs-core.</description>
+ <import file="nbproject/build-impl.xml"/>
+ <!--
+
+ There exist several targets which are by default empty and which can be
+ used for execution of your tasks. These targets are usually executed
+ before and after some main targets. They are:
+
+ -pre-init: called before initialization of project properties
+ -post-init: called after initialization of project properties
+ -pre-compile: called before javac compilation
+ -post-compile: called after javac compilation
+ -pre-compile-single: called before javac compilation of single file
+ -post-compile-single: called after javac compilation of single file
+ -pre-compile-test: called before javac compilation of JUnit tests
+ -post-compile-test: called after javac compilation of JUnit tests
+ -pre-compile-test-single: called before javac compilation of single JUnit test
+ -post-compile-test-single: called after javac compilation of single JUunit test
+ -pre-jar: called before JAR building
+ -post-jar: called after JAR building
+ -post-clean: called after cleaning build products
+
+ (Targets beginning with '-' are not intended to be called on their own.)
+
+ Example of inserting an obfuscator after compilation could look like this:
+
+ <target name="-post-compile">
+ <obfuscate>
+ <fileset dir="${build.classes.dir}"/>
+ </obfuscate>
+ </target>
+
+ For list of available properties check the imported
+ nbproject/build-impl.xml file.
+
+
+ Another way to customize the build is by overriding existing main targets.
+ The targets of interest are:
+
+ -init-macrodef-javac: defines macro for javac compilation
+ -init-macrodef-junit: defines macro for junit execution
+ -init-macrodef-debug: defines macro for class debugging
+ -init-macrodef-java: defines macro for class execution
+ -do-jar: JAR building
+ run: execution of project
+ -javadoc-build: Javadoc generation
+ test-report: JUnit report generation
+
+ An example of overriding the target for project execution could look like this:
+
+ <target name="run" depends="jjobs-core-impl.jar">
+ <exec dir="bin" executable="launcher.exe">
+ <arg file="${dist.jar}"/>
+ </exec>
+ </target>
+
+ Notice that the overridden target depends on the jar target and not only on
+ the compile target as the regular run target does. Again, for a list of available
+ properties which you can use, check the target you are overriding in the
+ nbproject/build-impl.xml file.
+
+ -->
+</project>
- cleanup
-->
-<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="addressbook-core-impl">
+<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="jjobs-core-impl">
<fail message="Please build using Ant 1.8.0 or higher.">
<condition>
<not>
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
- <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="addressbook-core" testname="TestNG tests" workingDir="${work.dir}">
+ <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="jjobs-core" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
<isset property="test.method"/>
</condition>
- <condition else="-suitename addressbook-core -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
+ <condition else="-suitename jjobs-core -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<matches pattern=".*\.xml" string="@{testClass}"/>
</condition>
<delete dir="${build.test.results.dir}" quiet="true"/>
<delete file="${built-jar.properties}" quiet="true"/>
</target>
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
- <echo level="warn" message="Cycle detected: addressbook-core was already built"/>
+ <echo level="warn" message="Cycle detected: jjobs-core was already built"/>
</target>
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
<mkdir dir="${build.dir}"/>
<delete file="${built-clean.properties}" quiet="true"/>
</target>
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
- <echo level="warn" message="Cycle detected: addressbook-core was already built"/>
+ <echo level="warn" message="Cycle detected: jjobs-core was already built"/>
</target>
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
<mkdir dir="${build.dir}"/>
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-application.title=addressbook-core
+application.title=jjobs-core
application.vendor=rhaeder
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
build.classes.dir=${build.dir}/classes
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
-dist.jar=${dist.dir}/addressbook-core.jar
+dist.jar=${dist.dir}/jjobs-core.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
javadoc.splitindex=true
javadoc.use=true
javadoc.version=true
-javadoc.windowtitle=Addressbook Core Library
+javadoc.windowtitle=JJobs Core Library
jnlp.codebase.type=no.codebase
jnlp.descriptor=application
jnlp.enabled=false
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
- <name>addressbook-core</name>
+ <name>jjobs-core</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
+++ /dev/null
-/*
- * Copyright (C) 2016 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.database;
-
-import java.text.MessageFormat;
-import java.util.GregorianCalendar;
-import java.util.Objects;
-import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.utils.PhoneUtils;
-
-/**
- * A helper class for beans that access the database.
- * <p>
- * @author Roland Haeder<rhaeder@cho-time.de>
- */
-public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 12_895_410_275_811_963L;
-
- /**
- * Protected constructor
- */
- protected BaseAddressbookDatabaseBean () {
- // Call super constructor
- super();
- }
-
- /**
- * Updates all contacts's phone entry's created timestamps
- * <p>
- * @param contact Contact instance to update
- */
- protected void setAllContactPhoneEntriesCreated (final Contact contact) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesCreated: contact={0} - CALLED!", 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
- DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
- DialableFaxNumber faxNumber = contact.getContactFaxNumber();
- DialableCellphoneNumber cellphoneNumber = contact.getContactCellphoneNumber();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},cellphoneNumber={2}", landLineNumber, faxNumber, cellphoneNumber)); //NOI18N
-
- // Is a phone number instance set?
- if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
-
- // Set updated timestamp
- landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
- }
-
- // Is a fax number instance set?
- if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
-
- // Set updated timestamp
- faxNumber.setPhoneEntryCreated(new GregorianCalendar());
- }
-
- // Is a mobile number instance set?
- if ((cellphoneNumber instanceof DialableCellphoneNumber) && (cellphoneNumber.getPhoneId() == null)) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ..."); //NOI18N
-
- // Set updated timestamp
- cellphoneNumber.setPhoneEntryCreated(new GregorianCalendar());
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesCreated: EXIT!"); //NOI18N
- }
-
- /**
- * Returnes a detached instance from given cellphone instance
- * <p>
- * @param cellphoneNumber Cellphone instance
- * @param fetchedNumber Found cellphone number in database
- * <p>
- * @return Detached instance
- */
- protected DialableCellphoneNumber getDetached (final DialableCellphoneNumber cellphoneNumber, final DialableCellphoneNumber fetchedNumber) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: cellphoneNumber={0},fetchedNumber={1} - CALLED!", cellphoneNumber, fetchedNumber));
-
- // Should be valid
- if (null == cellphoneNumber) {
- // Throw NPE
- throw new NullPointerException("cellphoneNumber is null");
- } else if (fetchedNumber.getPhoneId() == null) {
- // ..and again
- throw new NullPointerException("fetchedNumber.phoneId is null");
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId()));
-
- // Init query instance
- DialableCellphoneNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber));
-
- // Default is null
- DialableCellphoneNumber detachedNumber = null;
-
- // Is there a difference?
- if (!PhoneUtils.isSameCellphoneNumber(cellphoneNumber, fetchedNumber)) {
- // Merge this entry
- detachedNumber = this.getEntityManager().merge(foundNumber);
-
- // Copy all
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber));
-
- // Return it
- return detachedNumber;
- }
-
- /**
- * Returnes a detached instance from given land-line instance
- * <p>
- * @param landLineNumber Land-line instance
- * @param fetchedNumber Found land-line number in database
- * <p>
- * @return Detached instance
- */
- protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber));
-
- // Should be valid
- if (null == landLineNumber) {
- // Throw NPE
- throw new NullPointerException("landLineNumber is null");
- } else if (fetchedNumber.getPhoneId() == null) {
- // ..and again
- throw new NullPointerException("landLineNumber.phoneId is null");
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId()));
-
- // Init query instance
- DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber));
-
- // Default is null
- DialableLandLineNumber detachedNumber = null;
-
- // Is there a difference?
- if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
- // Merge this entry
- detachedNumber = this.getEntityManager().merge(foundNumber);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber));
-
- // Return it
- return detachedNumber;
- }
-
- /**
- * Returnes a detached instance from given fax instance
- * <p>
- * @param faxNumber Fax instance
- * @param fetchedNumber Found fax number in database
- * <p>
- * @return Detached instance
- */
- protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber));
-
- // Should be valid
- if (null == faxNumber) {
- // Throw NPE
- throw new NullPointerException("faxNumber is null");
- } else if (fetchedNumber.getPhoneId() == null) {
- // ..and again
- throw new NullPointerException("fetchedNumber.phoneId is null");
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId()));
-
- // Init query instance
- DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber));
-
- // Default is null
- DialableFaxNumber detachedNumber = null;
-
- // Is there a difference?
- if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
- // Merge this entry
- detachedNumber = this.getEntityManager().merge(foundNumber);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber));
-
- // Return it
- return detachedNumber;
- }
-
- /**
- * Merges given contact's data
- * <p>
- * @param contact Contact instance to merge
- * <p>
- * @return Detached contact instance
- */
- protected Contact mergeContactData (final Contact contact) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: contact={0} - CALLED!", contact)); //NOI18N
-
- // The contact instance must be valid
- if (null == contact) {
- // Throw NPE again
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- }
-
- // Set updated timestamp
- contact.setContactUpdated(new GregorianCalendar());
-
- // Get contact from it and find it
- Contact foundContact = this.getEntityManager().find(contact.getClass(), contact.getContactId());
-
- // Should be found
- assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
-
- // Merge contact instance
- Contact detachedContact = this.getEntityManager().merge(foundContact);
-
- // Copy all
- detachedContact.copyAll(contact);
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - EXIT!", detachedContact)); //NOI18N
-
- // Return detached contact
- return detachedContact;
- }
-
- /**
- * Merges given (detached) contact's cellphone, land-line and fax numbers
- * <p>
- * @param detachedContact Detached contact instance
- */
- protected void mergeContactsCellphoneLandLineFaxNumbers (final Contact detachedContact) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsCellphoneLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
-
- // The contact instance must be valid
- if (null == detachedContact) {
- // Throw NPE again
- throw new NullPointerException("detachedContact is null"); //NOI18N
- } else if (detachedContact.getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
- } else if (detachedContact.getContactId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
- }
-
- // Get all instances
- DialableCellphoneNumber cellphone = detachedContact.getContactCellphoneNumber();
- DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
- DialableFaxNumber fax = detachedContact.getContactFaxNumber();
-
- // Is there a cellphone instance set?
- if (cellphone instanceof DialableCellphoneNumber) {
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
-
- // Then find it, too
- DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
-
- // Should be there
- assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId()); //NOI18N
-
- // Then merge it, too
- DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone);
-
- // Should be there
- assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId()); //NOI18N
-
- // Copy all
- detachedCellphone.copyAll(detachedContact.getContactCellphoneNumber());
-
- // Set it back
- detachedContact.setContactCellphoneNumber(detachedCellphone);
- }
-
- // Is there a fax instance set?
- if (fax instanceof DialableFaxNumber) {
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
-
- // Then find it, too
- DialableFaxNumber foundFax = this.getEntityManager().find(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
-
- // Copy all
- detachedFax.copyAll(detachedContact.getContactFaxNumber());
-
- // Set it back
- detachedContact.setContactFaxNumber(detachedFax);
- }
-
- // Is there a fax instance set?
- if (landLine instanceof DialableLandLineNumber) {
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
-
- // Then find it, too
- 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());
-
- // Set it back
- detachedContact.setContactLandLineNumber(detachedLandLine);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace("mergeContactsCellphoneLandLineFaxNumbers: EXIT!"); //NOI18N
- }
-
- /**
- * Updates all contact's phone instances from other contact, both contacts
- * should be the same.
- * <p>
- * @param contact Contact to set instances
- * @param other Other contact to get instances from
- */
- protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N
-
- // Both must be the same and not null
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (null == other) {
- // Throw NPE
- throw new NullPointerException("other is null"); //NOI18N
- } else if (!Objects.equals(contact, other)) {
- // Not same instances
- throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactCellphoneNumber={0}", other.getContactCellphoneNumber())); //NOI18N
-
- // Is other cellphone not set?
- if ((other.getContactCellphoneNumber() == null) || (PhoneUtils.isSameCellphoneNumber(contact.getContactCellphoneNumber(), other.getContactCellphoneNumber()))) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying cellphone entry ..."); //NOI18N
-
- // Is the fax number set?
- if (other.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
- // Copy cellphone number
- contact.setContactCellphoneNumber(this.getDetached(other.getContactCellphoneNumber(), contact.getContactCellphoneNumber()));
- } else {
- // Null it
- contact.setContactCellphoneNumber(null);
- }
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
-
- // Is other cellphone not set?
- if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N
-
- // Is the land-line number set?
- if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
- // Copy land-line number
- contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
- } else {
- // Null it
- contact.setContactLandLineNumber(null);
- }
- }
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N
-
- // Is other cellphone not set?
- if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N
-
- // Is the fax number set?
- if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
- // Copy fax number
- contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
- } else {
- // Null it
- contact.setContactFaxNumber(null);
- }
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N
- }
-
- /**
- * Updates all contacts's phone entry's updated timestamps
- * <p>
- * @param contact Contact instance to update
- * @param isCellphoneUnlinked Whether a cellphone entry has been unlinked in
- * contact instance
- * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
- * contact instance
- * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
- * instance
- */
- protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isCellphoneUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isCellphoneUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isCellphoneUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
-
- // The contact instance must be valid
- if (null == contact) {
- // Throw NPE again
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- }
-
- // Get all phone instances
- DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
- DialableFaxNumber faxNumber = contact.getContactFaxNumber();
- DialableCellphoneNumber cellphoneNumber = contact.getContactCellphoneNumber();
-
- // Flags and instances must be constistent
- if (isCellphoneUnlinked && cellphoneNumber instanceof DialableCellphoneNumber) {
- // Bad state
- throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but cellphoneNumber is set."); //NOI18N
- } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
- // Bad state
- throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
- } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
- // Bad state
- throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
- }
-
- // Is a phone number instance set?
- if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N
-
- // Set updated timestamp
- landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
- }
-
- // Is a fax number instance set?
- if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N
-
- // Set updated timestamp
- faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
- }
-
- // Is a mobile number instance set?
- if ((cellphoneNumber instanceof DialableCellphoneNumber) && (cellphoneNumber.getPhoneId() instanceof Long) && (cellphoneNumber.getPhoneId() > 0)) {
- // Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ..."); //NOI18N
-
- // Set updated timestamp
- cellphoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.database;
+
+import java.text.MessageFormat;
+import java.util.GregorianCalendar;
+import java.util.Objects;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.utils.PhoneUtils;
+
+/**
+ * A helper class for beans that access the database.
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 12_895_410_275_811_963L;
+
+ /**
+ * Protected constructor
+ */
+ protected BaseJobsDatabaseBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Updates all contacts's phone entry's created timestamps
+ * <p>
+ * @param contact Contact instance to update
+ */
+ protected void setAllContactPhoneEntriesCreated (final Contact contact) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesCreated: contact={0} - CALLED!", 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
+ DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
+ DialableFaxNumber faxNumber = contact.getContactFaxNumber();
+ DialableCellphoneNumber cellphoneNumber = contact.getContactCellphoneNumber();
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},cellphoneNumber={2}", landLineNumber, faxNumber, cellphoneNumber)); //NOI18N
+
+ // Is a phone number instance set?
+ if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
+
+ // Set updated timestamp
+ landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
+ }
+
+ // Is a fax number instance set?
+ if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
+
+ // Set updated timestamp
+ faxNumber.setPhoneEntryCreated(new GregorianCalendar());
+ }
+
+ // Is a mobile number instance set?
+ if ((cellphoneNumber instanceof DialableCellphoneNumber) && (cellphoneNumber.getPhoneId() == null)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ..."); //NOI18N
+
+ // Set updated timestamp
+ cellphoneNumber.setPhoneEntryCreated(new GregorianCalendar());
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesCreated: EXIT!"); //NOI18N
+ }
+
+ /**
+ * Returnes a detached instance from given cellphone instance
+ * <p>
+ * @param cellphoneNumber Cellphone instance
+ * @param fetchedNumber Found cellphone number in database
+ * <p>
+ * @return Detached instance
+ */
+ protected DialableCellphoneNumber getDetached (final DialableCellphoneNumber cellphoneNumber, final DialableCellphoneNumber fetchedNumber) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: cellphoneNumber={0},fetchedNumber={1} - CALLED!", cellphoneNumber, fetchedNumber));
+
+ // Should be valid
+ if (null == cellphoneNumber) {
+ // Throw NPE
+ throw new NullPointerException("cellphoneNumber is null");
+ } else if (fetchedNumber.getPhoneId() == null) {
+ // ..and again
+ throw new NullPointerException("fetchedNumber.phoneId is null");
+ }
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId()));
+
+ // Init query instance
+ DialableCellphoneNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber));
+
+ // Default is null
+ DialableCellphoneNumber detachedNumber = null;
+
+ // Is there a difference?
+ if (!PhoneUtils.isSameCellphoneNumber(cellphoneNumber, fetchedNumber)) {
+ // Merge this entry
+ detachedNumber = this.getEntityManager().merge(foundNumber);
+
+ // Copy all
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber));
+
+ // Return it
+ return detachedNumber;
+ }
+
+ /**
+ * Returnes a detached instance from given land-line instance
+ * <p>
+ * @param landLineNumber Land-line instance
+ * @param fetchedNumber Found land-line number in database
+ * <p>
+ * @return Detached instance
+ */
+ protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber));
+
+ // Should be valid
+ if (null == landLineNumber) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber is null");
+ } else if (fetchedNumber.getPhoneId() == null) {
+ // ..and again
+ throw new NullPointerException("landLineNumber.phoneId is null");
+ }
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId()));
+
+ // Init query instance
+ DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber));
+
+ // Default is null
+ DialableLandLineNumber detachedNumber = null;
+
+ // Is there a difference?
+ if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
+ // Merge this entry
+ detachedNumber = this.getEntityManager().merge(foundNumber);
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber));
+
+ // Return it
+ return detachedNumber;
+ }
+
+ /**
+ * Returnes a detached instance from given fax instance
+ * <p>
+ * @param faxNumber Fax instance
+ * @param fetchedNumber Found fax number in database
+ * <p>
+ * @return Detached instance
+ */
+ protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber));
+
+ // Should be valid
+ if (null == faxNumber) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber is null");
+ } else if (fetchedNumber.getPhoneId() == null) {
+ // ..and again
+ throw new NullPointerException("fetchedNumber.phoneId is null");
+ }
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId()));
+
+ // Init query instance
+ DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber));
+
+ // Default is null
+ DialableFaxNumber detachedNumber = null;
+
+ // Is there a difference?
+ if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
+ // Merge this entry
+ detachedNumber = this.getEntityManager().merge(foundNumber);
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber));
+
+ // Return it
+ return detachedNumber;
+ }
+
+ /**
+ * Merges given contact's data
+ * <p>
+ * @param contact Contact instance to merge
+ * <p>
+ * @return Detached contact instance
+ */
+ protected Contact mergeContactData (final Contact contact) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: contact={0} - CALLED!", contact)); //NOI18N
+
+ // The contact instance must be valid
+ if (null == contact) {
+ // Throw NPE again
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ }
+
+ // Set updated timestamp
+ contact.setContactUpdated(new GregorianCalendar());
+
+ // Get contact from it and find it
+ Contact foundContact = this.getEntityManager().find(contact.getClass(), contact.getContactId());
+
+ // Should be found
+ assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.getContactId()); //NOI18N
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
+
+ // Merge contact instance
+ Contact detachedContact = this.getEntityManager().merge(foundContact);
+
+ // Copy all
+ detachedContact.copyAll(contact);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - EXIT!", detachedContact)); //NOI18N
+
+ // Return detached contact
+ return detachedContact;
+ }
+
+ /**
+ * Merges given (detached) contact's cellphone, land-line and fax numbers
+ * <p>
+ * @param detachedContact Detached contact instance
+ */
+ protected void mergeContactsCellphoneLandLineFaxNumbers (final Contact detachedContact) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsCellphoneLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
+
+ // The contact instance must be valid
+ if (null == detachedContact) {
+ // Throw NPE again
+ throw new NullPointerException("detachedContact is null"); //NOI18N
+ } else if (detachedContact.getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
+ } else if (detachedContact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
+ }
+
+ // Get all instances
+ DialableCellphoneNumber cellphone = detachedContact.getContactCellphoneNumber();
+ DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
+ DialableFaxNumber fax = detachedContact.getContactFaxNumber();
+
+ // Is there a cellphone instance set?
+ if (cellphone instanceof DialableCellphoneNumber) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
+
+ // Then find it, too
+ DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
+
+ // Should be there
+ assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId()); //NOI18N
+
+ // Then merge it, too
+ DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone);
+
+ // Should be there
+ assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId()); //NOI18N
+
+ // Copy all
+ detachedCellphone.copyAll(detachedContact.getContactCellphoneNumber());
+
+ // Set it back
+ detachedContact.setContactCellphoneNumber(detachedCellphone);
+ }
+
+ // Is there a fax instance set?
+ if (fax instanceof DialableFaxNumber) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
+
+ // Then find it, too
+ DialableFaxNumber foundFax = this.getEntityManager().find(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
+
+ // Copy all
+ detachedFax.copyAll(detachedContact.getContactFaxNumber());
+
+ // Set it back
+ detachedContact.setContactFaxNumber(detachedFax);
+ }
+
+ // Is there a fax instance set?
+ if (landLine instanceof DialableLandLineNumber) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
+
+ // Then find it, too
+ 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());
+
+ // Set it back
+ detachedContact.setContactLandLineNumber(detachedLandLine);
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("mergeContactsCellphoneLandLineFaxNumbers: EXIT!"); //NOI18N
+ }
+
+ /**
+ * Updates all contact's phone instances from other contact, both contacts
+ * should be the same.
+ * <p>
+ * @param contact Contact to set instances
+ * @param other Other contact to get instances from
+ */
+ protected void setAllContactPhoneEntries (final Contact contact, final Contact other) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N
+
+ // Both must be the same and not null
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (null == other) {
+ // Throw NPE
+ throw new NullPointerException("other is null"); //NOI18N
+ } else if (!Objects.equals(contact, other)) {
+ // Not same instances
+ throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N
+ }
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactCellphoneNumber={0}", other.getContactCellphoneNumber())); //NOI18N
+
+ // Is other cellphone not set?
+ if ((other.getContactCellphoneNumber() == null) || (PhoneUtils.isSameCellphoneNumber(contact.getContactCellphoneNumber(), other.getContactCellphoneNumber()))) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying cellphone entry ..."); //NOI18N
+
+ // Is the fax number set?
+ if (other.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
+ // Copy cellphone number
+ contact.setContactCellphoneNumber(this.getDetached(other.getContactCellphoneNumber(), contact.getContactCellphoneNumber()));
+ } else {
+ // Null it
+ contact.setContactCellphoneNumber(null);
+ }
+ }
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
+
+ // Is other cellphone not set?
+ if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N
+
+ // Is the land-line number set?
+ if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // Copy land-line number
+ contact.setContactLandLineNumber(this.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
+ } else {
+ // Null it
+ contact.setContactLandLineNumber(null);
+ }
+ }
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N
+
+ // Is other cellphone not set?
+ if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N
+
+ // Is the fax number set?
+ if (other.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // Copy fax number
+ contact.setContactFaxNumber(this.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
+ } else {
+ // Null it
+ contact.setContactFaxNumber(null);
+ }
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N
+ }
+
+ /**
+ * Updates all contacts's phone entry's updated timestamps
+ * <p>
+ * @param contact Contact instance to update
+ * @param isCellphoneUnlinked Whether a cellphone entry has been unlinked in
+ * contact instance
+ * @param isLandlineUnlinked Whether a land-line entry has been unlinked in
+ * contact instance
+ * @param isFaxUnlinked Whether a fax entry has been unlinked in contact
+ * instance
+ */
+ protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isCellphoneUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isCellphoneUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isCellphoneUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
+
+ // The contact instance must be valid
+ if (null == contact) {
+ // Throw NPE again
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ }
+
+ // Get all phone instances
+ DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
+ DialableFaxNumber faxNumber = contact.getContactFaxNumber();
+ DialableCellphoneNumber cellphoneNumber = contact.getContactCellphoneNumber();
+
+ // Flags and instances must be constistent
+ if (isCellphoneUnlinked && cellphoneNumber instanceof DialableCellphoneNumber) {
+ // Bad state
+ throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but cellphoneNumber is set."); //NOI18N
+ } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) {
+ // Bad state
+ throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N
+ } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) {
+ // Bad state
+ throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N
+ }
+
+ // Is a phone number instance set?
+ if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N
+
+ // Set updated timestamp
+ landLineNumber.setPhoneEntryUpdated(new GregorianCalendar());
+ }
+
+ // Is a fax number instance set?
+ if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N
+
+ // Set updated timestamp
+ faxNumber.setPhoneEntryUpdated(new GregorianCalendar());
+ }
+
+ // Is a mobile number instance set?
+ if ((cellphoneNumber instanceof DialableCellphoneNumber) && (cellphoneNumber.getPhoneId() instanceof Long) && (cellphoneNumber.getPhoneId() > 0)) {
+ // Debug message
+ this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ..."); //NOI18N
+
+ // Set updated timestamp
+ cellphoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N
+ }
+
+}