Class SimplePagedResultsControl

  • All Implemented Interfaces:
    DecodeableControl, java.io.Serializable

    @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class SimplePagedResultsControl
    extends Control
    implements DecodeableControl
    This class provides an implementation of the simple paged results control as defined in RFC 2696. It allows the client to iterate through a potentially large set of search results in subsets of a specified number of entries (i.e., "pages").

    The same control encoding is used for both the request control sent by clients and the response control returned by the server. It may contain two elements:
    • Size -- In a request control, this provides the requested page size, which is the maximum number of entries that the server should return in the next iteration of the search. In a response control, it is an estimate of the total number of entries that match the search criteria.
    • Cookie -- A token which is used by the server to keep track of its position in the set of search results. The first request sent by the client should not include a cookie, and the last response sent by the server should not include a cookie. For all other intermediate search requests and responses, the server will include a cookie value in its response that the client should include in its next request.
    When the client wishes to use the paged results control, the first search request should include a version of the paged results request control that was created with a requested page size but no cookie. The corresponding response from the server will include a version of the paged results control that may include an estimate of the total number of matching entries, and may also include a cookie. The client should include this cookie in the next request (with the same set of search criteria) to retrieve the next page of results. This process should continue until the response control returned by the server does not include a cookie, which indicates that the end of the result set has been reached.

    Note that the simple paged results control is similar to the VirtualListViewRequestControl in that both allow the client to request that only a portion of the result set be returned at any one time. However, there are significant differences between them, including:
    • In order to use the virtual list view request control, it is also necessary to use the ServerSideSortRequestControl to ensure that the entries are sorted. This is not a requirement for the simple paged results control.
    • The simple paged results control may only be used to iterate sequentially through the set of search results. The virtual list view control can retrieve pages out of order, can retrieve overlapping pages, and can re-request pages that it had already retrieved.

    Example

    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;
       }
     }
     
    See Also:
    Serialized Form
    • Constructor Detail

      • SimplePagedResultsControl

        public SimplePagedResultsControl​(int pageSize)
        Creates a new paged results control with the specified page size. This version of the constructor should only be used when creating the first search as part of the set of paged results. Subsequent searches to retrieve additional pages should use the response control returned by the server in their next request, until the response control returned by the server does not include a cookie.
        Parameters:
        pageSize - The maximum number of entries that the server should return in the first page.
      • SimplePagedResultsControl

        public SimplePagedResultsControl​(int pageSize,
                                         boolean isCritical)
        Creates a new paged results control with the specified page size. This version of the constructor should only be used when creating the first search as part of the set of paged results. Subsequent searches to retrieve additional pages should use the response control returned by the server in their next request, until the response control returned by the server does not include a cookie.
        Parameters:
        pageSize - The maximum number of entries that the server should return in the first page.
        isCritical - Indicates whether this control should be marked critical.
      • SimplePagedResultsControl

        public SimplePagedResultsControl​(int pageSize,
                                         ASN1OctetString cookie)
        Creates a new paged results control with the specified page size and the provided cookie. This version of the constructor should be used to continue iterating through an existing set of results, but potentially using a different page size.
        Parameters:
        pageSize - The maximum number of entries that the server should return in the next page of the results.
        cookie - The cookie provided by the server after returning the previous page of results, or null if this request will retrieve the first page of results.
      • SimplePagedResultsControl

        public SimplePagedResultsControl​(int pageSize,
                                         ASN1OctetString cookie,
                                         boolean isCritical)
        Creates a new paged results control with the specified page size and the provided cookie. This version of the constructor should be used to continue iterating through an existing set of results, but potentially using a different page size.
        Parameters:
        pageSize - The maximum number of entries that the server should return in the first page.
        cookie - The cookie provided by the server after returning the previous page of results, or null if this request will retrieve the first page of results.
        isCritical - Indicates whether this control should be marked critical.
      • SimplePagedResultsControl

        public SimplePagedResultsControl​(java.lang.String oid,
                                         boolean isCritical,
                                         ASN1OctetString value)
                                  throws LDAPException
        Creates a new paged results control from the control with the provided set of information. This should be used to decode the paged results response control returned by the server with a page of results.
        Parameters:
        oid - The OID for the control.
        isCritical - Indicates whether the control should be marked critical.
        value - The encoded value for the control. This may be null if no value was provided.
        Throws:
        LDAPException - If the provided control cannot be decoded as a simple paged results control.
    • Method Detail

      • decodeControl

        public SimplePagedResultsControl decodeControl​(java.lang.String oid,
                                                       boolean isCritical,
                                                       ASN1OctetString value)
                                                throws LDAPException
        Creates a new instance of this decodeable control from the provided information.
        Specified by:
        decodeControl in interface DecodeableControl
        Parameters:
        oid - The OID for the control.
        isCritical - Indicates whether the control should be marked critical.
        value - The encoded value for the control. This may be null if no value was provided.
        Returns:
        The decoded representation of this control.
        Throws:
        LDAPException - If the provided information cannot be decoded as a valid instance of this decodeable control.
      • get

        public static SimplePagedResultsControl get​(SearchResult result)
                                             throws LDAPException
        Extracts a simple paged results response control from the provided result.
        Parameters:
        result - The result from which to retrieve the simple paged results response control.
        Returns:
        The simple paged results response control contained in the provided result, or null if the result did not contain a simple paged results response control.
        Throws:
        LDAPException - If a problem is encountered while attempting to decode the simple paged results response control contained in the provided result.
      • getSize

        public int getSize()
        Retrieves the size for this paged results control. For a request control, it may be used to specify the number of entries that should be included in the next page of results. For a response control, it may be used to specify the estimated number of entries in the complete result set.
        Returns:
        The size for this paged results control.
      • getCookie

        public ASN1OctetString getCookie()
        Retrieves the cookie for this control, which may be used in a subsequent request to resume reading entries from the next page of results. The value should have a length of zero when used to retrieve the first page of results for a given search, and also in the response from the server when there are no more entries to send. It should be non-empty for all other conditions.
        Returns:
        The cookie for this control, or null if there is none.
      • moreResultsToReturn

        public boolean moreResultsToReturn()
        Indicates whether there are more results to return as part of this search.
        Returns:
        true if there are more results to return, or false if not.
      • getControlName

        public java.lang.String getControlName()
        Retrieves the user-friendly name for this control, if available. If no user-friendly name has been defined, then the OID will be returned.
        Overrides:
        getControlName in class Control
        Returns:
        The user-friendly name for this control, or the OID if no user-friendly name is available.
      • toString

        public void toString​(java.lang.StringBuilder buffer)
        Appends a string representation of this LDAP control to the provided buffer.
        Overrides:
        toString in class Control
        Parameters:
        buffer - The buffer to which to append the string representation of this buffer.