本文整理汇总了Java中org.springframework.dao.IncorrectResultSizeDataAccessException.getActualSize方法的典型用法代码示例。如果您正苦于以下问题:Java IncorrectResultSizeDataAccessException.getActualSize方法的具体用法?Java IncorrectResultSizeDataAccessException.getActualSize怎么用?Java IncorrectResultSizeDataAccessException.getActualSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.dao.IncorrectResultSizeDataAccessException
的用法示例。
在下文中一共展示了IncorrectResultSizeDataAccessException.getActualSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例3: searchForUser
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入方法依赖的package包/类
/**
* Return the DirContextOperations containing the user's information
*
* @param username the kerberos username 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.
*/
public DirContextOperations searchForUser(String username) {
String[] data = username.split("@");
eq(data.length, 2, () -> new UsernameNotFoundException("Wrong username format for " + username));
String accountName = data[0];
String domainName = data[1];
String[] domainData = domainName.split("\\.");
String searchBase = Stream.of(domainData)
.map(part -> "dc=" + part)
.collect(Collectors.joining(","));
log.debug("Searching for user '{}' in '{}', with user search {}.", accountName, searchBase, this);
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(getContextSource());
template.setSearchControls(getSearchControls());
try {
return template.searchForSingleEntry(searchBase, getSearchFilter(), new String[] { accountName });
} catch (IncorrectResultSizeDataAccessException ex) {
if (ex.getActualSize() == 0) {
throw new UsernameNotFoundException("User " + username + " not found in directory.");
}
// Search should never return multiple results if properly configured, so just rethrow
throw ex;
}
}
示例4: searchForUser
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public DirContextOperations searchForUser(String username) {
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(
initialDirContextFactory);
List<LdapSearchBaseDefinition> searchBaseDefs = userSearchConfig.getSearchBases();
String[] params = { LdapUtils.escapeLdapSearchFilterValue(username) };
SearchControls searchControls = new SearchControls();
template.setSearchControls(searchControls);
searchControls.setReturningAttributes(userAttributesMapper.getMappedLdapAttributeNames());
for (LdapSearchBaseDefinition searchBase : searchBaseDefs) {
searchControls
.setSearchScope(searchBase.isSearchSubtree() ? SearchControls.SUBTREE_SCOPE
: SearchControls.ONELEVEL_SCOPE);
try {
return template.searchForSingleEntry(searchBase.getSearchBase(), userSearchFilter,
params);
} catch (IncorrectResultSizeDataAccessException e) {
// ignore no results case to allow checking other search bases
if (e.getActualSize() != 0) {
// Search should never return multiple results if properly configured, so just
// rethrow
throw e;
}
}
}
throw new UsernameNotFoundException("User " + username + " not found in directory.");
}
示例5: findAnnotation
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入方法依赖的package包/类
@Override
public Annotation findAnnotation(RecordType recordType, Long id, Long jobId) {
try {
Object[] args = new Object[] {id, "Taxon", jobId};
int[] argTypes = new int[] {Types.BIGINT, Types.VARCHAR, Types.BIGINT};
Long annotationId = jdbcTemplate.queryForLong("Select a.id from Annotation a where a.annotatedObjId = ? and a.annotatedObjType = ? and a.jobId = ?", args, argTypes);
return (Annotation) getSession().load(Annotation.class, annotationId);
} catch(IncorrectResultSizeDataAccessException irsdae) {
if(irsdae.getActualSize() == 0) {
return null;
} else {
throw irsdae;
}
}
}
示例6: findAnnotation
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入方法依赖的package包/类
@Override
public Annotation findAnnotation(RecordType recordType, Long id, Long jobId) {
try {
Object[] args = new Object[] {id, "Taxon", jobId};
int[] argTypes = new int[] {Types.BIGINT, Types.VARCHAR, Types.BIGINT};
Long annotationId = jdbcTemplate.queryForObject("Select a.id from Annotation a where a.annotatedObjId = ? and a.annotatedObjType = ? and a.jobId = ?", args, argTypes, Long.class);
return (Annotation) getSession().load(Annotation.class, annotationId);
} catch(IncorrectResultSizeDataAccessException irsdae) {
if(irsdae.getActualSize() == 0) {
return null;
} else {
throw irsdae;
}
}
}
示例7: getObject
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入方法依赖的package包/类
/**
* Queries for a single string object.
*
* @return null when no result is provided, exception is thrown when more
* that 1 result is provided
*/
public <T> T getObject(String sql, RowMapper<T> rowMapper, Object... args) {
try {
return getJdbcTemplate().queryForObject(sql, rowMapper, args);
} catch (IncorrectResultSizeDataAccessException e) {
if (e.getActualSize() == 0) {
return null;
}
// else
throw e;
}
}
示例8: getPrimitiveObject
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入方法依赖的package包/类
/**
* @return null when no result is provided, exception is thrown when more
* that 1 result is provided
*/
private <T> T getPrimitiveObject(String sql, Class<T> clazz, Object... args) {
try {
return getJdbcTemplate().queryForObject(sql, clazz, args);
} catch (IncorrectResultSizeDataAccessException e) {
if (e.getActualSize() == 0) {
return null;
}
// else
throw e;
}
}
示例9: getServiceId
import org.springframework.dao.IncorrectResultSizeDataAccessException; //导入方法依赖的package包/类
/** {@inheritDoc} */
public synchronized int getServiceId(String serviceName) throws DataAccessException {
Assert.notNull(serviceName, "The serviceName argument must not be null");
if (m_serviceMap.containsKey(serviceName)) {
return m_serviceMap.get(serviceName).intValue();
} else {
log().debug("Could not find entry for '" + serviceName + "' in service name cache. Looking up in database.");
int serviceId;
try {
serviceId = new JdbcTemplate(m_dataSource).queryForInt("SELECT serviceID FROM service WHERE serviceName = ?", new Object[] { serviceName });
} catch (IncorrectResultSizeDataAccessException e) {
if (e.getActualSize() == 0) {
log().debug("Did not find entry for '" + serviceName + "' in database.");
return -1; // not found
} else {
throw e; // more than one found... WTF?!?!
}
}
m_serviceMap.put(serviceName, serviceId);
log().debug("Found entry for '" + serviceName + "' (ID " + serviceId + ") in database. Adding to service name cache.");
return serviceId;
}
}