From 31569acdbe76afbe9a584855f18263abf0562ba3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 17 Oct 2017 22:30:29 +0200 Subject: [PATCH] Please cherry-pick: - renamed employee as there will be no other employees - added administrative country EJB due to remote interface separation - removed find*ById() as this was causing load on EJB container which can be prevented by application's JCache - fixed persistence unit as entities have been moved MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- src/conf/persistence.xml | 8 +- .../model/contact/JobsContactSessionBean.java | 188 ++++++++++-------- .../JobsAdminContactPhoneSessionBean.java | 7 +- .../JobsAdminBusinessDataSessionBean.java | 22 +- .../JobsBusinessDataSessionBean.java | 88 +------- .../JobsAdminBranchOfficeSessionBean.java | 6 +- .../JobsBranchOfficeSessionBean.java | 44 ---- .../JobsAdminDepartmentSessionBean.java | 10 +- .../department/JobsDepartmentSessionBean.java | 44 ---- .../JobsOpeningTimesSessionBean.java | 44 ---- .../data/JobsAdminCountrySingletonBean.java | 132 ++++++++++++ .../model/data/JobsCountrySingletonBean.java | 87 -------- .../jjobs/database/BaseJobsDatabaseBean.java | 28 +-- .../JobsAdminMobileProviderSessionBean.java | 2 +- .../phone/JobsPhoneSessionBean.java | 7 +- .../model/user/JobsUserSessionBean.java | 81 -------- 16 files changed, 285 insertions(+), 513 deletions(-) create mode 100644 src/java/org/mxchange/jcountry/model/data/JobsAdminCountrySingletonBean.java diff --git a/src/conf/persistence.xml b/src/conf/persistence.xml index 8d2f143..340ff4b 100644 --- a/src/conf/persistence.xml +++ b/src/conf/persistence.xml @@ -5,10 +5,10 @@ org.mxchange.jaddressbook.model.addressbook.UserAddressbook org.mxchange.jaddressbook.model.addressbook.entry.UserAddressbookEntry org.mxchange.jcontacts.model.contact.UserContact - org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData - org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice - org.mxchange.jcontactsbusiness.model.department.CompanyDepartment - org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee + org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData + org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice + org.mxchange.jcontactsbusiness.model.department.BusinessDepartment + org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition org.mxchange.jcontactsbusiness.model.logo.CompanyLogo diff --git a/src/java/org/mxchange/jcontacts/model/contact/JobsContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/JobsContactSessionBean.java index 52b1c9c..4fec75f 100644 --- a/src/java/org/mxchange/jcontacts/model/contact/JobsContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/contact/JobsContactSessionBean.java @@ -85,92 +85,6 @@ public class JobsContactSessionBean extends BaseJobsDatabaseBean implements Cont return emailAddresses; } - @Override - public Contact findContactByEmailAddress (final String emailAddress) throws ContactNotFoundException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N - - // The parameter must be valid - if (null == emailAddress) { - // Throw NPE - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.isEmpty()) { - // Not valid - throw new IllegalArgumentException("emailAddress is empty"); //NOI18N - } - - // Get query instance - final Query query = this.getEntityManager().createNamedQuery("SearchContactByEmailAddress", UserContact.class); //NOI18N - - // Set parameter and limit - query.setParameter("emailAddress", emailAddress); //NOI18N - query.setMaxResults(1); - - // Init contact instance - final Contact contact; - - // Try to find a result - try { - // Find a single result - contact = (Contact) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new ContactNotFoundException(emailAddress, ex); - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Return found instance - return contact; - } - - @Override - public Contact findContactById (final Long contactId) throws ContactNotFoundException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contactId={1} - CALLED!", this.getClass().getSimpleName(), contactId)); //NOI18N - - // The parameter must be valid - if (null == contactId) { - // Throw NPE - throw new NullPointerException("contactId is null"); //NOI18N - } else if (contactId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N - } - - // Get query instance - final Query query = this.getEntityManager().createNamedQuery("SearchContactById", UserContact.class); //NOI18N - - // Set parameter - query.setParameter("contactId", contactId); //NOI18N - query.setMaxResults(1); - - // Init contact instance - final Contact contact; - - // Try to find a result - try { - // Find a single result - contact = (Contact) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new ContactNotFoundException(contactId, ex); - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Return found instance - return contact; - } - @Override public boolean isEmailAddressRegistered (final String emailAddress) { // Log trace message @@ -328,4 +242,106 @@ public class JobsContactSessionBean extends BaseJobsDatabaseBean implements Cont return detachedContact; } + /** + * Returns a contact instance which has the given email address. + *

