Search in sources :

Example 51 with NoResultException

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

the class WebResourceDAOImpl method read.

@Override
public WebResource read(Long key) {
    try {
        Query query = entityManager.createQuery("SELECT wr FROM " + getEntityClass().getName() + " wr" + " left join fetch wr.processResultSet prs" + " left join fetch prs.remarkSet prk" + " left join fetch prk.elementSet pr" + " WHERE wr.id = :id");
        query.setParameter("id", key);
        return (WebResource) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) WebResource(org.asqatasun.entity.subject.WebResource) NoResultException(javax.persistence.NoResultException)

Example 52 with NoResultException

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

the class WebResourceDAOImpl method findByUrl.

@Override
public WebResource findByUrl(String url) {
    Query query = entityManager.createQuery("SELECT wr FROM " + getEntityClass().getName() + " wr" + " left join fetch wr.processResultSet pr" + " WHERE wr.url = :url");
    query.setParameter("url", url);
    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 : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) WebResource(org.asqatasun.entity.subject.WebResource) List(java.util.List) NoResultException(javax.persistence.NoResultException)

Example 53 with NoResultException

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

the class WebResourceDAOImpl method findParentWebResourceId.

@Override
public Long findParentWebResourceId(Long webresourceId) {
    if (webresourceId == null) {
        return null;
    }
    try {
        Query query = entityManager.createQuery("SELECT r FROM " + getEntityClass().getName() + " r" + " WHERE r.id = :id");
        query.setParameter("id", webresourceId);
        if (query.getSingleResult() != null && ((WebResource) query.getSingleResult()).getParent() != null) {
            return ((WebResource) query.getSingleResult()).getParent().getId();
        } else {
            return null;
        }
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) WebResource(org.asqatasun.entity.subject.WebResource) NoResultException(javax.persistence.NoResultException)

Example 54 with NoResultException

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

the class WebResourceDAOImpl method findChildWebResourceCount.

@Override
public Long findChildWebResourceCount(WebResource parentWebResource) {
    if (parentWebResource == null) {
        return null;
    }
    Query query = entityManager.createQuery("SELECT count (r.id) FROM " + getEntityClass().getName() + " r" + " WHERE r.parent.id = :id");
    query.setParameter("id", parentWebResource.getId());
    query.setHint(CACHEABLE_OPTION, TRUE);
    try {
        return (Long) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 55 with NoResultException

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

the class WebResourceDAOImpl method findByAuditAndUrl.

@Override
public WebResource findByAuditAndUrl(Audit audit, String url) {
    Query query = entityManager.createQuery("SELECT wr FROM " + getEntityClass().getName() + " wr" + " left join fetch wr.processResultSet pr" + " WHERE wr.url = :url AND wr.audit = :audit");
    query.setParameter("url", url);
    query.setParameter("audit", audit);
    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 : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) WebResource(org.asqatasun.entity.subject.WebResource) List(java.util.List) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)169 Query (javax.persistence.Query)130 EntityManager (javax.persistence.EntityManager)40 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 NonUniqueResultException (javax.persistence.NonUniqueResultException)15 Test (org.junit.Test)14 Transactional (org.springframework.transaction.annotation.Transactional)14 UnitOfWork (com.google.inject.persist.UnitOfWork)12 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 IOException (java.io.IOException)8 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 WebResource (org.asqatasun.entity.subject.WebResource)6 ASException (com.intel.mountwilson.as.common.ASException)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)5 UserAccount (com.jappstart.model.auth.UserAccount)5 List (java.util.List)5 Parameter (org.asqatasun.entity.parameterization.Parameter)5 Transactional (com.google.inject.persist.Transactional)4