X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjphone%2Fphonenumbers%2Fphone%2FAddressbookPhoneSessionBean.java;h=247d4200bf1e23eb85ded4d0827071be6ebff72d;hb=e80ad0d5887655b45603464421805999a24f525e;hp=687cc28be4230553b71abebaf5054dc9a553fe49;hpb=2346998e40a6628e08b14521cb862f6636dc32ec;p=addressbook-ejb.git diff --git a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java index 687cc28..247d420 100644 --- a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java +++ b/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java @@ -23,12 +23,12 @@ import javax.persistence.NoResultException; import javax.persistence.Query; import org.mxchange.jcoreee.database.BaseDatabaseBean; import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; -import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; 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 @@ -49,59 +49,20 @@ public class AddressbookPhoneSessionBean extends BaseDatabaseBean implements Pho public AddressbookPhoneSessionBean () { } - @Override - public DialableCellphoneNumber findCellphoneById (final Long cellphoneId) throws PhoneEntityNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCellphoneById: cellphoneId={1} - CALLED!", this.getClass().getSimpleName(), cellphoneId)); //NOI18N - - // The id number should be valid - if (null == cellphoneId) { - // Throw NPE - throw new NullPointerException("cellphoneId is null"); //NOI18N - } else if (cellphoneId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("cellphoneId={0} is not valid.", cellphoneId)); //NOI18N - } - - // Now find it - Query query = this.getEntityManager().createNamedQuery("SearchCellphoneId", CellphoneNumber.class); //NOI18N - - // Set parameter - query.setParameter("cellphoneId", cellphoneId); //NOI18N - - // Init instance - DialableCellphoneNumber cellphone = null; - - // Try to get a result - try { - // Get a single result - cellphone = (DialableCellphoneNumber) query.getSingleResult(); - } catch (NoResultException ex) { - // The entry was not found, so throw it again - throw new PhoneEntityNotFoundException(cellphoneId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCellphoneById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), cellphone)); //NOI18N - - // Return found instance - return cellphone; - } - @SuppressWarnings ("unchecked") @Override - public List allCellphoneNumbers () { + public List allMobileNumbers () { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCellphoneNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N // Get query - Query query = this.getEntityManager().createNamedQuery("AllCellphoneNumbers", CellphoneNumber.class); //NOI18N + Query query = this.getEntityManager().createNamedQuery("AllCellphoneNumbers", MobileNumber.class); //NOI18N // Get list from it - List list = query.getResultList(); + List list = query.getResultList(); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCellphoneNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N // Return it return list; @@ -145,4 +106,43 @@ public class AddressbookPhoneSessionBean extends BaseDatabaseBean implements Pho return list; } + @Override + public DialableMobileNumber findMobileNumberById (final Long cellphoneId) throws PhoneEntityNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCellphoneById: cellphoneId={1} - CALLED!", this.getClass().getSimpleName(), cellphoneId)); //NOI18N + + // The id number should be valid + if (null == cellphoneId) { + // Throw NPE + throw new NullPointerException("cellphoneId is null"); //NOI18N + } else if (cellphoneId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("cellphoneId={0} is not valid.", cellphoneId)); //NOI18N + } + + // Now find it + Query query = this.getEntityManager().createNamedQuery("SearchCellphoneId", MobileNumber.class); //NOI18N + + // Set parameter + query.setParameter("cellphoneId", cellphoneId); //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(cellphoneId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCellphoneById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), cellphone)); //NOI18N + + // Return found instance + return cellphone; + } + }