Search in sources :

Example 36 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project Asqatasun by Asqatasun.

the class OptionElementDAO method findOptionElementFromUserAndFamilyCode.

public Collection<OptionElementImpl> findOptionElementFromUserAndFamilyCode(User user, String optionFamilyCode) {
    Query query = entityManager.createQuery("SELECT distinct(u.optionElementSet) FROM " + getUserEntityClass().getName() + " u" + " LEFT JOIN u.optionElementSet oe" + " WHERE u=:user" + " AND oe.option.optionFamily.code=:optionFamilyCode");
    query.setParameter("user", user);
    query.setParameter("optionFamilyCode", optionFamilyCode);
    try {
        return (Collection<OptionElementImpl>) query.getResultList();
    } catch (NoResultException | NonUniqueResultException nre) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) Collection(java.util.Collection) NoResultException(javax.persistence.NoResultException)

Example 37 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project Asqatasun by Asqatasun.

the class OptionElementDAO method findOptionElementFromUser.

public Collection<OptionElementImpl> findOptionElementFromUser(User user) {
    Query query = entityManager.createQuery("SELECT u.optionElementSet FROM " + getUserEntityClass().getName() + " u" + " WHERE u=:user");
    query.setParameter("user", user);
    try {
        return (Collection<OptionElementImpl>) query.getResultList();
    } catch (NoResultException | NonUniqueResultException nre) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) Collection(java.util.Collection) NoResultException(javax.persistence.NoResultException)

Example 38 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project Asqatasun by Asqatasun.

the class ParameterFamilyDAOImpl method findParameterFamilyFromCode.

@Override
public ParameterFamily findParameterFamilyFromCode(String parameterFamilyCode) {
    Query query = entityManager.createQuery("SELECT pf FROM " + getEntityClass().getName() + " pf" + " WHERE pf.paramFamilyCode = :parameterFamilyCode");
    query.setParameter("parameterFamilyCode", parameterFamilyCode);
    try {
        return (ParameterFamily) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    } catch (NonUniqueResultException nure) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) ParameterFamily(org.asqatasun.entity.parameterization.ParameterFamily) NoResultException(javax.persistence.NoResultException)

Example 39 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project Asqatasun by Asqatasun.

the class ContentDAOImpl method find.

@Override
public Content find(Audit audit, String uri) {
    Query query = entityManager.createQuery("SELECT c FROM " + getEntityClass().getName() + " c" + " WHERE c.audit = :audit" + " AND c.uri = :uri" + " AND c.httpStatusCode =:httpStatusCode");
    query.setParameter(AUDIT_KEY, audit);
    query.setParameter("uri", uri);
    query.setParameter(HTTP_STATUS_CODE_KEY, HTTP_STATUS_OK);
    try {
        return (Content) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    } catch (NonUniqueResultException nure) {
        List<Content> queryResult = query.getResultList();
        for (Content content : queryResult) {
            if (StringUtils.equals(content.getURI(), uri)) {
                return content;
            }
        }
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 40 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project Asqatasun by Asqatasun.

the class OptionElementDAO method findOptionElementFromValueAndOption.

/**
 * @param value
 * @param option
 * @return
 */
public OptionElementImpl findOptionElementFromValueAndOption(String value, Option option) {
    Query query = entityManager.createQuery("SELECT oe FROM " + getEntityClass().getName() + " oe" + " WHERE oe.value=:value" + " AND oe.option=:option");
    query.setParameter("value", value);
    query.setParameter("option", option);
    try {
        return (OptionElementImpl) query.getSingleResult();
    } catch (NoResultException | NonUniqueResultException nre) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) OptionElementImpl(org.asqatasun.entity.option.OptionElementImpl) Query(javax.persistence.Query) 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