Search in sources :

Example 56 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project dataverse by IQSS.

the class ExternalToolServiceBean method findById.

public ExternalTool findById(long id) {
    TypedQuery<ExternalTool> typedQuery = em.createQuery("SELECT OBJECT(o) FROM ExternalTool AS o WHERE o.id = :id", ExternalTool.class);
    typedQuery.setParameter("id", id);
    try {
        ExternalTool externalTool = typedQuery.getSingleResult();
        return externalTool;
    } catch (NoResultException | NonUniqueResultException ex) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) NoResultException(javax.persistence.NoResultException) ExternalTool(edu.harvard.iq.dataverse.externaltools.ExternalTool)

Example 57 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project dataverse by IQSS.

the class AuthenticationServiceBean method updateProvider.

/**
 * Associates the passed {@link AuthenticatedUser} with a new provider.
 * @param authenticatedUser the authenticated being re-associated
 * @param authenticationProviderId Id of the new provider
 * @param persistentIdInProvider Id of the user in the new provider
 * @return {@code true} iff the change was successful.
 */
public boolean updateProvider(AuthenticatedUser authenticatedUser, String authenticationProviderId, String persistentIdInProvider) {
    try {
        AuthenticatedUserLookup aul = em.createNamedQuery("AuthenticatedUserLookup.findByAuthUser", AuthenticatedUserLookup.class).setParameter("authUser", authenticatedUser).getSingleResult();
        aul.setAuthenticationProviderId(authenticationProviderId);
        aul.setPersistentUserId(persistentIdInProvider);
        actionLogSvc.log(new ActionLogRecord(ActionLogRecord.ActionType.Auth, authenticatedUser.getIdentifier() + " now associated with provider " + authenticationProviderId + " id: " + persistentIdInProvider));
        return true;
    } catch (NoResultException | NonUniqueResultException ex) {
        logger.log(Level.WARNING, "Error converting user " + authenticatedUser.getUserIdentifier() + ": " + ex.getMessage(), ex);
        return false;
    }
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) NonUniqueResultException(javax.persistence.NonUniqueResultException) NoResultException(javax.persistence.NoResultException)

Example 58 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project dataverse by IQSS.

the class PrivateUrlServiceBean method getRoleAssignmentFromPrivateUrlToken.

/**
 * @return A RoleAssignment or null.
 *
 * @todo This might be a good place for Optional.
 */
private RoleAssignment getRoleAssignmentFromPrivateUrlToken(String privateUrlToken) {
    if (privateUrlToken == null) {
        return null;
    }
    TypedQuery<RoleAssignment> query = em.createNamedQuery("RoleAssignment.listByPrivateUrlToken", RoleAssignment.class);
    query.setParameter("privateUrlToken", privateUrlToken);
    try {
        RoleAssignment roleAssignment = query.getSingleResult();
        return roleAssignment;
    } catch (NoResultException | NonUniqueResultException ex) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) NoResultException(javax.persistence.NoResultException)

Example 59 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project oozie by apache.

the class TestPersistenceExceptionSubclassFilterRetryPredicate method testNestedFilteredJPAExceptions.

@Test
public void testNestedFilteredJPAExceptions() {
    assertFalse(predicate.test(wrapCause(new EntityExistsException())));
    assertFalse(predicate.test(wrapCause(new EntityNotFoundException())));
    assertFalse(predicate.test(wrapCause(new LockTimeoutException())));
    assertFalse(predicate.test(wrapCause(new NoResultException())));
    assertFalse(predicate.test(wrapCause(new NonUniqueResultException())));
    assertFalse(predicate.test(wrapCause(new OptimisticLockException())));
    assertFalse(predicate.test(wrapCause(new PessimisticLockException())));
    assertFalse(predicate.test(wrapCause(new QueryTimeoutException())));
    assertFalse(predicate.test(wrapCause(new TransactionRequiredException())));
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) QueryTimeoutException(javax.persistence.QueryTimeoutException) TransactionRequiredException(javax.persistence.TransactionRequiredException) OptimisticLockException(javax.persistence.OptimisticLockException) EntityNotFoundException(javax.persistence.EntityNotFoundException) NoResultException(javax.persistence.NoResultException) EntityExistsException(javax.persistence.EntityExistsException) LockTimeoutException(javax.persistence.LockTimeoutException) PessimisticLockException(javax.persistence.PessimisticLockException) Test(org.junit.Test)

Example 60 with NonUniqueResultException

use of javax.persistence.NonUniqueResultException in project joynr by bmwcarit.

the class DataAccess method findGetResultForMessageId.

public Optional<GetResult> findGetResultForMessageId(String messageId) {
    Query query = entityManager.createQuery("select gr from GetResult gr where gr.messageId = :messageId");
    query.setParameter("messageId", messageId);
    List<GetResult> resultList = query.getResultList();
    logger.trace("Get result for {}:\n{}", messageId, resultList);
    if (resultList.isEmpty()) {
        return Optional.empty();
    }
    if (resultList.size() > 1) {
        throw new NonUniqueResultException("Several entities found with messageId: " + messageId);
    }
    return Optional.of(resultList.get(0));
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) Query(javax.persistence.Query)

Aggregations

NonUniqueResultException (javax.persistence.NonUniqueResultException)71 NoResultException (javax.persistence.NoResultException)56 Query (javax.persistence.Query)30 EntityManager (javax.persistence.EntityManager)11 List (java.util.List)7 PersistenceException (javax.persistence.PersistenceException)6 Collection (java.util.Collection)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 QueryBuilder (org.meveo.commons.utils.QueryBuilder)5 IOException (java.io.IOException)4 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 EntityExistsException (javax.persistence.EntityExistsException)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 OptimisticLockException (javax.persistence.OptimisticLockException)3 TransactionRequiredException (javax.persistence.TransactionRequiredException)3 TypedQuery (javax.persistence.TypedQuery)3 WebResource (org.asqatasun.entity.subject.WebResource)3 PopulationDataCriteria (de.symeda.sormas.api.infrastructure.PopulationDataCriteria)2