+ * @param emailAddress Email address + *

+ * @return Contact instance + *

+ * @throws ContactNotFoundException If the contact was not found + */ + private Contact findContactByEmailAddress (final String emailAddress) throws ContactNotFoundException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N + + // The parameter must be valid + if (null == emailAddress) { + // Throw NPE + throw new NullPointerException("emailAddress is null"); //NOI18N + } else if (emailAddress.isEmpty()) { + // Not valid + throw new IllegalArgumentException("emailAddress is empty"); //NOI18N + } + + // Get query instance + final Query query = this.getEntityManager().createNamedQuery("SearchContactByEmailAddress", UserContact.class); //NOI18N + + // Set parameter and limit + query.setParameter("emailAddress", emailAddress); //NOI18N + query.setMaxResults(1); + + // Init contact instance + final Contact contact; + + // Try to find a result + try { + // Find a single result + contact = (Contact) query.getSingleResult(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N + } catch (final NoResultException ex) { + // No result found + throw new ContactNotFoundException(emailAddress, ex); + } + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Return found instance + return contact; + } + + /** + * Returns a contact instance which has the given id number. + *

+ * @param contactId Contact id + *

+ * @return Contact instance + *

+ * @throws ContactNotFoundException If the contact was not found + */ + private Contact findContactById (final Long contactId) throws ContactNotFoundException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contactId={1} - CALLED!", this.getClass().getSimpleName(), contactId)); //NOI18N + + // The parameter must be valid + if (null == contactId) { + // Throw NPE + throw new NullPointerException("contactId is null"); //NOI18N + } else if (contactId < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N + } + + // Get query instance + final Query query = this.getEntityManager().createNamedQuery("SearchContactById", UserContact.class); //NOI18N + + // Set parameter + query.setParameter("contactId", contactId); //NOI18N + query.setMaxResults(1); + + // Init contact instance + final Contact contact; + + // Try to find a result + try { + // Find a single result + contact = (Contact) query.getSingleResult(); + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N + } catch (final NoResultException ex) { + // No result found + throw new ContactNotFoundException(contactId, ex); + } + + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N + + // Return found instance + return contact; + } + } diff --git a/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java index c215fc7..6657f5f 100644 --- a/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/phone/JobsAdminContactPhoneSessionBean.java @@ -23,8 +23,11 @@ import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; -import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException; -import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException; +import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException; +import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** * A session EJB for administrative contact's phone number purposes diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsAdminBusinessDataSessionBean.java index 1d27226..13d752e 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsAdminBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsAdminBusinessDataSessionBean.java @@ -22,10 +22,10 @@ import java.util.List; import java.util.Objects; import javax.ejb.EJB; import javax.ejb.Stateless; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataAlreadyAddedException; -import org.mxchange.jcontactsbusiness.model.employee.Employee; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataAlreadyAddedException; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jcontactsbusiness.model.employee.Employable; /** * An administrative stateless session bean for business data @@ -55,7 +55,7 @@ public class JobsAdminBusinessDataSessionBean extends BaseJobsDatabaseBean imple } @Override - public BusinessBasicData addCompanyBasicData (final BusinessBasicData basicData) throws BasicCompanyDataAlreadyAddedException { + public BasicData addBusinessBasicData (final BasicData basicData) throws BasicDataAlreadyAddedException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBusinessBasicData: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N @@ -68,7 +68,7 @@ public class JobsAdminBusinessDataSessionBean extends BaseJobsDatabaseBean imple throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} - is not null", basicData.getBasicDataId())); //NOI18N } else if (this.isSameCompanyNameAdded(basicData)) { // Throw exception - throw new BasicCompanyDataAlreadyAddedException(basicData); + throw new BasicDataAlreadyAddedException(basicData); } // Now add current date @@ -84,18 +84,18 @@ public class JobsAdminBusinessDataSessionBean extends BaseJobsDatabaseBean imple } // Is a founder set? - if (basicData.getCompanyFounder() instanceof Employee) { + if (basicData.getCompanyFounder() instanceof Employable) { // Get managed instance - final Employee managedEmployee = this.createManaged(basicData.getCompanyFounder()); + final Employable managedEmployee = this.createManaged(basicData.getCompanyFounder()); // Set it back basicData.setCompanyFounder(managedEmployee); } // Is a contact person set? - if (basicData.getCompanyContactEmployee() instanceof Employee) { + if (basicData.getCompanyContactEmployee() instanceof Employable) { // Get managed instance - final Employee managedEmployee = this.createManaged(basicData.getCompanyContactEmployee()); + final Employable managedEmployee = this.createManaged(basicData.getCompanyContactEmployee()); // Set it back basicData.setCompanyContactEmployee(managedEmployee); @@ -121,15 +121,15 @@ public class JobsAdminBusinessDataSessionBean extends BaseJobsDatabaseBean imple * * @return Whether same company name has been used */ - private boolean isSameCompanyNameAdded (final BusinessBasicData basicData) { + private boolean isSameCompanyNameAdded (final BasicData basicData) { // Get all available entries - final List list = this.businessDataBean.allCompanyBasicData(); + final List list = this.businessDataBean.allBusinessBasicData(); // Default is not found boolean isFound = false; // Then check each entry - for (final BusinessBasicData entry : list) { + for (final BasicData entry : list) { // Is the company name matching? if (Objects.equals(entry.getCompanyName(), basicData.getCompanyName())) { // Found match diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsBusinessDataSessionBean.java index 101b04e..29b3373 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/JobsBusinessDataSessionBean.java @@ -18,12 +18,9 @@ package org.mxchange.jcontactsbusiness.model.basicdata; import java.text.MessageFormat; import java.util.List; -import java.util.Objects; import javax.ejb.Stateless; -import javax.persistence.NoResultException; import javax.persistence.Query; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataNotFoundException; /** * A stateless session bean for business data @@ -48,7 +45,7 @@ public class JobsBusinessDataSessionBean extends BaseJobsDatabaseBean implements @Override @SuppressWarnings ("unchecked") - public List allCompanyBasicData () { + public List allBusinessBasicData () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N @@ -56,7 +53,7 @@ public class JobsBusinessDataSessionBean extends BaseJobsDatabaseBean implements final Query query = this.getEntityManager().createNamedQuery("AllBusinessData"); //NOI18N // Get list from it - final List list = query.getResultList(); + final List list = query.getResultList(); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N @@ -65,85 +62,4 @@ public class JobsBusinessDataSessionBean extends BaseJobsDatabaseBean implements return list; } - @Override - public BusinessBasicData findBasicDataById (final Long basicDataId) throws BasicCompanyDataNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Validate parameter - if (null == basicDataId) { - // Throw NPE - throw new NullPointerException("basicDataId is null"); //NOI18N - } else if (basicDataId < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("basicDataId={0}is invalid", basicDataId)); //NOI18N - } - - // Get query - final Query query = this.getEntityManager().createNamedQuery("SearchBusinessDataById", CompanyBasicData.class); //NOI18N - - // Set parameter - query.setParameter("basicDataId", basicDataId); //NOI18N - - // Get single instance - final BusinessBasicData basicData; - - // Try to find a result - try { - // Find a single result - basicData = (BusinessBasicData) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: Found basicData={1}", this.getClass().getSimpleName(), basicData)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new BasicCompanyDataNotFoundException(basicDataId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: basicData={1} - EXIT!", this.getClass().getSimpleName(), basicData)); //NOI18N - - // Return it - return basicData; - } - - @Override - public Boolean isCompanyNameUsed (final String companyName) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isCompanyNameUsed: companyName={1} - CALLED!", this.getClass().getSimpleName(), companyName)); //NOI18N - - // Is the parameter valid? - if (null == companyName) { - // Throw NPE - throw new NullPointerException("companyName is null"); //NOI18N - } else if (companyName.isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("companyName is empty"); //NOI18N - } - - // Default is not found - Boolean isCompanyNameUsed = Boolean.FALSE; - - // Get whole list - final List list = this.allCompanyBasicData(); - - // Check whole list - for (final BusinessBasicData basicData : list) { - // Is name used? - if (Objects.equals(basicData.getCompanyName(), companyName)) { - // Found one - isCompanyNameUsed = Boolean.TRUE; - - // Abort search - break; - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isCompanyNameUsed: isCompanyNameUsed={1} - EXIT!", this.getClass().getSimpleName(), isCompanyNameUsed)); //NOI18N - - // Return it - return isCompanyNameUsed; - } - } diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java index bc644c7..5cc7566 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsAdminBranchOfficeSessionBean.java @@ -22,11 +22,11 @@ import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; /** * A stateless session bean for administrative branch office purposes @@ -76,9 +76,9 @@ public class JobsAdminBranchOfficeSessionBean extends BaseJobsDatabaseBean imple branchOffice.setBranchCreated(new Date()); // Is user instance set? - if (branchOffice.getBranchCompany() instanceof org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData) { + if (branchOffice.getBranchCompany() instanceof BasicData) { // Get managed instance back - final org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData managedBasicData = this.createManaged(branchOffice.getBranchCompany()); + final BasicData managedBasicData = this.createManaged(branchOffice.getBranchCompany()); // Set it back in branch office branchOffice.setBranchCompany(managedBasicData); diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java index 638bef9..d454a0b 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/JobsBranchOfficeSessionBean.java @@ -19,9 +19,7 @@ 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; /** @@ -56,46 +54,4 @@ 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 - - // Validate parameter - if (null == branchOfficeId) { - // Throw NPE - throw new NullPointerException("branchOfficeId is null"); //NOI18N - } else if (branchOfficeId < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("branchOfficeId={0}is invalid", branchOfficeId)); //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; - } - } diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java index a71603d..875ecb2 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsAdminDepartmentSessionBean.java @@ -22,12 +22,12 @@ import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException; -import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.employee.Employee; import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; /** * A stateless session bean for administrative department purposes @@ -92,7 +92,7 @@ public class JobsAdminDepartmentSessionBean extends BaseJobsDatabaseBean impleme department.setDepartmentCreated(new Date()); // Get managed basic data instance - final BusinessBasicData managedBasicData = this.createManaged(department.getDepartmentCompany()); + final BasicData managedBasicData = this.createManaged(department.getDepartmentCompany()); // Set it back department.setDepartmentCompany(managedBasicData); @@ -116,9 +116,9 @@ public class JobsAdminDepartmentSessionBean extends BaseJobsDatabaseBean impleme } // Is lead employee set? - if (department.getDepartmentLead()instanceof Employee) { + if (department.getDepartmentLead()instanceof Employable) { // Get managed lead employee - final Employee managedEmployee = this.createManaged(department.getDepartmentLead()); + final Employable managedEmployee = this.createManaged(department.getDepartmentLead()); // Set it back department.setDepartmentLead(managedEmployee); diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java index b4a4211..57fe587 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/JobsDepartmentSessionBean.java @@ -19,9 +19,7 @@ package org.mxchange.jcontactsbusiness.model.department; 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.jjobs.database.BaseJobsDatabaseBean; /** @@ -56,46 +54,4 @@ public class JobsDepartmentSessionBean extends BaseJobsDatabaseBean implements D 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; - } - } diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java index 2ab6c7d..c10e0d1 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/JobsOpeningTimesSessionBean.java @@ -19,9 +19,7 @@ package org.mxchange.jcontactsbusiness.model.opening_time; 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.opening_time.OpeningTimeNotFoundException; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; /** @@ -56,46 +54,4 @@ public class JobsOpeningTimesSessionBean extends BaseJobsDatabaseBean implements return list; } - @Override - public OpeningTime findOpeningTimesById (final Long departmentId) throws OpeningTimeNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: 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("SearchOpeningTimesById", BusinessOpeningTime.class); //NOI18N - - // Set parameter - query.setParameter("departmentId", departmentId); //NOI18N - - // Get single instance - final OpeningTime department; - - // Try to find a result - try { - // Find a single result - department = (OpeningTime) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: Found department={1}", this.getClass().getSimpleName(), department)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new OpeningTimeNotFoundException(departmentId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: department={1} - EXIT!", this.getClass().getSimpleName(), department)); //NOI18N - - // Return it - return department; - } - } diff --git a/src/java/org/mxchange/jcountry/model/data/JobsAdminCountrySingletonBean.java b/src/java/org/mxchange/jcountry/model/data/JobsAdminCountrySingletonBean.java new file mode 100644 index 0000000..a2cd638 --- /dev/null +++ b/src/java/org/mxchange/jcountry/model/data/JobsAdminCountrySingletonBean.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +*/ +package org.mxchange.jcountry.model.data; + +import java.text.MessageFormat; +import java.util.Date; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException; +import org.mxchange.jjobs.database.BaseJobsDatabaseBean; + +/** + * A stateless EJB for administrative country purposes + *

