]> git.mxchange.org Git - jfinancials-mailer-ejb.git/commitdiff
Implemented business method ifUserNameExists()
authorRoland Häder <roland@mxchange.org>
Thu, 21 Apr 2016 13:50:55 +0000 (15:50 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 21 Apr 2016 18:26:39 +0000 (20:26 +0200)
src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java

index a4b903b28f0b8ac5f7acc9b9f668ddc150404351..cb012dc9c3db42b61150844e34f536796c2cb80e 100644 (file)
@@ -380,6 +380,47 @@ public class AddressbookUserSessionBean extends BaseDatabaseBean implements User
                return true;
        }
 
+       @Override
+       public boolean ifUserNameExists (final String userName) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserNameExists: userName={0} - CALLED!", userName)); //NOI18N
+
+               // userId should not be null
+               if (null == userName) {
+                       // Abort here
+                       throw new NullPointerException("userName is null"); //NOI18N
+               } else if (userName.isEmpty()) {
+                       // Abort here
+                       throw new NullPointerException("userName is empty"); //NOI18N
+               }
+
+               // Generate query
+               Query query = this.getEntityManager().createNamedQuery("SearchUserName", LoginUser.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("param", userName); //NOI18N
+
+               // Try this
+               try {
+                       User dummy = (User) query.getSingleResult();
+
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserNameExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
+               } catch (final NoResultException ex) {
+                       // Log it
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserNameExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
+
+                       // User name does not exist
+                       return false;
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserNameExists: Found user name {0} - EXIT!", userName)); //NOI18N
+
+               // Found it
+               return true;
+       }
+
        @Override
        public boolean isEmailAddressReqistered (final User user) {
                // Trace message