]> git.mxchange.org Git - pizzaservice-mailer-ejb.git/commitdiff
Continued a bit:
authorRoland Haeder <roland@mxchange.org>
Sun, 17 Apr 2016 10:38:39 +0000 (12:38 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 17 Apr 2016 10:39:15 +0000 (12:39 +0200)
- added session bean for handling phone number lookups, maybe it will be used for user-depending purposes later on. So maybe session-scoped is not a bad idea after all.
- updated jar(s)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jphone/phonenumbers/phone/PizzaPhoneSessionBean.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/jphone/phonenumbers/phone/PizzaPhoneSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/phone/PizzaPhoneSessionBean.java
new file mode 100644 (file)
index 0000000..b903705
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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 javax.ejb.Stateless;
+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;
+
+/**
+ * A general phone EJB
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "phone", mappedName = "ejb/stateless-pizza-phone", description = "A bean handling phone data")
+public class PizzaPhoneSessionBean extends BaseDatabaseBean implements PhoneSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 134_945_698_127_601L;
+
+       /**
+        * Default constructor
+        */
+       public PizzaPhoneSessionBean () {
+       }
+
+       @Override
+       public DialableCellphoneNumber findCellphoneById (final Long cellphoneId) throws PhoneEntityNotFoundException {
+               // 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);
+               }
+
+               // Return found instance
+               return cellphone;
+       }
+
+}