]> git.mxchange.org Git - jjobs-ejb.git/blob - src/java/org/mxchange/jcontactsbusiness/basicdata/JobsBusinessDataSessionBean.java
Pre cherry-pick: jcontacts-business-core/lib has changed again ...
[jjobs-ejb.git] / src / java / org / mxchange / jcontactsbusiness / basicdata / JobsBusinessDataSessionBean.java
1 /*
2  * Copyright (C) 2017 Roland Häder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcontactsbusiness.basicdata;
18
19 import java.text.MessageFormat;
20 import javax.ejb.Stateless;
21 import javax.persistence.NoResultException;
22 import javax.persistence.Query;
23 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException;
24 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
25
26 /**
27  * A stateless session bean for business data
28  * <p>
29  * @author Roland Häder<roland@mxchange.org>
30  */
31 @Stateless (name = "businessData", description = "A general statless bean for handling business data (all)")
32 public class JobsBusinessDataSessionBean extends BaseJobsDatabaseBean implements BusinessDataSessionBeanRemote {
33
34         /**
35          * Serial number
36          */
37         private static final long serialVersionUID = 56_389_504_892_184_571L;
38
39         /**
40          * Default constructor
41          */
42         public JobsBusinessDataSessionBean () {
43                 // Call super constructor
44                 super();
45         }
46
47         @Override
48         public BusinessBasicData findBusinessDataById (final Long businessDataId) throws BusinessDataNotFoundException {
49                 // Trace message
50                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBusinessDataById: CALLED!", this.getClass().getSimpleName())); //NOI18N
51
52                 // Get query
53                 Query query = this.getEntityManager().createNamedQuery("SearchBusinessDataById", CompanyBasicData.class); //NOI18N
54
55                 // Set parameter
56                 query.setParameter("businessDataId", businessDataId); //NOI18N
57
58                 // Get single instance
59                 BusinessBasicData businessData = null;
60
61                 // Try to find a result
62                 try {
63                         // Find a single result
64                         businessData = (BusinessBasicData) query.getSingleResult();
65
66                         // Log trace message
67                         this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBusinessDataById: Found contact={1}", this.getClass().getSimpleName(), businessData)); //NOI18N
68                 } catch (final NoResultException ex) {
69                         // No result found
70                         throw new BusinessDataNotFoundException(businessDataId, ex);
71                 }
72
73                 // Trace message
74                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBusinessDataById: businessData={1} - EXIT!", this.getClass().getSimpleName(), businessData)); //NOI18N
75
76                 // Return it
77                 return businessData;
78         }
79
80 }