本文整理汇总了Java中org.springframework.dao.IncorrectResultSizeDataAccessException类的典型用法代码示例。如果您正苦于以下问题:Java IncorrectResultSizeDataAccessException类的具体用法?Java IncorrectResultSizeDataAccessException怎么用?Java IncorrectResultSizeDataAccessException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IncorrectResultSizeDataAccessException类属于org.springframework.dao包,在下文中一共展示了IncorrectResultSizeDataAccessException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchForUser
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
/**
* Return the DirContextOperations containing the user's information
*
* @param dn full DN of the user to search for.
*
* @return An DirContextOperations object containing the details of the located user's
* directory entry
*
* @throws UsernameNotFoundException if no matching entry is found.
*/
@Override
public DirContextOperations searchForUser(String dn) {
log.debug("Searching for dn '{}'.", dn);
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(getContextSource());
template.setSearchControls(getSearchControls());
try {
return template.retrieveEntry(dn, null);
} catch (IncorrectResultSizeDataAccessException ex) {
if (ex.getActualSize() == 0) {
throw new UsernameNotFoundException("User " + dn + " not found in directory.");
}
// Search should never return multiple results if properly configured, so just rethrow
throw ex;
}
}
示例2: testOptional
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Test
public void testOptional() {
Optional<SimpleEntity> optional = repository.findByNumberBetweenOrderByHero(9, 11);
Assert.assertTrue(optional.isPresent());
Assert.assertEquals(new Long(4), optional.get().getId());
optional = repository.findByNumberBetweenOrderByHero(1234, 2000);
Assert.assertFalse(optional.isPresent());
try {
repository.findByNumberBetweenOrderByHero(-5, 15);
Assert.fail();
} catch (Exception e) {
Assert.assertEquals(IncorrectResultSizeDataAccessException.class, e.getClass());
}
}
示例3: getTerm
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Override
public TermResult getTerm(String fullTermPath)
{
List<TermResult> trs = executeListQuery(queryGetTerm, Collections.singletonMap("term", fullTermPath));
if( Check.isEmpty(trs) )
{
return null;
}
else if( trs.size() == 1 )
{
return trs.get(0);
}
else
{
// Sanity check - ensure only a single result
throw new IncorrectResultSizeDataAccessException(1);
}
}
示例4: executeSingleResultQuery
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
private Object executeSingleResultQuery(String query, Map<?, ?> params)
{
return jdbcTemplate.query(query, params, new ResultSetExtractor()
{
@Override
public Object extractData(ResultSet rs) throws SQLException, DataAccessException
{
Object data = null;
if( rs.next() )
{
data = rs.getObject(1);
// Sanity check - ensure only a single result
if( rs.next() )
{
throw new IncorrectResultSizeDataAccessException(1);
}
}
return data;
}
});
}
示例5: withEquivalentIntegerInstanceTwice
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Test
public void withEquivalentIntegerInstanceTwice() {
Collection<Integer> col = new ArrayList<Integer>(2);
col.add(new Integer(5));
col.add(new Integer(5));
try {
DataAccessUtils.uniqueResult(col);
fail("Should have thrown IncorrectResultSizeDataAccessException");
}
catch (IncorrectResultSizeDataAccessException ex) {
// expected
assertEquals(1, ex.getExpectedSize());
assertEquals(2, ex.getActualSize());
}
}
示例6: searchForUser
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
private DirContextOperations searchForUser(DirContext context, String username)
throws NamingException {
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String bindPrincipal = createBindPrincipalDomainAlias(username);
String searchRoot = rootDn != null ? rootDn : searchRootFromPrincipal(bindPrincipal);
try {
return SpringSecurityLdapTemplate.searchForSingleEntryInternal(context,
searchControls, searchRoot, searchFilter,
new Object[] { bindPrincipal });
}
catch (IncorrectResultSizeDataAccessException incorrectResults) {
// Search should never return multiple results if properly configured - just
// rethrow
if (incorrectResults.getActualSize() != 0) {
throw incorrectResults;
}
// If we found no results, then the username/password did not match
UsernameNotFoundException userNameNotFoundException = new UsernameNotFoundException(
"User " + username + " not found in directory.", incorrectResults);
throw badCredentials(userNameNotFoundException);
}
}
示例7: testGetAnnotationCollectionByIdTwo
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Test(expected = IncorrectResultSizeDataAccessException.class)
@SuppressWarnings("serial")
public void testGetAnnotationCollectionByIdTwo() {
W3CAnnotationCollection w3cAnnotationCollection = generateRandomW3CAnnotationCollection();
String collectionId = w3cAnnotationCollection.getCollectionId();
Object[] params = {collectionId, false};
int[] sqlTypes = {Types.VARCHAR, Types.BOOLEAN};
when(jdbcTemplate.query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationCollectionRowMapper) any())).thenReturn(new ArrayList<W3CAnnotationCollection>() {
{
add(w3cAnnotationCollection);
add(w3cAnnotationCollection);
}
});
annotationCollectionStoreRepository.getAnnotationCollectionById(collectionId);
}
示例8: testGetAnnotationByCollectionIdAndAnnotationIdTwo
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test(expected = IncorrectResultSizeDataAccessException.class)
public void testGetAnnotationByCollectionIdAndAnnotationIdTwo() {
W3CAnnotation w3cAnnotation = generateRandomW3CAnnotation();
String collectionId = generateRandomId();
String annotationId = generateRandomId();
Object[] params = {collectionId, annotationId, false};
int[] sqlTypes = {Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN};
when(jdbcTemplate.query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any())).thenReturn(new ArrayList<W3CAnnotation>() {
{
add(w3cAnnotation);
add(w3cAnnotation);
}
});
annotationStoreRepository.getAnnotationByCollectionIdAndAnnotationId(collectionId, annotationId);
}
示例9: findObjectBySearch
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Override
public <T> T findObjectBySearch(Class<T> type, Map<String, String> formProps) {
// This is the strictly Lookup-compatible way of constructing the criteria
// from a map of properties, which performs some minor logic such as only including
// non-blank and "writable" properties, as well as minor type coercions of string values
QueryByCriteria.Builder queryByCriteria = lookupCriteriaGenerator.createObjectCriteriaFromMap(type, formProps);
List<T> results = dataObjectService.findMatching(type, queryByCriteria.build()).getResults();
if (results.isEmpty()) {
return null;
}
if (results.size() != 1) {
// this behavior is different from the legacy OJB behavior in that it throws an exception if more than
// one result from such a single object query
throw new IncorrectResultSizeDataAccessException("Incorrect number of results returned when finding object",
1, results.size());
}
return results.get(0);
}
示例10: testFindUnique_TooManyResults
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Test(expected = IncorrectResultSizeDataAccessException.class)
public void testFindUnique_TooManyResults() {
QueryByCriteria criteria = QueryByCriteria.Builder.create().build();
// create results that contains multiple objects
Object result1 = new Object();
Object result2 = new Object();
GenericQueryResults.Builder<Object> resultsBuilder =
GenericQueryResults.Builder.<Object>create();
resultsBuilder.setResults(Lists.newArrayList(result1, result2));
QueryResults<Object> results = resultsBuilder.build();
when(mockProvider.findMatching(Object.class, criteria)).thenReturn(results);
// now when we invoke this, we should get the data access exception
// (see the "expected" exception on the @Test annotation)
service.findUnique(Object.class, criteria);
}
示例11: changePasswordForUser
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
/**
*
* @param username Set the username
* @param newPassword Set the new password
*/
@Transactional(readOnly = false)
public final void changePasswordForUser(final String username,
final String newPassword) {
Assert.hasText(username);
Assert.hasText(newPassword);
try {
User user = dao.find(username);
if (user == null) {
throw new UsernameNotFoundException(username);
}
Object salt = this.saltSource.getSalt(user);
String password = passwordEncoder.encodePassword(newPassword, salt);
((User) user).setPassword(password);
dao.update((User) user);
userCache.removeUserFromCache(user.getUsername());
} catch (NonUniqueResultException nure) {
throw new IncorrectResultSizeDataAccessException(
"More than one user found with name '" + username + "'", 1);
}
}
示例12: loadUserByUsername
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
/**
* DO NOT CALL THIS METHOD IN LONG RUNNING SESSIONS OR CONVERSATIONS A
* THROWN UsernameNotFoundException WILL RENDER THE CONVERSATION UNUSABLE.
*
* @param username
* Set the username
* @return the userdetails of the user
*/
@Transactional(readOnly = true)
public final UserDetails loadUserByUsername(final String username) {
try {
Assert.hasText(username);
} catch (IllegalArgumentException iae) {
throw new UsernameNotFoundException(username, iae);
}
try {
User user = dao.load(username);
userCache.putUserInCache(user);
return user;
} catch (ObjectRetrievalFailureException orfe) {
throw new UsernameNotFoundException(username, orfe);
} catch (NonUniqueResultException nure) {
throw new IncorrectResultSizeDataAccessException(
"More than one user found with name '" + username + "'", 1);
}
}
示例13: getCurrentTimeMillis
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Override
public Pair<Long, Long> getCurrentTimeMillis() {
return (Pair<Long, Long>) getJdbcTemplate().execute(new StatementCallback() {
@Override
public Object doInStatement(Statement stmt) throws SQLException, DataAccessException {
ResultSet rs = null;
try {
long time1 = System.currentTimeMillis();
rs = stmt.executeQuery("show @@status.time");
long time2 = System.currentTimeMillis();
if (rs.next()) {
return new Pair<Long, Long>(time1 + (time2 - time1) / 2, rs.getLong(1));
} else {
throw new IncorrectResultSizeDataAccessException(1, 0);
}
} finally {
if (rs != null) {
rs.close();
}
}
}
});
}
示例14: objectResult
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
/**
* Return a unique result object from the given Collection.
* Throws an exception if 0 or more than 1 result objects found,
* of if the unique result object is not convertable to the
* specified required type.
* @param results the result Collection (can be {@code null})
* @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
* @throws TypeMismatchDataAccessException if the unique object does
* not match the specified required type
*/
@SuppressWarnings("unchecked")
public static <T> T objectResult(Collection<?> results, Class<T> requiredType)
throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException {
Object result = requiredUniqueResult(results);
if (requiredType != null && !requiredType.isInstance(result)) {
if (String.class.equals(requiredType)) {
result = result.toString();
}
else if (Number.class.isAssignableFrom(requiredType) && Number.class.isInstance(result)) {
try {
result = NumberUtils.convertNumberToTargetClass(((Number) result), (Class<? extends Number>) requiredType);
}
catch (IllegalArgumentException ex) {
throw new TypeMismatchDataAccessException(ex.getMessage());
}
}
else {
throw new TypeMismatchDataAccessException(
"Result object is of type [" + result.getClass().getName() +
"] and could not be converted to required type [" + requiredType.getName() + "]");
}
}
return (T) result;
}
示例15: getTokenForSeries
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入依赖的package包/类
@Override
public PersistentRememberMeToken getTokenForSeries(String seriesId) {
try {
return getJdbcTemplate().queryForObject(sqlSelect, new RowMapper<PersistentRememberMeToken>() {
public PersistentRememberMeToken mapRow(ResultSet rs, int rowNum) throws SQLException {
//String username, String series, String tokenValue, Date date
return new PersistentRememberMeToken(rs.getString(3),
rs.getString(1),
rs.getString(2),
rs.getTimestamp(4));
}
}, seriesId);
} catch (EmptyResultDataAccessException zeroResults) {
if (logger.isInfoEnabled()) {
logger.info("Querying token for series '" + seriesId + "' returned no results.", zeroResults);
}
} catch (IncorrectResultSizeDataAccessException moreThanOne) {
logger.error("Querying token for series '" + seriesId + "' returned more than one value. Series" +
" should be unique");
} catch (DataAccessException e) {
logger.error("Failed to load token for series " + seriesId, e);
}
return null;
}