+ * @author Roland Häder + */ +@Stateless (name = "adminCountry", description = "A stateless session-scoped bean for administrative country purposes") +public class JobsAdminCountrySingletonBean extends BaseJobsDatabaseBean implements AdminCountrySessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 15_846_983_298_691_208L; + + /** + * Default constructor + */ + public JobsAdminCountrySingletonBean () { + // Call super constructor + super(); + } + + @Override + public Country addCountry (final Country country) throws CountryAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N + + // Is it already there? + if (null == country) { + // Throw NPE + throw new NullPointerException("country is null"); //NOI18N + } else if (country.getCountryCode().isEmpty()) { + // Code is not set + throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N + } else if (country.getCountryI18nKey().isEmpty()) { + // I18n key is not set + throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N + } else if (country.getCountryId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N + } else if (this.isCountryAdded(country)) { + // Yes, then abort here + throw new CountryAlreadyAddedException(country); + } + + // Add timestamp + country.setCountryEntryCreated(new Date()); + + // It is not added, so persist it + this.getEntityManager().persist(country); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - EXIT!", this.getClass().getSimpleName(), country)); //NOI18N + + // Return updated instance + return country; + } + + /** + * Checks whether given country is already added by i18n key or country + * code, what comes first. + *

+ * @param country Country instance to check + *

+ * @return Whether the country was found + */ + private boolean isCountryAdded (final Country country) { + if (null == country) { + // Throw NPE + throw new NullPointerException("country is null"); //NOI18N + } else if (country.getCountryCode().isEmpty()) { + // Code is not set + throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N + } else if (country.getCountryI18nKey().isEmpty()) { + // I18n key is not set + throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N + } else if (country.getCountryId() != null) { + // Should be null + throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N + } + + // Default is not found + boolean isAdded = false; + + // Get query instance + final Query query = this.getEntityManager().createNamedQuery("SearchCountryByCodeI18nKey", CountryData.class); //NOI18N + + // Assign all parameters + query.setParameter("code", country.getCountryCode()); //NOI18N + query.setParameter("key", country.getCountryI18nKey()); //NOI18N + + // Try to get a single result + try { + // Get single result + final Country foundCountry = (Country) query.getSingleResult(); + + // Found it? + isAdded = (foundCountry instanceof Country); + } catch (final NoResultException ex) { + // Not found, don't log this + } + + // Return result + return isAdded; + } + +} diff --git a/src/java/org/mxchange/jcountry/model/data/JobsCountrySingletonBean.java b/src/java/org/mxchange/jcountry/model/data/JobsCountrySingletonBean.java index 26c3b6d..71a874b 100644 --- a/src/java/org/mxchange/jcountry/model/data/JobsCountrySingletonBean.java +++ b/src/java/org/mxchange/jcountry/model/data/JobsCountrySingletonBean.java @@ -17,13 +17,10 @@ package org.mxchange.jcountry.model.data; import java.text.MessageFormat; -import java.util.Date; import java.util.List; import javax.ejb.Singleton; import javax.ejb.Startup; -import javax.persistence.NoResultException; import javax.persistence.Query; -import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; /** @@ -48,42 +45,6 @@ public class JobsCountrySingletonBean extends BaseJobsDatabaseBean implements Co super(); } - @Override - public Country addCountry (final Country country) throws CountryAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N - - // Is it already there? - if (null == country) { - // Throw NPE - throw new NullPointerException("country is null"); //NOI18N - } else if (country.getCountryCode().isEmpty()) { - // Code is not set - throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N - } else if (country.getCountryI18nKey().isEmpty()) { - // I18n key is not set - throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N - } else if (country.getCountryId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N - } else if (this.isCountryAdded(country)) { - // Yes, then abort here - throw new CountryAlreadyAddedException(country); - } - - // Add timestamp - country.setCountryEntryCreated(new Date()); - - // It is not added, so persist it - this.getEntityManager().persist(country); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - EXIT!", this.getClass().getSimpleName(), country)); //NOI18N - - // Return updated instance - return country; - } - @Override @SuppressWarnings ("unchecked") public List allCountries () { @@ -103,52 +64,4 @@ public class JobsCountrySingletonBean extends BaseJobsDatabaseBean implements Co return countries; } - /** - * Checks whether given country is already added by i18n key or country - * code, what comes first. - *

- * @param country Country instance to check - *

- * @return Whether the country was found - */ - private boolean isCountryAdded (final Country country) { - if (null == country) { - // Throw NPE - throw new NullPointerException("country is null"); //NOI18N - } else if (country.getCountryCode().isEmpty()) { - // Code is not set - throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N - } else if (country.getCountryI18nKey().isEmpty()) { - // I18n key is not set - throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N - } else if (country.getCountryId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N - } - - // Default is not found - boolean isAdded = false; - - // Get query instance - final Query query = this.getEntityManager().createNamedQuery("SearchCountryByCodeI18nKey", CountryData.class); //NOI18N - - // Assign all parameters - query.setParameter("code", country.getCountryCode()); //NOI18N - query.setParameter("key", country.getCountryI18nKey()); //NOI18N - - // Try to get a single result - try { - // Get single result - final Country foundCountry = (Country) query.getSingleResult(); - - // Found it? - isAdded = (foundCountry instanceof Country); - } catch (final NoResultException ex) { - // Not found, don't log this - } - - // Return result - return isAdded; - } - } diff --git a/src/java/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java b/src/java/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java index 8c39172..616d3ae 100644 --- a/src/java/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java +++ b/src/java/org/mxchange/jjobs/database/BaseJobsDatabaseBean.java @@ -31,11 +31,9 @@ import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.ContactUtils; import org.mxchange.jcontacts.model.contact.UserContact; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; -import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice; -import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee; -import org.mxchange.jcontactsbusiness.model.employee.Employee; +import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; +import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData; import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; @@ -54,6 +52,8 @@ import org.mxchange.jphone.utils.PhoneUtils; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.UserUtils; +import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; /** * A helper class for beans that access the database. @@ -372,7 +372,7 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { *

* @return Managed basic data instance */ - protected BusinessBasicData createManaged (final BusinessBasicData basicData) { + protected BasicData createManaged (final BasicData basicData) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N @@ -389,10 +389,10 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final BusinessBasicData managedBasicData = this.getEntityManager().find(CompanyBasicData.class, basicData.getBasicDataId()); + final BasicData managedBasicData = this.getEntityManager().find(BusinessBasicData.class, basicData.getBasicDataId()); // Should be there - assert (managedBasicData instanceof BusinessBasicData) : "managedBasicData is null"; //NOI18N + assert (managedBasicData instanceof BasicData) : "managedBasicData is null"; //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N @@ -425,10 +425,10 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final BranchOffice managedBranchOffice = this.getEntityManager().find(CompanyBranchOffice.class, branchOffice.getBranchId()); + final BranchOffice managedBranchOffice = this.getEntityManager().find(BusinessBranchOffice.class, branchOffice.getBranchId()); // Should be there - assert (managedBranchOffice instanceof BusinessBasicData) : "managedBranchOffice is null"; //NOI18N + assert (managedBranchOffice instanceof BasicData) : "managedBranchOffice is null"; //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N @@ -444,7 +444,7 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { *

* @return Managed employee instance */ - protected Employee createManaged (final Employee employee) { + protected Employable createManaged (final Employable employee) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N @@ -461,10 +461,10 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { } // Try to find it (should be there) - final Employee managedEmployee = this.getEntityManager().find(CompanyEmployee.class, employee.getEmployeeId()); + final Employable managedEmployee = this.getEntityManager().find(BusinessEmployee.class, employee.getEmployeeId()); // Should be there - assert (managedEmployee instanceof Employee) : "managedEmployee is null"; //NOI18N + assert (managedEmployee instanceof Employable) : "managedEmployee is null"; //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedEmployee={1} - EXIT!", this.getClass().getSimpleName(), managedEmployee)); //NOI18N @@ -500,7 +500,7 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { final HeadquartersData managedHeadquarters = this.getEntityManager().find(CompanyHeadquartersData.class, headquarters.getHeadquartersId()); // Should be there - assert (managedHeadquarters instanceof BusinessBasicData) : "managedHeadquarters is null"; //NOI18N + assert (managedHeadquarters instanceof BasicData) : "managedHeadquarters is null"; //NOI18N // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarters={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarters)); //NOI18N @@ -695,7 +695,7 @@ public abstract class BaseJobsDatabaseBean extends BaseDatabaseBean { *

* @param basicData Company basic data instance to update */ - protected void setAllPhoneEntriesCreated (final BusinessBasicData basicData) { + protected void setAllPhoneEntriesCreated (final BasicData basicData) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllPhoneEntriesCreated: basicData={0} - CALLED!", basicData)); //NOI18N diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/JobsAdminMobileProviderSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/JobsAdminMobileProviderSessionBean.java index 603f14a..f53b33e 100644 --- a/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/JobsAdminMobileProviderSessionBean.java +++ b/src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/JobsAdminMobileProviderSessionBean.java @@ -20,7 +20,7 @@ import java.text.MessageFormat; import java.util.Date; import javax.ejb.Stateless; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; -import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException; +import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderAlreadyAddedException; /** * An administrative singleton EJB for mobile provider informations diff --git a/src/java/org/mxchange/jphone/model/phonenumbers/phone/JobsPhoneSessionBean.java b/src/java/org/mxchange/jphone/model/phonenumbers/phone/JobsPhoneSessionBean.java index 9a07dc9..5684d99 100644 --- a/src/java/org/mxchange/jphone/model/phonenumbers/phone/JobsPhoneSessionBean.java +++ b/src/java/org/mxchange/jphone/model/phonenumbers/phone/JobsPhoneSessionBean.java @@ -19,10 +19,15 @@ package org.mxchange.jphone.model.phonenumbers.phone; import java.text.MessageFormat; import java.util.List; import javax.ejb.Stateless; -import javax.persistence.NoResultException; import javax.persistence.Query; import org.mxchange.jjobs.database.BaseJobsDatabaseBean; import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote; /** diff --git a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java index 9d29a40..7888f17 100644 --- a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java @@ -252,39 +252,6 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes return foundUser; } - @Override - public User findUserById (final Long userId) throws UserNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N - - // Is the parameter valid? - if (null == userId) { - // Throw NPE - throw new NullPointerException("userId is null"); //NOI18N - } else if (userId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N - } else if (!this.ifUserIdExists(userId)) { - // Does not exist - throw new UserNotFoundException(userId); - } - - // Create query instance - final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N - - // Set user id - query.setParameter("id", userId); //NOI18N - - // Fetch the result, it should be there by now - final User user = (User) query.getSingleResult(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N - - // Return found user - return user; - } - @Override public String generateRandomUserName () { // Trace message @@ -379,54 +346,6 @@ public class JobsUserSessionBean extends BaseJobsDatabaseBean implements UserSes return true; } - @Override - public boolean ifUserIdExists (final Long userId) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N - - // userId should not be null - if (null == userId) { - // Abort here - throw new NullPointerException("userId is null"); //NOI18N - } else if (userId < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N - } - - // Generate query - final Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("id", userId); //NOI18N - - // Try this - try { - // Try to get single result - final User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N - - // User name does not exist - return false; - } catch (final PersistenceException ex) { - // Something bad happened - this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N - - // Throw again - throw ex; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: Found userId={1} - EXIT!", this.getClass().getSimpleName(), userId)); //NOI18N - - // Found it - return true; - } - @Override public boolean ifUserNameExists (final String userName) { // Trace message -- 2.39.2