【问题标题】:JAVA LDAP - all data retrievalJAVA LDAP - 所有数据检索
【发布时间】:2015-09-13 06:15:31
【问题描述】:

我的 LDAP 的人员条目超过 100,000,但是当我输入搜索查询时,我只 收到 2000 个条目。

SearchControls constraints = new SearchControls();
            constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
            constraints.setCountLimit(1);//pageSize
            NamingEnumeration<SearchResult> results = ctx.search("DC=YourDomain,DC=com", filterQuery, constraints);
            while (results != null && results.hasMore()) {
                person = new Person();
                Attributes attrs = ((SearchResult) results.next()).getAttributes();
                person.setEmail(attrs.get("email").toString());
                person.setEmployee_id(attrs.get("employee_id").toString());
                person.setGuid(attrs.get("guid").toString());
                person.setId(Integer.parseInt(attrs.get("id").toString()));
                person.setName(attrs.get("name").toString());
                person.setPhone(attrs.get("phone").toString());
                person.setPpid(attrs.get("ppid").toString());
                result.add(person);
            }

抛出异常 -

javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded];

【问题讨论】:

  • results 在您测试它时不可能为空。

标签: java ldap jndi


【解决方案1】:

javax.naming.SizeLimitExceededException 表示您已超出大小相关限制,该限制可以由您在搜索选项中设置,也可以由 LDAP 实现设置。

您已指定 constraints.setCountLimit(1);,这表明您只要求一个结果(请参阅 javadoc here)。 0 的值表示对象检索没有限制。

我不知道它为什么要检索 2000 个条目,但是您可以尝试输入 0 并查看它是否有效,否则,您将不得不查看 LDAP 服务器配置,因为它可以忽略 constraints.setCountLimit选项。

【讨论】:

    【解决方案2】:

    Java 或者更可能是服务器限制了您一次可以检索的搜索结果的数量。

    您需要查看paged results control

    您不可能在一次操作中检索所有 100,000 个条目,并且存在很大的风险,即它们无论如何都不会全部放入内存中。无论如何,正确配置的服务器都不会让您尝试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多