当前位置: 首页>>代码示例>>Java>>正文


Java IncorrectResultSizeDataAccessException.getActualSize方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:29,代码来源:LdapFullDnSearch.java

示例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);
	}
}
 
开发者ID:gustajz,项目名称:parking-api,代码行数:26,代码来源:ActiveDirectoryAliasLdapAuthenticationProvider.java

示例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;
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:42,代码来源:KerberosFilterBasedLdapUserSearch.java

示例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.");
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:31,代码来源:CommunoteLdapUserSearch.java

示例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;
		}
	}
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:16,代码来源:AnnotationDaoImpl.java

示例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;
		}
	}
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:16,代码来源:AnnotationDaoImpl.java

示例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;
    }
}
 
开发者ID:nortal,项目名称:petit,代码行数:18,代码来源:SqlSupport.java

示例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;
    }
}
 
开发者ID:nortal,项目名称:petit,代码行数:16,代码来源:SqlSupport.java

示例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;
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:29,代码来源:JdbcEventdServiceManager.java


注:本文中的org.springframework.dao.IncorrectResultSizeDataAccessException.getActualSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。