简体   繁体   English

Java DirContext片段仅记录几条

[英]Java DirContext sreach only few records

When I try to search records by using query (testAtt=1) in Apache Directory Studio they showing me 17062 records and when I run the same query on my Java code they get only 8531 records. 当我尝试在Apache Directory Studio中使用查询(testAtt=1)搜索记录时,它们显示了17062条记录,而当我在Java代码上运行相同的查询时,它们仅获得了8531条记录。 My Java Code is given below 我的Java代码如下

String searchFilter = propFile.getProperty(Constants.GetAllUsersQuery);
String ldapSearchBase = propFile.getProperty(Constants.eDir_SearchBase);
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> resultsApp = ctx.search(ldapSearchBase, searchFilter, searchControls);
int i = 0;
while (resultsApp.hasMoreElements()) {
    SearchResult result = (SearchResult) resultsApp.next();
    String DN = "";
    DN = result.getNameInNamespace();
    if (!DN.isEmpty()) {
        eDir_AllUsersDNList.add(i, DN);
        i++;
    }
    resultsApp.nextElement();
}

System.out.println("eDir_AllUsersDNList : "+eDir_AllUsersDNList.size());

Please help me to find out the issue. 请帮助我找出问题所在。 I am using Java 8. 我正在使用Java 8。

while (resultsApp.hasMoreElements()) {
    SearchResult result = (SearchResult) resultsApp.next();
    String DN = "";
    DN = result.getNameInNamespace();
    if (!DN.isEmpty()) {
        eDir_AllUsersDNList.add(i, DN);
        i++;
    }
    resultsApp.nextElement();
}

Remove the final nextElement() call. 删除最后的nextElement()调用。 It is doing nothing useful, and it is skipping all the even-numbered elements. 它无济于事,并且跳过了所有偶数元素。 Note that 8531 is half of 17062. 请注意,8531是17062的一半。

NB the cast is redundant, and the DN can't be empty, and providing an initializer for it when you assign it on the very next line is pointless. 注意,强制转换是多余的,并且DN不能为空,并且在下一行分配它时为其提供初始化程序是没有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM