Javadoc for the method clarifies the semantics:

"Returns a count of queued search results immediately available for processing. A search result is either a
search entry or an exception. If the search is asynchronous (batch size not 0), this reports the number of
results received so far."

You see different values on each call as the count is incremented when the connection thread receives a new search result from the server and decremented when the app thread calls next() or nextElement().

The method name is a bit misleading and often people expect it to return the total number of search results. Thus a more appropriate name would be getQueuedCount() ot getAvailableCount() or getReceivedCount(). The only scenario where the total result count is returned is when synchronous search is used (batch size=0, LDAPConnection.search() blocks until all search results are received).

Miodrag

Ingo Schaefer wrote:

Hello,

I'm writing an application, which should interoperate with
my openldap-Server (2.1.4)

So I downloaded the source for the Directory SDK 4.1
and, after correcting 2 minor errors, got it to compile.

Now I can connect to the server and retrieve results, fine.

LDAPConnection ld=new LDAPConnection;
ld.connnect(<something>);
LDAPResult res=ld.search(base,LDAPConnection.SCOPE_SUB
,filter,attribs,false);

If I now ask res.getCount(), I get very strange results.

sometimes it gives 1 (if currently 2 entries matched)
sometimes it gives 2 (if currently 4 entries matched)

only "right" thing (to my mind) is, if no entry matched, 0 is returned.

What is the reason for that?
Is it a bug?

If I iterate through the result using res.hasMoreElements()
and res.next() I got all matching entries.

Any help appreciated
Regards
Ingo Schaefer






Reply via email to