Is there way to get page number N during pagination request without iterating over previous pages?

16 Views Asked by At

Currently I use SimplePagedResultsControl and my code looks similar to example on that page: https://docs.ldap.com/ldap-sdk/docs/javadoc/com/unboundid/ldap/sdk/controls/SimplePagedResultsControl.html

The following example demonstrates the use of the simple paged results control. It will iterate through all users, retrieving up to 10 entries at a time:
 // Perform a search to retrieve all users in the server, but only retrieving
 // ten at a time.
 int numSearches = 0;
 int totalEntriesReturned = 0;
 SearchRequest searchRequest = new SearchRequest("dc=example,dc=com",
      SearchScope.SUB, Filter.createEqualityFilter("objectClass", "person"));
 ASN1OctetString resumeCookie = null;
 while (true)
 {
   searchRequest.setControls(
        new SimplePagedResultsControl(10, resumeCookie));
   SearchResult searchResult = connection.search(searchRequest);
   numSearches++;
   totalEntriesReturned += searchResult.getEntryCount();
   for (SearchResultEntry e : searchResult.getSearchEntries())
   {
     // Do something with each entry...
   }

   LDAPTestUtils.assertHasControl(searchResult,
        SimplePagedResultsControl.PAGED_RESULTS_OID);
   SimplePagedResultsControl responseControl =
        SimplePagedResultsControl.get(searchResult);
   if (responseControl.moreResultsToReturn())
   {
     // The resume cookie can be included in the simple paged results
     // control included in the next search to get the next page of results.
     resumeCookie = responseControl.getCookie();
   }
   else
   {
     break;
   }
 }

Is there way to get page number N without iterating over previous pages ? Is there way to get amount of pages/entries ?

P.S. I use Samba (AD)

0

There are 0 best solutions below