return findNextId(idType, null);
}
@Override
public IdGeneration findNextId(String idType, Long batchSize) 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()) {