]> git.mxchange.org Git - addressbook-mailer-ejb.git/blobdiff - src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java
Please cherry-pick:
[addressbook-mailer-ejb.git] / src / java / org / mxchange / jcontacts / phone / AddressbookAdminContactPhoneSessionBean.java
index a23d9b3e97c1f84d7329f9e18c55aaf1c1ba0f19..7348f3927be1d97d7f437bffc6bd8a84b37d41eb 100644 (file)
@@ -24,6 +24,7 @@ import javax.ejb.Stateless;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.contact.UserContact;
 import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
@@ -93,17 +94,17 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                        throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Set fax number in contact
-               contact.setContactFaxNumber(faxNumber);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Set fax number in contact
+               managedContact.setContactFaxNumber(faxNumber);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -150,17 +151,17 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                        throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Set land-line number in contact
-               contact.setContactLandLineNumber(landLineNumber);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Set landline number in contact
+               managedContact.setContactLandLineNumber(landLineNumber);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -201,17 +202,17 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                        throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
                }
 
-               // Set mobile number in contact
-               contact.setContactMobileNumber(mobileNumber);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Set landline number in contact
+               managedContact.setContactMobileNumber(mobileNumber);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -258,17 +259,20 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                // Set created instance
                faxNumber.setPhoneEntryCreated(new GregorianCalendar());
 
-               // Set fax number in contact
-               contact.setContactFaxNumber(faxNumber);
+               // Persist it
+               this.getEntityManager().persist(faxNumber);
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
+
+               // Set fax number in contact
+               managedContact.setContactFaxNumber(faxNumber);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -315,17 +319,20 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                // Set created instance
                landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
 
-               // Set landLine number in contact
-               contact.setContactLandLineNumber(landLineNumber);
+               // Persist it
+               this.getEntityManager().persist(landLineNumber);
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
+
+               // Set land-line number in contact
+               managedContact.setContactLandLineNumber(landLineNumber);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -366,17 +373,20 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                // Set created instance
                mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
 
-               // Set mobile number in contact
-               contact.setContactMobileNumber(mobileNumber);
+               // Persist it
+               this.getEntityManager().persist(mobileNumber);
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
+
+               // Set land-line number in contact
+               managedContact.setContactMobileNumber(mobileNumber);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -408,17 +418,17 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                        throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} and faxNumber.phoneId={1} are not the same.", contact.getContactFaxNumber().getPhoneId(), faxNumber.getPhoneId())); //NOI18N
                }
 
-               // Remove it from contact
-               contact.setContactFaxNumber(null);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Remove it from contact
+               managedContact.setContactFaxNumber(null);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -450,17 +460,17 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                        throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} and landLineNumber.phoneId={1} are not the same.", contact.getContactLandLineNumber().getPhoneId(), landLineNumber.getPhoneId())); //NOI18N
                }
 
-               // Remove it from contact
-               contact.setContactLandLineNumber(null);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Remove it from contact
+               managedContact.setContactLandLineNumber(null);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
        @Override
@@ -492,17 +502,17 @@ public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookData
                        throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N
                }
 
-               // Remove it from contact
-               contact.setContactMobileNumber(null);
+               // Find contact
+               Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId());
 
-               // Update database
-               Contact updatedContact = this.contactBean.updateContactData(contact);
+               // Remove it from contact
+               managedContact.setContactLandLineNumber(null);
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
-               return updatedContact;
+               return managedContact;
        }
 
 }