Search in sources :

Example 11 with NonUniqueResultException

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

the class ContentDAOImpl method find.

@Override
public Content find(WebResource page, String uri) {
    Query query = entityManager.createQuery("SELECT c FROM " + getEntityClass().getName() + " c" + " WHERE c.page = :page " + " AND c.uri = :uri");
    query.setParameter("page", page);
    query.setParameter("uri", uri);
    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 12 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 13 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 14 with NonUniqueResultException

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

the class WebResourceDAOImpl method findByUrlAndParentWebResource.

@Override
public WebResource findByUrlAndParentWebResource(String url, WebResource webResource) {
    Query query = entityManager.createQuery("SELECT wr FROM " + PageImpl.class.getName() + " wr" + " WHERE wr.url = :url" + " AND wr.parent =:webResource");
    query.setParameter("url", url);
    query.setParameter("webResource", webResource);
    try {
        return (WebResource) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    } catch (NonUniqueResultException nure) {
        List<WebResource> queryResult = query.getResultList();
        for (WebResource wr : queryResult) {
            if (StringUtils.equals(wr.getURL(), url)) {
                return wr;
            }
        }
        return null;
    }
}
Also used : PageImpl(org.asqatasun.entity.subject.PageImpl) NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) WebResource(org.asqatasun.entity.subject.WebResource) List(java.util.List) NoResultException(javax.persistence.NoResultException)

Example 15 with NonUniqueResultException

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

the class OptionDAOImpl method findOptionFromCode.

@Override
public Option findOptionFromCode(String optionCode) {
    Query query = entityManager.createQuery("SELECT o FROM " + getEntityClass().getName() + " o" + " WHERE o.code = :optionCode");
    query.setParameter("optionCode", optionCode);
    try {
        return (Option) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    } catch (NonUniqueResultException nure) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) Option(org.asqatasun.webapp.entity.option.Option) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)16 NonUniqueResultException (javax.persistence.NonUniqueResultException)16 Query (javax.persistence.Query)14 List (java.util.List)3 WebResource (org.asqatasun.entity.subject.WebResource)3 Collection (java.util.Collection)2 EntityExistsException (javax.persistence.EntityExistsException)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 PersistenceException (javax.persistence.PersistenceException)2 SQLException (java.sql.SQLException)1 LockTimeoutException (javax.persistence.LockTimeoutException)1 PessimisticLockException (javax.persistence.PessimisticLockException)1 QueryTimeoutException (javax.persistence.QueryTimeoutException)1 RollbackException (javax.persistence.RollbackException)1 TransactionRequiredException (javax.persistence.TransactionRequiredException)1 Parameter (org.asqatasun.entity.parameterization.Parameter)1 ParameterElement (org.asqatasun.entity.parameterization.ParameterElement)1 ParameterFamily (org.asqatasun.entity.parameterization.ParameterFamily)1 PageImpl (org.asqatasun.entity.subject.PageImpl)1