--- /dev/null
+/*
+ * 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.jcontacts.contact;
+
+import java.text.MessageFormat;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+
+/**
+ * A contact EJB
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "contact", mappedName = "ejb/stateless-pizza-contact", description = "A bean handling contact data")
+public class PizzaContactSessionBean extends BaseDatabaseBean implements ContactSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_916L;
+
+ /**
+ * Default constructor
+ */
+ public PizzaContactSessionBean () {
+ }
+
+ @Override
+ public Contact findContactById (final Long contactId) throws ContactNotFoundException {
+ // The parameter must be valid
+ if (null == contactId) {
+ // Throw NPE
+ throw new NullPointerException("contactId is null"); //NOI18N
+ } else if (contactId < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N
+ }
+
+ // Get query instance
+ Query query = this.getEntityManager().createNamedQuery("SearchContactId", UserContact.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("contactId", contactId); //NOI18N
+
+ // Init contact instance
+ Contact contact;
+
+ // Try to find a result
+ try {
+ // Find a single result
+ contact = (Contact) query.getSingleResult();
+ } catch (final NoResultException ex) {
+ // No result found
+ throw new ContactNotFoundException(contactId, ex);
+ }
+
+ // Return found instance
+ return contact;
+ }
+
+}
--- /dev/null
+/*
+ * 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 java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+
+/**
+ * A session EJB for administrative contact's phone number purposes
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "admincontactphone", mappedName = "ejb/stateless-pizza-admin-contact-phone", description = "An administrative bean handling contact's phone data")
+public class PizzaAdminContactPhoneSessionBean extends BaseDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 189_217_561_460_237_108L;
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<Contact> allContacts (final DialableCellphoneNumber cellPhone) {
+ // The parameter should be valid
+ if (null == cellPhone) {
+ // Throw NPE
+ throw new NullPointerException("cellPhone is null"); //NOI18N
+ } else if (cellPhone.getPhoneId() == null) {
+ // Phone id is null, means not persisted or correclty updated instance
+ throw new NullPointerException("cellPhone.phoneId is null"); //NOI18N
+ } else if (cellPhone.getPhoneId() < 1) {
+ // Not valid id number
+ throw new IllegalArgumentException(MessageFormat.format("cellPhone.phoneId={0} is not valid", cellPhone.getPhoneId())); //NOI18N
+ }
+
+ // Init list instance
+ List<Contact> contacts = null;
+
+ // Get query object from all found contact-cellphone links
+ Query query = this.getEntityManager().createNamedQuery("AllContactsByCellphone", List.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("cellPhone", cellPhone); //NOI18N
+
+ // Try to find all
+ try {
+ contacts = query.getResultList();
+ } catch (final NoResultException ex) {
+ // No results found
+ }
+
+ // Return list
+ return contacts;
+ }
+
+}
--- /dev/null
+/*
+ * 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 javax.ejb.Stateless;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+
+/**
+ * An EJB for administrative phone purposes
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "adminphone", mappedName = "ejb/stateless-pizza-admin-phone", description = "An administrative bean handling phone data")
+public class PizzaAdminPhoneSessionBean extends BaseDatabaseBean implements AdminPhoneSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 18_597_165_817_401_853L;
+
+}