]> git.mxchange.org Git - pizzaservice-mailer-ejb.git/commitdiff
added new business method
authorRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 17:03:28 +0000 (19:03 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 17:03:28 +0000 (19:03 +0200)
src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java

index 4edacc20eede9b7179d215fbc0d501bc4f8f0d41..ef6472b2a9cabd6457daae22cf5a3e43a43f04af 100644 (file)
@@ -22,6 +22,7 @@ import javax.ejb.Stateless;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jusercore.model.user.User;
 
@@ -38,16 +39,31 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb
         */
        private static final long serialVersionUID = 129_857_871_287_691L;
 
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<AddressbookEntry> allEntries (final Addressbook addressbook) {
+               // Generate query
+               Query query = this.getEntityManager().createNamedQuery("AllAddressbookEntries"); //NOI18N
+
+               // Set parameters
+               query.setParameter("addressbook", addressbook); //NOI18N
+               query.setParameter("owner", addressbook.getAddressbookUser()); //NOI18N
+               query.setParameter("sharer", addressbook.getAddressbookUser()); //NOI18N
+
+               // Return it
+               return query.getResultList();
+       }
+
        @Override
        @SuppressWarnings ("unchecked")
        public List<Addressbook> getUsersList (final User loggedInUser) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser));
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N
 
                // Is the user instance null?
                if (null == loggedInUser) {
                        // Abort here
-                       throw new NullPointerException("loggedInUser is null");
+                       throw new NullPointerException("loggedInUser is null"); //NOI18N
                }
 
                // Get query instance
@@ -111,11 +127,11 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb
                }
 
                // Get query instance
-               Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class);
+               Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class); //NOI18N
 
                // Set parameter
-               query.setParameter("user", addressbook.getAddressbookUser());
-               query.setParameter("name", addressbook.getAddressbookName());
+               query.setParameter("user", addressbook.getAddressbookUser()); //NOI18N
+               query.setParameter("name", addressbook.getAddressbookName()); //NOI18N
 
                // Default is not found
                boolean isUsed = false;
@@ -126,13 +142,13 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb
                        Addressbook dummy = (Addressbook) query.getSingleResult();
 
                        // Log it
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy));
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy)); //NOI18N
 
                        // Found one
                        isUsed = true;
                } catch (final NoResultException ex) {
                        // No result found, so log it away
-                       this.getLoggerBeanLocal().logDebug("isAddressbookNameUsed: getSingleResult() did not return a result: " + ex);
+                       this.getLoggerBeanLocal().logDebug("isAddressbookNameUsed: getSingleResult() did not return a result: " + ex); //NOI18N
                }
 
                // Return result