/*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017 - 2020 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
import java.text.MessageFormat;
import java.util.List;
import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
import javax.persistence.Query;
-import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
-import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
+import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
/**
* A stateless session bean for general department purposes
* @author Roland Häder<roland@mxchange.org>
*/
@Stateless (name = "department", description = "A general statless bean for handling branch office data (all)")
-public class FinancialsDepartmentSessionBean extends BaseFinancialsDatabaseBean implements DepartmentSessionBeanRemote {
+public class FinancialsDepartmentSessionBean extends BaseFinancialsEnterpriseBean implements DepartmentSessionBeanRemote {
/**
* Serial number
*/
- private static final long serialVersionUID = 58_467_386_571_701L;
+ private static final long serialVersionUID = 58_467_386_571_704L;
@Override
@SuppressWarnings ("unchecked")
- public List<Department> allDepartments () {
+ public List<Department> fetchAllDepartments () {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allDepartments: CALLED!", this.getClass().getSimpleName())); //NOI18N
return list;
}
- @Override
- public Department findDepartmentById (final Long departmentId) throws DepartmentNotFoundException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findDepartmentById: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
- // Validate parameter
- if (null == departmentId) {
- // Throw NPE
- throw new NullPointerException("departmentId is null"); //NOI18N
- } else if (departmentId < 1) {
- // Throw NPE
- throw new NullPointerException(MessageFormat.format("departmentId={0}is invalid", departmentId)); //NOI18N
- }
-
- // Get query
- final Query query = this.getEntityManager().createNamedQuery("SearchDepartmentById", CompanyDepartment.class); //NOI18N
-
- // Set parameter
- query.setParameter("departmentId", departmentId); //NOI18N
-
- // Get single instance
- final Department department;
-
- // Try to find a result
- try {
- // Find a single result
- department = (Department) query.getSingleResult();
-
- // Log trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findDepartmentById: Found department={1}", this.getClass().getSimpleName(), department)); //NOI18N
- } catch (final NoResultException ex) {
- // No result found
- throw new DepartmentNotFoundException(departmentId, ex);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findDepartmentById: department={1} - EXIT!", this.getClass().getSimpleName(), department)); //NOI18N
-
- // Return it
- return department;
- }
-
}