From d845176e9ffddc291e40ca583fe96faa89d3331e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 19 Sep 2017 22:35:27 +0200 Subject: [PATCH] Please cherry-pick: - implemented business method findBranchOfficeById() - fixed mobileProvider EJB name (which is part of portable name) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../AddressbookBranchOfficeSessionBean.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java index c09b8be..3683fd4 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java @@ -19,8 +19,10 @@ 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.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException; /** * A stateless session bean for general branch office purposes @@ -54,4 +56,37 @@ public class AddressbookBranchOfficeSessionBean extends BaseAddressbookDatabaseB 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; + } + } -- 2.39.5