2 * Copyright (C) 2017 Roland Häder
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.jcontactsbusiness.model.opening_time;
19 import java.text.MessageFormat;
20 import java.util.List;
21 import javax.ejb.Stateless;
22 import javax.persistence.NoResultException;
23 import javax.persistence.Query;
24 import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException;
25 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
28 * A stateless session bean for general opening times purposes
30 * @author Roland Häder<roland@mxchange.org>
32 @Stateless (name = "openingTimes", description = "A general statless bean for handling branch office data (all)")
33 public class JobsOpeningTimesSessionBean extends BaseJobsDatabaseBean implements OpeningTimeSessionBeanRemote {
38 private static final long serialVersionUID = 58_467_386_571_701L;
41 @SuppressWarnings ("unchecked")
42 public List<OpeningTime> allOpeningTimes () {
44 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allOpeningTimes: CALLED!", this.getClass().getSimpleName())); //NOI18N
47 final Query query = this.getEntityManager().createNamedQuery("AllOpeningTimes"); //NOI18N
50 final List<OpeningTime> list = query.getResultList();
53 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allOpeningTimes: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
60 public OpeningTime findOpeningTimesById (final Long departmentId) throws OpeningTimeNotFoundException {
62 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: CALLED!", this.getClass().getSimpleName())); //NOI18N
65 if (null == departmentId) {
67 throw new NullPointerException("departmentId is null"); //NOI18N
68 } else if (departmentId < 1) {
70 throw new NullPointerException(MessageFormat.format("departmentId={0}is invalid", departmentId)); //NOI18N
74 final Query query = this.getEntityManager().createNamedQuery("SearchOpeningTimesById", BusinessOpeningTime.class); //NOI18N
77 query.setParameter("departmentId", departmentId); //NOI18N
79 // Get single instance
80 final OpeningTime department;
82 // Try to find a result
84 // Find a single result
85 department = (OpeningTime) query.getSingleResult();
88 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: Found department={1}", this.getClass().getSimpleName(), department)); //NOI18N
89 } catch (final NoResultException ex) {
91 throw new OpeningTimeNotFoundException(departmentId, ex);
95 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: department={1} - EXIT!", this.getClass().getSimpleName(), department)); //NOI18N