2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcontacts.contact;
19 import java.text.MessageFormat;
20 import java.util.List;
21 import javax.ejb.Stateless;
22 import javax.persistence.NoResultException;
23 import javax.persistence.Query;
24 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
25 import org.mxchange.jcoreee.database.BaseDatabaseBean;
30 * @author Roland Haeder<roland@mxchange.org>
32 @Stateless (name = "contact", mappedName = "ejb/stateless-pizza-contact", description = "A bean handling contact data")
33 public class PizzaContactSessionBean extends BaseDatabaseBean implements ContactSessionBeanRemote {
38 private static final long serialVersionUID = 542_145_347_916L;
43 public PizzaContactSessionBean () {
47 public Contact findContactById (final Long contactId) throws ContactNotFoundException {
49 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findContactById: contactId={0} - CALLED!", contactId)); //NOI18N
51 // The parameter must be valid
52 if (null == contactId) {
54 throw new NullPointerException("contactId is null"); //NOI18N
55 } else if (contactId < 1) {
57 throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N
61 Query query = this.getEntityManager().createNamedQuery("SearchContactById", UserContact.class); //NOI18N
64 query.setParameter("contactId", contactId); //NOI18N
66 // Init contact instance
69 // Try to find a result
71 // Find a single result
72 contact = (Contact) query.getSingleResult();
75 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findContactById: Found contact={0}", contact)); //NOI18N
76 } catch (final NoResultException ex) {
78 throw new ContactNotFoundException(contactId, ex);
82 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findContactById: contact={0} - EXIT!", contact)); //NOI18N
84 // Return found instance
89 @SuppressWarnings ("unchecked")
90 public List<Contact> getAllContacts () {
92 this.getLoggerBeanLocal().logTrace("getAllContacts - CALLED!"); //NOI18N
94 // Create query instance
95 Query query = this.getEntityManager().createNamedQuery("AllContacts", List.class); //NOI18N
98 List<Contact> contacts = query.getResultList();
101 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAllContacts: contacts.size()={0} - EXIT!", contacts.size())); //NOI18N
108 @SuppressWarnings ("unchecked")
109 public List<String> getEmailAddressList () {
111 this.getLoggerBeanLocal().logTrace("getEmailAddressList - CALLED!"); //NOI18N
113 // Create query instance
114 Query query = this.getEntityManager().createNamedQuery("AllContactEmailAddresses", List.class); //NOI18N
117 List<String> emailAddresses = query.getResultList();
120 this.getLoggerBeanLocal().logTrace(MessageFormat.format("getEmailAddressList: emailAddresses.size()={0} - EXIT!", emailAddresses.size())); //NOI18N
123 return emailAddresses;
127 public void updateContactPersonalData (final Contact contact) {
128 throw new UnsupportedOperationException("Not supported yet."); //NOI18N