Package com.unboundid.ldap.sdk.controls
Class SimplePagedResultsControl
- java.lang.Object
-
- com.unboundid.ldap.sdk.Control
-
- com.unboundid.ldap.sdk.controls.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.
Note that the simple paged results control is similar to theVirtualListViewRequestControl
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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PAGED_RESULTS_OID
The OID (1.2.840.113556.1.4.319) for the paged results control.
-
Constructor Summary
Constructors Constructor Description SimplePagedResultsControl(int pageSize)
Creates a new paged results control with the specified page size.SimplePagedResultsControl(int pageSize, boolean isCritical)
Creates a new paged results control with the specified page size.SimplePagedResultsControl(int pageSize, ASN1OctetString cookie)
Creates a new paged results control with the specified page size and the provided cookie.SimplePagedResultsControl(int pageSize, ASN1OctetString cookie, boolean isCritical)
Creates a new paged results control with the specified page size and the provided cookie.SimplePagedResultsControl(java.lang.String oid, boolean isCritical, ASN1OctetString value)
Creates a new paged results control from the control with the provided set of information.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SimplePagedResultsControl
decodeControl(java.lang.String oid, boolean isCritical, ASN1OctetString value)
Creates a new instance of this decodeable control from the provided information.static SimplePagedResultsControl
get(SearchResult result)
Extracts a simple paged results response control from the provided result.java.lang.String
getControlName()
Retrieves the user-friendly name for this control, if available.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.int
getSize()
Retrieves the size for this paged results control.boolean
moreResultsToReturn()
Indicates whether there are more results to return as part of this search.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP control to the provided buffer.-
Methods inherited from class com.unboundid.ldap.sdk.Control
decode, decode, decodeControls, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, toString, writeTo
-
-
-
-
Field Detail
-
PAGED_RESULTS_OID
public static final java.lang.String PAGED_RESULTS_OID
The OID (1.2.840.113556.1.4.319) for the paged results control.- See Also:
- Constant Field Values
-
-
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, ornull
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, ornull
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 benull
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 interfaceDecodeableControl
- 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 benull
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, orfalse
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 classControl
- Returns:
- The user-friendly name for this control, or the OID if no user-friendly name is available.
-
-