From: Roland Häder Date: Tue, 19 Sep 2017 20:35:27 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ac1502b3a9e1ddfeb21d1024f1aebe738d8b1f1b;p=jjobs-ejb.git Please cherry-pick: - implemented business method findBranchOfficeById() - fixed mobileProvider EJB name (which is part of portable name) Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java index d454a0b..ac6683f 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java @@ -19,7 +19,9 @@ package org.mxchange.jcontactsbusiness.model.branchoffice; 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.branchoffice.BranchOfficeNotFoundException; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; /** @@ -54,4 +56,37 @@ public class JobsBranchOfficeSessionBean extends BaseJobsDatabaseBean implements return list; } + @Override + public BranchOffice findBranchOfficeById (final Long branchOfficeId) throws BranchOfficeNotFoundException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBranchOfficeById: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Get query + final Query query = this.getEntityManager().createNamedQuery("SearchBranchOfficeById", CompanyBranchOffice.class); //NOI18N + + // Set parameter + query.setParameter("branchOfficeId", branchOfficeId); //NOI18N + + // Get single instance + final BranchOffice branchOffice; + + // Try to find a result + try { + // Find a single result + branchOffice = (BranchOffice) query.getSingleResult(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBranchOfficeById: Found branchOffice={1}", this.getClass().getSimpleName(), branchOffice)); //NOI18N + } catch (final NoResultException ex) { + // No result found + throw new BranchOfficeNotFoundException(branchOfficeId, ex); + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBranchOfficeById: branchOffice={1} - EXIT!", this.getClass().getSimpleName(), branchOffice)); //NOI18N + + // Return it + return branchOffice; + } + }