From: Roland Haeder Date: Mon, 12 Oct 2015 17:03:28 +0000 (+0200) Subject: added new business method X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e6473b67805a82583587bc55167c74d131823a5e;p=jfinancials-mailer-ejb.git added new business method --- diff --git a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java index 4edacc2..ef6472b 100644 --- a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java +++ b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java @@ -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 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 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