/*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 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 java.util.Objects;
import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
import javax.persistence.Query;
-import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException;
-import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
+import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean;
/**
* A stateless session bean for business data
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-@Stateless (name = "businessData", description = "A general statless bean for handling business data (all)")
-public class JobsBusinessDataSessionBean extends BaseJobsDatabaseBean implements BusinessDataSessionBeanRemote {
+@Stateless (name = "basicCompanyData", description = "A general statless bean for handling business data (all)")
+public class JobsBusinessDataSessionBean extends BaseJobsEnterpriseBean implements BasicCompanyDataSessionBeanRemote {
/**
* Serial number
@Override
@SuppressWarnings ("unchecked")
- public List<BusinessBasicData> allCompanyBasicData () {
+ public List<BasicData> allBusinessBasicData () {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N
final Query query = this.getEntityManager().createNamedQuery("AllBusinessData"); //NOI18N
// Get list from it
- final List<BusinessBasicData> list = query.getResultList();
+ final List<BasicData> list = query.getResultList();
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBusinessContacts: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
return list;
}
- @Override
- public BusinessBasicData findBasicDataById (final Long basicDataId) throws BusinessDataNotFoundException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: CALLED!", this.getClass().getSimpleName())); //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 BusinessDataNotFoundException(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<BusinessBasicData> 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;
- }
-
}