Search in sources :

Example 21 with NoResultException

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;
    }
}
Also used : BigInteger(java.math.BigInteger) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 22 with NoResultException

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;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) Collection(java.util.Collection) NoResultException(javax.persistence.NoResultException)

Example 23 with NoResultException

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;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query) OptionElement(org.asqatasun.webapp.entity.option.OptionElement) NoResultException(javax.persistence.NoResultException)

Example 24 with NoResultException

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;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 25 with NoResultException

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;
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) BigInteger(java.math.BigInteger) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)356 Query (javax.persistence.Query)205 EntityManager (javax.persistence.EntityManager)69 NonUniqueResultException (javax.persistence.NonUniqueResultException)33 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)25 TypedQuery (javax.persistence.TypedQuery)22 Transactional (org.springframework.transaction.annotation.Transactional)20 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19 Test (org.junit.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Session (org.hibernate.Session)13 UnitOfWork (com.google.inject.persist.UnitOfWork)12 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)11 PersistenceException (javax.persistence.PersistenceException)11 Date (java.util.Date)9 NotFoundException (org.opencastproject.util.NotFoundException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 List (java.util.List)8 NamedQuery (javax.persistence.NamedQuery)8