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