當前位置: 首頁>>代碼示例>>Java>>正文


Java IncorrectResultSizeDataAccessException類代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:29,代碼來源:LdapFullDnSearch.java

示例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());
    }
}
 
開發者ID:snowdrop,項目名稱:spring-data-snowdrop,代碼行數:17,代碼來源:OpsDefaultBase.java

示例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);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:SqlTaxonomyDataSource.java

示例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;
		}
	});
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:SqlTaxonomyDataSource.java

示例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());
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:DataAccessUtilsTests.java

示例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);
	}
}
 
開發者ID:gustajz,項目名稱:parking-api,代碼行數:26,代碼來源:ActiveDirectoryAliasLdapAuthenticationProvider.java

示例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);
}
 
開發者ID:dlcs,項目名稱:elucidate-server,代碼行數:19,代碼來源:AnnotationCollectionStoreRepositoryJDBCImplTest.java

示例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);
}
 
開發者ID:dlcs,項目名稱:elucidate-server,代碼行數:20,代碼來源:AnnotationStoreRepositoryJDBCImplTest.java

示例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);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:19,代碼來源:KRADLegacyDataAdapterImpl.java

示例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);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:18,代碼來源:ProviderBasedDataObjectServiceTest.java

示例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);
	}
}
 
開發者ID:RBGKew,項目名稱:eMonocot,代碼行數:30,代碼來源:UserServiceImpl.java

示例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);
 }
}
 
開發者ID:RBGKew,項目名稱:eMonocot,代碼行數:27,代碼來源:UserServiceImpl.java

示例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();
                }
            }
        }
    });
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:25,代碼來源:CobarAdapter.java

示例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;
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:40,代碼來源:DataAccessUtils.java

示例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;
}
 
開發者ID:OlegNyr,項目名稱:GisGMP,代碼行數:26,代碼來源:MemberRepositoryImpl.java


注:本文中的org.springframework.dao.IncorrectResultSizeDataAccessException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。