2 * Copyright (C) 2016, 2017 Roland Häder
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.jphone.phonenumbers.phone;
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.addressbook.database.BaseAddressbookDatabaseBean;
25 import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;
26 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
27 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
28 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
29 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
30 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
31 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
36 * @author Roland Häder<roland@mxchange.org>
38 @Stateless (name = "phone", description = "A bean handling phone data")
39 public class AddressbookPhoneSessionBean extends BaseAddressbookDatabaseBean implements PhoneSessionBeanRemote {
44 private static final long serialVersionUID = 134_945_698_127_601L;
49 public AddressbookPhoneSessionBean () {
50 // Call super constructor
54 @SuppressWarnings ("unchecked")
56 public List<DialableFaxNumber> allFaxNumbers () {
58 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
61 Query query = this.getEntityManager().createNamedQuery("AllFaxNumbers", FaxNumber.class); //NOI18N
64 List<DialableFaxNumber> list = query.getResultList();
67 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
73 @SuppressWarnings ("unchecked")
75 public List<DialableLandLineNumber> allLandLineNumbers () {
77 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
80 Query query = this.getEntityManager().createNamedQuery("AllLandLineNumbers", LandLineNumber.class); //NOI18N
83 List<DialableLandLineNumber> list = query.getResultList();
86 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
92 @SuppressWarnings ("unchecked")
94 public List<DialableMobileNumber> allMobileNumbers () {
96 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
99 Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N
102 List<DialableMobileNumber> list = query.getResultList();
105 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
112 public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException {
114 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), faxNumberId)); //NOI18N
116 // The id number should be valid
117 if (null == faxNumberId) {
119 throw new NullPointerException("faxNumberId is null"); //NOI18N
120 } else if (faxNumberId < 1) {
122 throw new IllegalArgumentException(MessageFormat.format("faxNumberId={0} is not valid.", faxNumberId)); //NOI18N
126 Query query = this.getEntityManager().createNamedQuery("SearchFaxNumberId", FaxNumber.class); //NOI18N
129 query.setParameter("faxNumberId", faxNumberId); //NOI18N
132 DialableFaxNumber faxNumber = null;
134 // Try to get a result
136 // Get a single result
137 faxNumber = (DialableFaxNumber) query.getSingleResult();
138 } catch (NoResultException ex) {
139 // The entry was not found, so throw it again
140 throw new PhoneEntityNotFoundException(faxNumberId, ex);
144 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N
146 // Return found instance
151 public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException {
153 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), landLineNumberId)); //NOI18N
155 // The id number should be valid
156 if (null == landLineNumberId) {
158 throw new NullPointerException("landLineNumberId is null"); //NOI18N
159 } else if (landLineNumberId < 1) {
161 throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is not valid.", landLineNumberId)); //NOI18N
165 Query query = this.getEntityManager().createNamedQuery("SearchLandLineNumberId", LandLineNumber.class); //NOI18N
168 query.setParameter("landLineNumberId", landLineNumberId); //NOI18N
171 DialableLandLineNumber landLineNumber = null;
173 // Try to get a result
175 // Get a single result
176 landLineNumber = (DialableLandLineNumber) query.getSingleResult();
177 } catch (NoResultException ex) {
178 // The entry was not found, so throw it again
179 throw new PhoneEntityNotFoundException(landLineNumberId, ex);
183 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N
185 // Return found instance
186 return landLineNumber;
190 public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException {
192 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), mobileNumberId)); //NOI18N
194 // The id number should be valid
195 if (null == mobileNumberId) {
197 throw new NullPointerException("mobileNumberId is null"); //NOI18N
198 } else if (mobileNumberId < 1) {
200 throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is not valid.", mobileNumberId)); //NOI18N
204 Query query = this.getEntityManager().createNamedQuery("SearchMobileNumberId", MobileNumber.class); //NOI18N
207 query.setParameter("mobileNumberId", mobileNumberId); //NOI18N
210 DialableMobileNumber cellphone = null;
212 // Try to get a result
214 // Get a single result
215 cellphone = (DialableMobileNumber) query.getSingleResult();
216 } catch (NoResultException ex) {
217 // The entry was not found, so throw it again
218 throw new PhoneEntityNotFoundException(mobileNumberId, ex);
222 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), cellphone)); //NOI18N
224 // Return found instance