public IdGeneration findNextId(String idType) throws OptimisticLockException, Exception {
    IdGeneration response;
    Query query = em.createNamedQuery("BC_FIND_NEXT_ID");
    query.setParameter("idType", idType);
    try {
      IdGeneration idGeneration = (IdGeneration) query.getSingleResult();
      response =
          (IdGeneration)
              entityConfiguration.createEntityInstance(
                  "org.broadleafcommerce.profile.core.domain.IdGeneration");
      response.setBatchSize(idGeneration.getBatchSize());
      response.setBatchStart(idGeneration.getBatchStart());
      Long originalBatchStart = idGeneration.getBatchStart();
      idGeneration.setBatchStart(originalBatchStart + idGeneration.getBatchSize());
      if (idGeneration.getBegin() != null) {
        response.setBegin(idGeneration.getBegin());
        if (idGeneration.getBatchStart() < idGeneration.getBegin()) {
          idGeneration.setBatchStart(idGeneration.getBegin());
          response.setBatchStart(idGeneration.getBatchStart());
        }
      }
      if (idGeneration.getEnd() != null) {
        response.setEnd(idGeneration.getEnd());
        if (idGeneration.getBatchStart() > idGeneration.getEnd()) {
          response.setBatchSize(idGeneration.getEnd() - originalBatchStart + 1);
          if (idGeneration.getBegin() != null) {
            idGeneration.setBatchStart(idGeneration.getBegin());
          } else {
            idGeneration.setBatchStart(getDefaultBatchStart());
          }
        }
      }
      response.setType(idGeneration.getType());
      em.merge(idGeneration);
      em.flush();
    } catch (NoResultException nre) {
      // No result not found.
      if (LOG.isDebugEnabled()) {
        LOG.debug("No row found in idGenerator table for " + idType + " creating row.");
      }
      response =
          (IdGeneration)
              entityConfiguration.createEntityInstance(
                  "org.broadleafcommerce.profile.core.domain.IdGeneration");
      response.setType(idType);
      response.setBegin(null);
      response.setEnd(null);
      response.setBatchStart(getDefaultBatchStart());
      response.setBatchSize(getDefaultBatchSize());
      try {
        em.persist(response);
        em.flush();
      } catch (EntityExistsException e) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              "Error inserting row id generation for idType " + idType + ".  Requerying table.");
        }
        return findNextId(idType);
      }
    }

    return response;
  }
 public CustomerPhone create() {
   return (CustomerPhone) entityConfiguration.createEntityInstance(CustomerPhone.class.getName());
 }
 public CustomerPhone readCustomerPhoneById(Long customerPhoneId) {
   return (CustomerPhone)
       em.find(
           entityConfiguration.lookupEntityClass(CustomerPhone.class.getName()), customerPhoneId);
 }
 public OfferCode create() {
   return ((OfferCode) entityConfiguration.createEntityInstance(OfferCode.class.getName()));
 }
 @Override
 public StaticAssetStorage create() {
   return (StaticAssetStorage)
       entityConfiguration.createEntityInstance(
           "org.broadleafcommerce.cms.file.domain.StaticAssetStorage");
 }
 public OfferCode readOfferCodeById(Long offerCodeId) {
   return (OfferCode)
       em.find(entityConfiguration.lookupEntityClass(OfferCode.class.getName()), offerCodeId);
 }