Search in sources :

Example 21 with NonUniqueResultException

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;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 22 with NonUniqueResultException

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;
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NonUniqueResultException(javax.persistence.NonUniqueResultException) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) PopulationDataCriteria(de.symeda.sormas.api.infrastructure.PopulationDataCriteria) NoResultException(javax.persistence.NoResultException) Predicate(javax.persistence.criteria.Predicate)

Example 23 with NonUniqueResultException

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();
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) EntityManager(javax.persistence.EntityManager) NoResultException(javax.persistence.NoResultException)

Example 24 with NonUniqueResultException

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();
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) EntityManager(javax.persistence.EntityManager) NoResultException(javax.persistence.NoResultException)

Example 25 with NonUniqueResultException

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();
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) EntityManager(javax.persistence.EntityManager) NoResultException(javax.persistence.NoResultException)

Aggregations

NonUniqueResultException (javax.persistence.NonUniqueResultException)64 NoResultException (javax.persistence.NoResultException)53 Query (javax.persistence.Query)29 EntityManager (javax.persistence.EntityManager)10 List (java.util.List)6 PersistenceException (javax.persistence.PersistenceException)6 Collection (java.util.Collection)5 QueryBuilder (org.meveo.commons.utils.QueryBuilder)5 IOException (java.io.IOException)4 Date (java.util.Date)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 HashMap (java.util.HashMap)3 EntityExistsException (javax.persistence.EntityExistsException)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 OptimisticLockException (javax.persistence.OptimisticLockException)3 TransactionRequiredException (javax.persistence.TransactionRequiredException)3 TypedQuery (javax.persistence.TypedQuery)3 WebResource (org.asqatasun.entity.subject.WebResource)3 ContextMappingInfo (org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo)3 PopulationDataCriteria (de.symeda.sormas.api.infrastructure.PopulationDataCriteria)2