From: Roland Häder Date: Tue, 26 Apr 2016 13:43:32 +0000 (+0200) Subject: No more fancy stuff in EJBs, like auto-linking, straight ahead only adding non-existi... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=48acf779eee43d303ac382609f382fba91fa6e01;p=pizzaservice-ejb.git No more fancy stuff in EJBs, like auto-linking, straight ahead only adding non-existing, else a checked exception is thrown. --- diff --git a/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java index 70ebcb3..511be1e 100644 --- a/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java @@ -17,7 +17,6 @@ package org.mxchange.pizzaapplication.model.customer; import java.text.MessageFormat; -import java.util.GregorianCalendar; import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; @@ -25,6 +24,7 @@ import javax.persistence.NoResultException; import javax.persistence.Query; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException; import org.mxchange.jcustomercore.model.customer.Customer; import org.mxchange.jcustomercore.utils.CustomerUtils; @@ -56,7 +56,7 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme private RateCalcCustomerSessionBeanRemote customerBean; @Override - public Customer addCustomer (final Customer customer) throws CustomerAlreadyRegisteredException { + public Customer addCustomer (final Customer customer) throws CustomerAlreadyRegisteredException, ContactAlreadyAddedException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("addCustomer: customer={0} - CALLED!", customer)); //NOI18N @@ -90,28 +90,12 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme // Is a customer found? if (updatedContact instanceof Contact) { - // Set all entries - contact.setContactId(updatedContact.getContactId()); - this.setAllContactPhoneEntries(updatedContact, contact); - - // Yes, then get updated version - updatedContact = this.contactBean.updateContactData(contact); - - // Remove it from customer so it won't get persisted again - customer.setCustomerContact(null); + // Don't double-create + throw new ContactAlreadyAddedException(contact); } - // Set created timestamp(s) - customer.setCustomerCreated(new GregorianCalendar()); - - // No conrtact was found? - if (null == updatedContact) { - // Set created in contact, too - contact.setContactCreated(new GregorianCalendar()); - - // Set all "created" timestamps - this.setAllContactPhoneEntriesCreated(contact); - } + // Set all "created" timestamps + this.setAllContactPhoneEntriesCreated(contact); // Persist the customer this.getEntityManager().persist(customer); @@ -119,12 +103,6 @@ public class PizzaAdminCustomerSessionBean extends BasePizzaDatabaseBean impleme // Flush it to get id number set this.getEntityManager().flush(); - // Has the contact being updated? - if (updatedContact instanceof Contact) { - // Set it again - customer.setCustomerContact(updatedContact); - } - // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("addCustomer: customer.customerId={0} - EXIT!", customer.getCustomerId())); //NOI18N