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,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:
Note that the simple paged results control is similar to the
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 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
ServerSideSortRequestControlto 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe OID (1.2.840.113556.1.4.319) for the paged results control. -
Constructor Summary
ConstructorsConstructorDescriptionSimplePagedResultsControl(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(String oid, boolean isCritical, ASN1OctetString value) Creates a new paged results control from the control with the provided set of information. -
Method Summary
Modifier and TypeMethodDescriptiondecodeControl(String oid, boolean isCritical, ASN1OctetString value) Creates a new instance of this decodeable control from the provided information.static SimplePagedResultsControldecodeJSONControl(JSONObject controlObject, boolean strict) Attempts to decode the provided object as a JSON representation of a simple paged results control.static SimplePagedResultsControlget(SearchResult result) Extracts a simple paged results response control from the provided result.Retrieves the user-friendly name for this control, if available.Retrieves the cookie for this control, which may be used in a subsequent request to resume reading entries from the next page of results.intgetSize()Retrieves the size for this paged results control.booleanIndicates whether there are more results to return as part of this search.Retrieves a representation of this simple paged results control as a JSON object.voidtoString(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, decodeJSONControl, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, registerDecodeableControl, toString, writeTo
-
Field Details
-
PAGED_RESULTS_OID
The OID (1.2.840.113556.1.4.319) for the paged results control.- See Also:
-
-
Constructor Details
-
SimplePagedResultsControl
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
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
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, ornullif this request will retrieve the first page of results.
-
SimplePagedResultsControl
public SimplePagedResultsControl(int pageSize, @Nullable 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, ornullif this request will retrieve the first page of results.isCritical- Indicates whether this control should be marked critical.
-
SimplePagedResultsControl
public SimplePagedResultsControl(@NotNull String oid, boolean isCritical, @Nullable 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 benullif no value was provided.- Throws:
LDAPException- If the provided control cannot be decoded as a simple paged results control.
-
-
Method Details
-
decodeControl
@NotNull public SimplePagedResultsControl decodeControl(@NotNull String oid, boolean isCritical, @Nullable ASN1OctetString value) throws LDAPException Creates a new instance of this decodeable control from the provided information.- Specified by:
decodeControlin 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 benullif 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
@Nullable public static SimplePagedResultsControl get(@NotNull 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
nullif 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
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
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 an empty cookie (with a value length of zero) if there is none.
-
moreResultsToReturn
Indicates whether there are more results to return as part of this search.- Returns:
trueif there are more results to return, orfalseif not.
-
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:
getControlNamein classControl- Returns:
- The user-friendly name for this control, or the OID if no user-friendly name is available.
-
toJSONControl
Retrieves a representation of this simple paged results control as a JSON object. The JSON object uses the following fields:-
oid-- A mandatory string field whose value is the object identifier for this control. For the simple paged results control, the OID is "1.2.840.113556.1.4.319". -
control-name-- An optional string field whose value is a human-readable name for this control. This field is only intended for descriptive purposes, and when decoding a control, theoidfield should be used to identify the type of control. -
criticality-- A mandatory Boolean field used to indicate whether this control is considered critical. -
value-base64-- An optional string field whose value is a base64-encoded representation of the raw value for this simple paged results control. Exactly one of thevalue-base64andvalue-jsonfields must be present. -
value-json-- An optional JSON object field whose value is a user-friendly representation of the value for this simple paged results control. Exactly one of thevalue-base64andvalue-jsonfields must be present, and if thevalue-jsonfield is used, then it will use the following fields:-
size-- A mandatory integer field. When used in a request control, this represents the maximum number of entries that should be returned in the next page of results. When used in a response control, it provides an estimate of the total number of entries across all pages of the result set. -
cookie-- An optional string field. When used in a request control, this should be empty when requesting the first page of results, and the value of thecookiefield returned in the response control from the previous page of results. For a response control, this will be non-empty for all pages except the last page of results. The cookie value used in the JSON representation of the control will be a base64-encoded representation of the raw cookie value that would be used in the LDAP representation of the control, and it must be treated as an opaque blob by the client.
-
- Overrides:
toJSONControlin classControl- Returns:
- A JSON object that contains a representation of this control.
-
-
decodeJSONControl
@NotNull public static SimplePagedResultsControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException Attempts to decode the provided object as a JSON representation of a simple paged results control.- Parameters:
controlObject- The JSON object to be decoded. It must not benull.strict- Indicates whether to use strict mode when decoding the provided JSON object. If this istrue, then this method will throw an exception if the provided JSON object contains any unrecognized fields. If this isfalse, then unrecognized fields will be ignored.- Returns:
- The simple paged results control that was decoded from the provided JSON object.
- Throws:
LDAPException- If the provided JSON object cannot be parsed as a valid simple paged results control.
-
toString
Appends a string representation of this LDAP control to the provided buffer.
-