use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.
the class StatisticsDAOImpl method findResultCountByResultTypeAndTheme.
/**
* Native sql query :
* SELECT ts.$testSolution FROM THEME_STATISTICS as ts,
* WEB_RESOURCE_STATISTICS as wrs
* WHERE ts.Id_Web_Resource_Statistics=wrs.Id_Web_Resource_Statistics
* AND wrs.Id_Web_Resource=:idWebResource
* AND wrs.Id_Audit=:idAudit
* AND ts.Id_Theme=:idTheme";
*
* where $testSolution is computed on the fly for the given the testSolution
* passed in argument.
*
* @param webResource
* @param audit
* @param testSolution
* @param theme
* @param manualAudit
* @return
* the number of elements for a given result type and theme
*/
@Override
public Long findResultCountByResultTypeAndTheme(WebResource webResource, Audit audit, TestSolution testSolution, Theme theme, boolean manualAudit) {
StringBuilder queryString = new StringBuilder();
queryString.append(SELECT_STR);
queryString.append(THEME_STATISTICS_TABLE_STR);
queryString = selectNbField(queryString, testSolution);
queryString.append(RETRIEVE_COUNT_BY_RESULT_TYPE_AND_THEME_QUERY);
queryString.append(" and wrs.manual_audit = ");
queryString.append(manualAudit ? "1" : "0");
Query query = entityManager.createNativeQuery(queryString.toString());
query.setParameter("idWebResource", webResource.getId());
query.setParameter("idAudit", audit.getId());
query.setParameter("idTheme", theme.getId());
try {
return ((Integer) query.getSingleResult()).longValue();
} catch (NoResultException e) {
return (long) 0;
}
}
use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.
the class OptionElementDAOImpl method findOptionElementFromUser.
@Override
public Collection<OptionElement> findOptionElementFromUser(User user) {
Query query = entityManager.createQuery("SELECT u.optionElementSet FROM " + getUserEntityClass().getName() + " u" + " WHERE u=:user");
query.setParameter("user", user);
try {
return (Collection<OptionElement>) query.getResultList();
} catch (NoResultException | NonUniqueResultException nre) {
return null;
}
}
use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.
the class OptionElementDAOImpl method findOptionElementFromValueAndOption.
/**
*
* @param value
* @param option
* @return
*/
@Override
public OptionElement 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 (OptionElement) query.getSingleResult();
} catch (NoResultException | NonUniqueResultException nre) {
return null;
}
}
use of javax.persistence.NoResultException in project ORCID-Source by ORCID.
the class OrcidSocialDaoImpl method isEnabled.
@Override
public boolean isEnabled(String orcid, OrcidSocialType type) {
Query query = entityManager.createNativeQuery("SELECT * FROM orcid_social WHERE orcid=:orcid AND type=:type");
query.setParameter("orcid", orcid);
query.setParameter("type", type.name());
try {
query.getSingleResult();
return true;
} catch (NoResultException nre) {
return false;
}
}
use of javax.persistence.NoResultException in project ORCID-Source by ORCID.
the class InternalSSODaoImpl method verify.
@Override
public boolean verify(String orcid, String token, Date maxAge) {
Query query = entityManager.createNativeQuery("SELECT count(*) FROM internal_sso WHERE orcid = :orcid AND token = :token AND last_modified >= :maxAge");
query.setParameter("orcid", orcid);
query.setParameter("token", token);
query.setParameter("maxAge", maxAge);
try {
BigInteger result = (BigInteger) query.getSingleResult();
return result.longValue() > 0;
} catch (NoResultException nre) {
}
return false;
}
Aggregations