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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
Aggregations