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.jphone.exceptions.PhoneEntityNotFoundException;
24 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
25 import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
30 * @author Roland Haeder<roland@mxchange.org>
32 @Stateless (name = "phone", mappedName = "ejb/stateless-pizza-phone", description = "A bean handling phone data")
33 public class PizzaPhoneSessionBean extends BasePizzaDatabaseBean implements PhoneSessionBeanRemote {
38 private static final long serialVersionUID = 134_945_698_127_601L;
43 public PizzaPhoneSessionBean () {
47 public DialableCellphoneNumber findCellphoneById (final Long cellphoneId) throws PhoneEntityNotFoundException {
49 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findCellphoneById: cellphoneId={0} - CALLED!", cellphoneId)); //NOI18N
51 // The id number should be valid
52 if (null == cellphoneId) {
54 throw new NullPointerException("cellphoneId is null"); //NOI18N
55 } else if (cellphoneId < 1) {
57 throw new IllegalArgumentException(MessageFormat.format("cellphoneId={0} is not valid.", cellphoneId)); //NOI18N
61 Query query = this.getEntityManager().createNamedQuery("SearchCellphoneId", DialableCellphoneNumber.class); //NOI18N
64 query.setParameter("cellphoneId", cellphoneId); //NOI18N
67 DialableCellphoneNumber cellphone = null;
69 // Try to get a result
71 // Get a single result
72 cellphone = (DialableCellphoneNumber) query.getSingleResult();
73 } catch (NoResultException ex) {
74 // The entry was not found, so throw it again
75 throw new PhoneEntityNotFoundException(cellphoneId, ex);
79 this.getLoggerBeanLocal().logTrace(MessageFormat.format("findCellphoneById: cellphone={0} - EXIT!", cellphone)); //NOI18N
81 // Return found instance