From 514fcc5585e4b0eddeae821c4bf540bf0f602bf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 6 Jun 2016 14:13:15 +0200 Subject: [PATCH] implemented addContact() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../contact/PizzaContactSessionBean.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/java/org/mxchange/jcontacts/contact/PizzaContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/PizzaContactSessionBean.java index 29b765a..a7dc1b7 100644 --- a/src/java/org/mxchange/jcontacts/contact/PizzaContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/contact/PizzaContactSessionBean.java @@ -49,34 +49,34 @@ public class PizzaContactSessionBean extends BasePizzaDatabaseBean implements Co @Override public Contact addContact (final Contact contact) throws ContactAlreadyAddedException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("addContact: contact={0} - CALLED!", contact)); //NOI18N + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("addContact: contact={0} - CALLED!", contact)); - // The contact instance must be valid + // Is the instance set? if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() instanceof Long) { - // Throw NPE again - throw new NullPointerException("contact.contactId is not null"); //NOI18N //NOI18N - } else if (this.lookupContact(contact) instanceof Contact) { - // Already found - throw new ContactAlreadyAddedException(contact); + // Throw NPE + throw new NullPointerException("contact is null"); + } else if (contact.getContactId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId())); } // Set created timestamp contact.setContactCreated(new GregorianCalendar()); - // Set all created timestamps in cellphone, land-line and fax number(s) + // Set all created timestamps, if instance is there this.setAllContactPhoneEntriesCreated(contact); // Persist it this.getEntityManager().persist(contact); - // Flush it + // Flush it to get contactId set this.getEntityManager().flush(); - // Return updated instance + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("addContact: contact.contactId={0} after persisting - EXIT!", contact.getContactId())); + + // Return it return contact; } -- 2.39.5