From d121d54394210b89dec1aa692ead4a5f677f5a91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 25 Jun 2017 20:32:08 +0200 Subject: [PATCH] Please cherry-pick: - always rely on "cached" lists rather than calling EJB for each request MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../AddressbookEmailAddressValidator.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java index 8ab45b86..4b8c1176 100644 --- a/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java +++ b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java @@ -17,6 +17,7 @@ package org.mxchange.addressbook.validator.emailaddress; import java.text.MessageFormat; +import java.util.List; import java.util.regex.Pattern; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; @@ -49,6 +50,11 @@ public class AddressbookEmailAddressValidator extends BaseStringValidator implem */ private ContactSessionBeanRemote contactBean; + /** + * Cached list of all email addresses + */ + private List emailAddresses; + /** * Default constructor */ @@ -90,6 +96,9 @@ public class AddressbookEmailAddressValidator extends BaseStringValidator implem // Try to lookup this.contactBean = (ContactSessionBeanRemote) initialContext.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + + // Get whole list of email addresses + this.emailAddresses = this.contactBean.getEmailAddressList(); } catch (final NamingException ex) { // Continue to throw it throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N @@ -101,13 +110,13 @@ public class AddressbookEmailAddressValidator extends BaseStringValidator implem String clientId = component.getClientId(); // Is the email address already registered? - if ((!clientId.endsWith("resendEmailAddress")) && (this.contactBean.isEmailAddressRegistered(emailAddress))) { //NOI18N + if ((!clientId.endsWith("resendEmailAddress")) && (this.emailAddresses.contains(emailAddress))) { //NOI18N // Generate message String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N // No, then abort here throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); - } else if ((clientId.endsWith("resendEmailAddress")) && (!this.contactBean.isEmailAddressRegistered(emailAddress))) { //NOI18N + } else if ((clientId.endsWith("resendEmailAddress")) && (!this.emailAddresses.contains(emailAddress))) { //NOI18N // Generate message String message = MessageFormat.format("Email address {0} is not registered.", emailAddress); //NOI18N -- 2.39.5