/** * Handle the case where the ResultSet does not contain a row. * @throws DataAccessException a corresponding exception, * by default an EmptyResultDataAccessException * @see org.springframework.dao.EmptyResultDataAccessException */ protected void handleNoRowFound() throws DataAccessException { throw new EmptyResultDataAccessException( "LobStreamingResultSetExtractor did not find row in database", 1); }
@Test public void testWriteAndFlushWithEmptyUpdate() throws Exception { ps.addBatch(); when(ps.executeBatch()).thenReturn(new int[] { 0 }); try { writer.write(Collections.singletonList("bar")); fail("Expected EmptyResultDataAccessException"); } catch (EmptyResultDataAccessException e) { // expected String message = e.getMessage(); assertTrue("Wrong message: " + message, message.indexOf("did not update") >= 0); } assertEquals(2, list.size()); assertTrue(list.contains("SQL")); }
@Override public Response toResponse(final EmptyResultDataAccessException exception) { return toResponseNotFound(exception.getCause()); }
/** * Return a single result object from the given Collection. * <p>Throws an exception if 0 or more than 1 element found. * @param results the result Collection (can be {@code null} * but is not expected to contain {@code null} elements) * @return the single result object * @throws IncorrectResultSizeDataAccessException if more than one * element has been found in the given Collection * @throws EmptyResultDataAccessException if no element at all * has been found in the given Collection */ public static <T> T requiredSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException { if (CollectionUtils.isEmpty(results)) { throw new EmptyResultDataAccessException(1); } if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
@Test public void testWriteAndFlushWithEmptyUpdate() throws Exception { when(namedParameterJdbcOperations.batchUpdate(eq(sql), eqSqlParameterSourceArray(new SqlParameterSource[] {new BeanPropertySqlParameterSource(new Foo("bar"))}))) .thenReturn(new int[] {0}); try { writer.write(Collections.singletonList(new Foo("bar"))); fail("Expected EmptyResultDataAccessException"); } catch (EmptyResultDataAccessException e) { // expected String message = e.getMessage(); assertTrue("Wrong message: " + message, message.contains("did not update")); } }
/** * Return a single result object from the given Collection. * <p>Throws an exception if 0 or more than 1 element found. * @param results the result Collection (can be {@code null} * and is also expected to contain {@code null} elements) * @return the single result object * @throws IncorrectResultSizeDataAccessException if more than one * element has been found in the given Collection * @throws EmptyResultDataAccessException if no element at all * has been found in the given Collection * @since 5.0.2 */ @Nullable public static <T> T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException { // This is identical to the requiredSingleResult implementation but differs in the // semantics of the incoming Collection (which we currently can't formally express) if (CollectionUtils.isEmpty(results)) { throw new EmptyResultDataAccessException(1); } if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
@Override public IdentityZone retrieveBySubdomain(String subdomain) { if (subdomain==null) { throw new EmptyResultDataAccessException("Subdomain cannot be null", 1); } IdentityZone identityZone = jdbcTemplate.queryForObject(IDENTITY_ZONE_BY_SUBDOMAIN_QUERY, mapper, subdomain.toLowerCase(), true); return identityZone; }
/** * Return a unique result object from the given Collection. * <p>Throws an exception if 0 or more than 1 instance found. * @param results the result Collection (can be {@code null} * but is not expected to contain {@code null} elements) * @return the unique result object * @throws IncorrectResultSizeDataAccessException if more than one * result object has been found in the given Collection * @throws EmptyResultDataAccessException if no result object at all * has been found in the given Collection * @see org.springframework.util.CollectionUtils#hasUniqueObject */ public static <T> T requiredUniqueResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException { if (CollectionUtils.isEmpty(results)) { throw new EmptyResultDataAccessException(1); } if (!CollectionUtils.hasUniqueObject(results)) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
/** * Return a single result object from the given Collection. * <p>Throws an exception if 0 or more than 1 element found. * @param results the result Collection (can be {@code null} * but is not expected to contain {@code null} elements) * @return the single result object * @throws IncorrectResultSizeDataAccessException if more than one * element has been found in the given Collection * @throws EmptyResultDataAccessException if no element at all * has been found in the given Collection */ public static <T> T requiredSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException { if (CollectionUtils.isEmpty(results)) { throw new EmptyResultDataAccessException(1); } if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
@Transactional @Override public void deleteById(ID id) { Assert.notNull(id, ID_MUST_NOT_BE_NULL); delete(findById(id).orElseThrow(() -> new EmptyResultDataAccessException( String.format("No %s entity with id %s exists!", entityInformation.getJavaType(), id), 1))); }
/** * Return a single result object from the given Collection. * <p>Throws an exception if 0 or more than 1 element found. * @param results the result Collection (can be {@code null} * and is also expected to contain {@code null} elements) * @return the single result object * @throws IncorrectResultSizeDataAccessException if more than one * element has been found in the given Collection * @throws EmptyResultDataAccessException if no element at all * has been found in the given Collection * @since 5.0.2 */ @Nullable public static <T> T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException { // This is identical to the requiredSingleResult implementation but differs in the // semantics of the incoming Collection (which we currently can't formally express) if (CollectionUtils.isEmpty(results)) { throw new EmptyResultDataAccessException(1); } if (results.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
/** * Return a unique result object from the given Collection. * <p>Throws an exception if 0 or more than 1 instance found. * @param results the result Collection (can be {@code null} * but is not expected to contain {@code null} elements) * @return the unique result object * @throws IncorrectResultSizeDataAccessException if more than one * result object has been found in the given Collection * @throws EmptyResultDataAccessException if no result object at all * has been found in the given Collection * @see org.springframework.util.CollectionUtils#hasUniqueObject */ public static <T> T requiredUniqueResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException { if (CollectionUtils.isEmpty(results)) { throw new EmptyResultDataAccessException(1); } if (!CollectionUtils.hasUniqueObject(results)) { throw new IncorrectResultSizeDataAccessException(1, results.size()); } return results.iterator().next(); }
return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
@Override public boolean addApproval(final Approval approval, final String zoneId) { logger.debug(String.format("adding approval: [%s]", approval)); try { refreshApproval(approval, IdentityZoneHolder.get().getId()); // try to refresh the approval } catch (DataIntegrityViolationException ex) { // could not find the // approval. add it. int count = jdbcTemplate.update(ADD_AUTHZ_SQL, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, approval.getUserId()); ps.setString(2, approval.getClientId()); ps.setString(3, approval.getScope()); ps.setTimestamp(4, new Timestamp(approval.getExpiresAt().getTime())); ps.setString(5, (approval.getStatus() == null ? APPROVED : approval.getStatus()).toString()); ps.setTimestamp(6, new Timestamp(approval.getLastUpdatedAt().getTime())); ps.setString(7, zoneId); } }); if (count == 0) throw new EmptyResultDataAccessException("Approval add failed", 1); } Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); publish(new ApprovalModifiedEvent(approval, authentication)); return true; }
public RevocableToken retrieve(String id, boolean checkExpired, String zoneId) { if (checkExpired) { checkExpired(); } RevocableToken result = template.queryForObject(GET_QUERY, rowMapper, id, zoneId); if (checkExpired && result.getExpiresAt() < timeService.getCurrentTimeMillis()) { delete(id, 0, zoneId); throw new EmptyResultDataAccessException("Token expired.", 1); } return result; }
int value = updateCounts[i]; if (value == 0) { throw new EmptyResultDataAccessException("Item " + i + " of " + updateCounts.length + " did not update any rows: [" + items.get(i) + "]", 1);
return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
@Test(expected = UnauthorizedClientException.class) public void testClientIDPAuthorizationInUAAzoneEmptyResultSetException() { when(providerProvisioning.retrieveByOrigin(anyString(), anyString())).thenThrow(new EmptyResultDataAccessException(1)); client.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, Arrays.asList("random2")); factory.checkClientIdpAuthorization(client, user); }
@Test public void validate_disabled_no_provider_id() throws InvalidIdentityZoneConfigurationException { when(provisioning.retrieveByName(anyString(), anyString())).thenThrow(new EmptyResultDataAccessException(1)); MfaConfig configuration = new MfaConfig().setEnabled(false).setProviderName(""); validator.validate(configuration, "some-zone"); }
@Test public void nonRevocableToken() { revocableTokenProvisioning = mock(RevocableTokenProvisioning.class); when(revocableTokenProvisioning.retrieve("8b14f193-8212-4af2-9927-e3ae903f94a6", IdentityZoneHolder.get().getId())) .thenThrow(new EmptyResultDataAccessException(1)); // should not occur content.remove("revocable"); buildAccessTokenValidator(getToken(), new KeyInfoService("https://localhost")) .checkRevocableTokenStore(revocableTokenProvisioning); verifyZeroInteractions(revocableTokenProvisioning); }