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.jphone.phonenumbers.phone;
19 import java.text.MessageFormat;
20 import javax.ejb.Stateless;
21 import javax.persistence.NoResultException;
22 import javax.persistence.Query;
23 import org.mxchange.jcoreee.database.BaseDatabaseBean;
24 import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;
25 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
26 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
31 * @author Roland Haeder<roland@mxchange.org>
33 @Stateless (name = "phone", mappedName = "ejb/stateless-pizza-phone", description = "A bean handling phone data")
34 public class PizzaPhoneSessionBean extends BaseDatabaseBean implements PhoneSessionBeanRemote {
39 private static final long serialVersionUID = 134_945_698_127_601L;
44 public PizzaPhoneSessionBean () {
48 public DialableCellphoneNumber findCellphoneById (final Long cellphoneId) throws PhoneEntityNotFoundException {
50 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findCellphoneById: cellphoneId={0} - CALLED!", cellphoneId)); //NOI18N
52 // The id number should be valid
53 if (null == cellphoneId) {
55 throw new NullPointerException("cellphoneId is null"); //NOI18N
56 } else if (cellphoneId < 1) {
58 throw new IllegalArgumentException(MessageFormat.format("cellphoneId={0} is not valid.", cellphoneId)); //NOI18N
62 Query query = this.getEntityManager().createNamedQuery("SearchCellphoneId", CellphoneNumber.class); //NOI18N
65 query.setParameter("cellphoneId", cellphoneId); //NOI18N
68 DialableCellphoneNumber cellphone = null;
70 // Try to get a result
72 // Get a single result
73 cellphone = (DialableCellphoneNumber) query.getSingleResult();
74 } catch (NoResultException ex) {
75 // The entry was not found, so throw it again
76 throw new PhoneEntityNotFoundException(cellphoneId, ex);
80 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findCellphoneById: cellphone={0} - EXIT!", cellphone)); //NOI18N
82 // Return found instance