+++ /dev/null
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jphone.phonenumbers.phone;
-
-import java.text.MessageFormat;
-import java.util.List;
-import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
-import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;
-import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
-
-/**
- * A general phone EJB
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "phone", description = "A bean handling phone data")
-public class AddressbookPhoneSessionBean extends BaseAddressbookDatabaseBean implements PhoneSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 134_945_698_127_601L;
-
- /**
- * Default constructor
- */
- public AddressbookPhoneSessionBean () {
- // Call super constructor
- super();
- }
-
- @SuppressWarnings ("unchecked")
- @Override
- public List<DialableFaxNumber> allFaxNumbers () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get query
- Query query = this.getEntityManager().createNamedQuery("AllFaxNumbers", FaxNumber.class); //NOI18N
-
- // Get list from it
- List<DialableFaxNumber> list = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
-
- // Return it
- return list;
- }
-
- @SuppressWarnings ("unchecked")
- @Override
- public List<DialableLandLineNumber> allLandLineNumbers () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get query
- Query query = this.getEntityManager().createNamedQuery("AllLandLineNumbers", LandLineNumber.class); //NOI18N
-
- // Get list from it
- List<DialableLandLineNumber> list = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
-
- // Return it
- return list;
- }
-
- @SuppressWarnings ("unchecked")
- @Override
- public List<DialableMobileNumber> allMobileNumbers () {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Get query
- Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N
-
- // Get list from it
- List<DialableMobileNumber> list = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
-
- // Return it
- return list;
- }
-
- @Override
- public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), faxNumberId)); //NOI18N
-
- // The id number should be valid
- if (null == faxNumberId) {
- // Throw NPE
- throw new NullPointerException("faxNumberId is null"); //NOI18N
- } else if (faxNumberId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("faxNumberId={0} is not valid.", faxNumberId)); //NOI18N
- }
-
- // Now find it
- Query query = this.getEntityManager().createNamedQuery("SearchFaxNumberId", FaxNumber.class); //NOI18N
-
- // Set parameter
- query.setParameter("faxNumberId", faxNumberId); //NOI18N
-
- // Init instance
- DialableFaxNumber faxNumber = null;
-
- // Try to get a result
- try {
- // Get a single result
- faxNumber = (DialableFaxNumber) query.getSingleResult();
- } catch (NoResultException ex) {
- // The entry was not found, so throw it again
- throw new PhoneEntityNotFoundException(faxNumberId, ex);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N
-
- // Return found instance
- return faxNumber;
- }
-
- @Override
- public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), landLineNumberId)); //NOI18N
-
- // The id number should be valid
- if (null == landLineNumberId) {
- // Throw NPE
- throw new NullPointerException("landLineNumberId is null"); //NOI18N
- } else if (landLineNumberId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is not valid.", landLineNumberId)); //NOI18N
- }
-
- // Now find it
- Query query = this.getEntityManager().createNamedQuery("SearchLandLineNumberId", LandLineNumber.class); //NOI18N
-
- // Set parameter
- query.setParameter("landLineNumberId", landLineNumberId); //NOI18N
-
- // Init instance
- DialableLandLineNumber landLineNumber = null;
-
- // Try to get a result
- try {
- // Get a single result
- landLineNumber = (DialableLandLineNumber) query.getSingleResult();
- } catch (NoResultException ex) {
- // The entry was not found, so throw it again
- throw new PhoneEntityNotFoundException(landLineNumberId, ex);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N
-
- // Return found instance
- return landLineNumber;
- }
-
- @Override
- public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), mobileNumberId)); //NOI18N
-
- // The id number should be valid
- if (null == mobileNumberId) {
- // Throw NPE
- throw new NullPointerException("mobileNumberId is null"); //NOI18N
- } else if (mobileNumberId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is not valid.", mobileNumberId)); //NOI18N
- }
-
- // Now find it
- Query query = this.getEntityManager().createNamedQuery("SearchMobileNumberId", MobileNumber.class); //NOI18N
-
- // Set parameter
- query.setParameter("mobileNumberId", mobileNumberId); //NOI18N
-
- // Init instance
- DialableMobileNumber cellphone = null;
-
- // Try to get a result
- try {
- // Get a single result
- cellphone = (DialableMobileNumber) query.getSingleResult();
- } catch (NoResultException ex) {
- // The entry was not found, so throw it again
- throw new PhoneEntityNotFoundException(mobileNumberId, ex);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), cellphone)); //NOI18N
-
- // Return found instance
- return cellphone;
- }
-
-}