use of javax.persistence.NonUniqueResultException in project jbpm by kiegroup.
the class JpaProcessPersistenceContext method getProcessInstanceByCorrelationKey.
/**
* With regards to locking, the method is not always called during a transaction, which means
* that including logic to lock the query will cause exceptions and is not feasible.
* </p>
* However, this is not an issue: see the {@link #getProcessInstancesWaitingForEvent(String)} documentation
* for more information. The same logic applies to this method.
* </p>
*/
public Long getProcessInstanceByCorrelationKey(CorrelationKey correlationKey) {
Query processInstancesForEvent = getEntityManager().createNamedQuery("GetProcessInstanceIdByCorrelation");
processInstancesForEvent.setParameter("ckey", correlationKey.toExternalForm());
try {
return (Long) processInstancesForEvent.getSingleResult();
} catch (NonUniqueResultException e) {
return null;
} catch (NoResultException e) {
return null;
}
}
use of javax.persistence.NonUniqueResultException in project SORMAS-Project by hzi-braunschweig.
the class PopulationDataFacadeEjb method getProjectedRegionPopulation.
@Override
public Integer getProjectedRegionPopulation(String regionUuid) {
Float growthRate = regionService.getByUuid(regionUuid).getGrowthRate();
if (growthRate == null || growthRate == 0) {
return getRegionPopulation(regionUuid);
}
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<PopulationData> cq = cb.createQuery(PopulationData.class);
Root<PopulationData> root = cq.from(PopulationData.class);
PopulationDataCriteria criteria = new PopulationDataCriteria().ageGroupIsNull(true).sexIsNull(true).districtIsNull(true).communityIsNull(true).region(new RegionReferenceDto(regionUuid, null, null));
Predicate filter = service.buildCriteriaFilter(criteria, cb, root);
cq.where(filter);
try {
PopulationData populationData = em.createQuery(cq).getSingleResult();
return InfrastructureHelper.getProjectedPopulation(populationData.getPopulation(), populationData.getCollectionDate(), growthRate);
} catch (NoResultException | NonUniqueResultException e) {
return null;
}
}
use of javax.persistence.NonUniqueResultException in project droolsjbpm-integration by kiegroup.
the class ByCaseIdContainerLocator method locateContainer.
@Override
public String locateContainer(String alias, List<? extends KieContainerInstance> containerInstances) {
if (containerId != null) {
logger.debug("Container id has already been found for case {} and is {}", caseId, containerId);
return containerId;
}
logger.debug("Searching for container id for case id {} and alias {}", caseId, alias);
EntityManager em = EntityManagerFactoryManager.get().getOrCreate(KieServerConstants.KIE_SERVER_PERSISTENCE_UNIT_NAME).createEntityManager();
try {
containerId = (String) em.createQuery(CONTAINER_ID_QUERY).setParameter("caseId", caseId).getSingleResult();
logger.debug("Found container id '{}' for case id {}", containerId, caseId);
return containerId;
} catch (NoResultException e) {
throw new IllegalArgumentException("Case with id " + caseId + " not found");
} catch (NonUniqueResultException e) {
throw new IllegalArgumentException("Multiple containerIds found for caseId " + caseId);
} finally {
em.close();
}
}
use of javax.persistence.NonUniqueResultException in project droolsjbpm-integration by kiegroup.
the class ByTaskIdContainerLocator method locateContainer.
@Override
public String locateContainer(String alias, List<? extends KieContainerInstance> containerInstances) {
if (containerId != null) {
logger.debug("Container id has already be found for task {} and is {}", taskId, containerId);
return containerId;
}
logger.debug("Searching for container id for task id {} and alias {}", taskId, alias);
EntityManager em = EntityManagerFactoryManager.get().getOrCreate(KieServerConstants.KIE_SERVER_PERSISTENCE_UNIT_NAME).createEntityManager();
try {
containerId = (String) em.createQuery(CONTAINER_ID_QUERY).setParameter("taskId", taskId).getSingleResult();
logger.debug("Found container id '{}' for task id {}", containerId, taskId);
return containerId;
} catch (NoResultException e) {
throw new IllegalArgumentException("Task with id " + taskId + " not found");
} catch (NonUniqueResultException e) {
throw new IllegalArgumentException("Multiple containerIds found for taskId " + taskId);
} finally {
em.close();
}
}
use of javax.persistence.NonUniqueResultException in project droolsjbpm-integration by kiegroup.
the class ProcessContainerLocator method locateContainer.
@Override
public String locateContainer(final String alias, final List<? extends KieContainerInstance> containerInstances) {
if (containerId != null) {
logger.debug("Container id has already be found for process instance {} and is {}", processInstanceId, containerId);
return containerId;
}
logger.debug("Searching for container id for process instance id {} and alias {}", processInstanceId, alias);
EntityManager em = EntityManagerFactoryManager.get().getOrCreate(KieServerConstants.KIE_SERVER_PERSISTENCE_UNIT_NAME).createEntityManager();
try {
containerId = invokeQuery(em, processInstanceId);
logger.debug("Found container id '{}' for process instance id {}", containerId, processInstanceId);
return containerId;
} catch (NoResultException e) {
throw new IllegalArgumentException("ProcessInstance with id " + processInstanceId + " not found");
} catch (NonUniqueResultException e) {
throw new IllegalArgumentException("Multiple containerIds found for processInstanceId " + processInstanceId);
} finally {
em.close();
}
}
Aggregations