directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amit nanda <amit...@gmail.com>
Subject Getting total count of entries in a container
Date Thu, 11 Dec 2014 04:32:45 GMT
Hi,

I would like to  get the total count of entries under a container.
I application will have around 100000 entries, i can't get a direct way to
to this.


Here is a sample of workaround the code i wrote

Stopwatch timer = Stopwatch.createStarted();

final SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
searchControls.setReturningAttributes(new String[]{"uid"});

int count = 0;
String filter =
"(&(objectClass=asoc-es)(|(asoc-es-state=Karnataka)(asoc-es-city=Ontario)(asoc-es-county=England)"
+
"(asoc-es-priority=5)))";

count += ldapTemplate.search("ou=services,ou=configuration,ou=system",
filter,
searchControls, new AttributesMapper<Object>() {
@Override
public Object mapFromAttributes(Attributes attributes) throws
NamingException {
return "";
}
}).size();

timer.stop();

Logger.getLogger("Ldap-Client").info("Count = : " + count);
Logger.getLogger("Ldap-Client").info("Duration = : " + timer);


I tried this with around 20,000 entries, time taken was around 4 seconds,
which is bit more that my requirement.

I also see that in PagedResultsDirContextProcessor I see that there is a
getResultSize(), which should give us the total count according to the doc,
but this doesn't seems to be working for me.

Is there any way i can get the total count, faster than this.


Thanks
Amit

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message