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.employee;
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.employee.CompanyEmployeeNotFoundException;
25 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
28 * A stateless bean for general purposes for company employees.
30 * @author Roland Häder<roland@mxchange.org>
32 @Stateless (name = "companyEmployee", description = "A general statless bean for handling company employees")
33 public class JobsCompanyEmployeeSessionBean extends BaseJobsDatabaseBean implements CompanyEmployeeSessionBeanRemote {
38 private static final long serialVersionUID = 26_458_796_703_761L;
43 public JobsCompanyEmployeeSessionBean () {
48 @SuppressWarnings ("unchecked")
49 public List<Employee> allCompanyEmployees () {
51 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCompanyEmployees(): CALLED!", this.getClass().getSimpleName())); //NOI18N
54 final Query query = this.getEntityManager().createNamedQuery("AllCompanyEmployees"); //NOI18N
57 final List<Employee> employees = query.getResultList();
60 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCompanyEmployees(): employees.size()={1} - EXIT!", this.getClass().getSimpleName(), employees.size())); //NOI18N
67 public Employee findCompanyEmployeeById (final Long employeeId) throws CompanyEmployeeNotFoundException {
69 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById(): employeeId={1} - CALLED!", this.getClass().getSimpleName(), employeeId)); //NOI18N
71 // Is the employee id valid?
72 if (null == employeeId) {
74 throw new NullPointerException("employeeId is null"); //NOI18N
75 } else if (employeeId < 1) {
77 throw new IllegalArgumentException(MessageFormat.format("employeeId={0} is not valid", employeeId)); //NOI18N
80 // Now get named query
81 final Query query = this.getEntityManager().createNamedQuery("SearchCompanyEmployeeById"); //NOI18N
84 query.setParameter("employeeId", employeeId); //NOI18N
87 final Employee employee;
89 // Try to find a result
91 // Find a single result
92 employee = (Employee) query.getSingleResult();
95 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById: Found employee={1}", this.getClass().getSimpleName(), employee)); //NOI18N
96 } catch (final NoResultException ex) {
98 throw new CompanyEmployeeNotFoundException(employeeId, ex);
102 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findCompanyEmployeeById: employee={1} - EXIT!", this.getClass().getSimpleName(), employee)); //NOI18N
104 // Return found instance