Package com.unboundid.ldap.sdk.controls
Class ServerSideSortRequestControl
- java.lang.Object
-
- com.unboundid.ldap.sdk.Control
-
- com.unboundid.ldap.sdk.controls.ServerSideSortRequestControl
-
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class ServerSideSortRequestControl extends Control
This class provides an implementation of the server-side sort request control, as defined in RFC 2891. It may be included in a search request to indicate that the server should sort the results before returning them to the client.
The order in which the entries are to be sorted is specified by one or moreSortKey
values. Each sort key includes an attribute name and a flag that indicates whether to sort in ascending or descending order. It may also specify a custom matching rule that should be used to specify which logic should be used to perform the sorting.
If the search is successful, then the search result done message may include theServerSideSortResponseControl
to provide information about the status of the sort processing.
Example
The following example demonstrates the use of the server-side sort controls to retrieve users in different sort orders.// Perform a search to get all user entries sorted by last name, then by // first name, both in ascending order. SearchRequest searchRequest = new SearchRequest( "ou=People,dc=example,dc=com", SearchScope.SUB, Filter.createEqualityFilter("objectClass", "person")); searchRequest.addControl(new ServerSideSortRequestControl( new SortKey("sn"), new SortKey("givenName"))); SearchResult lastNameAscendingResult; try { lastNameAscendingResult = connection.search(searchRequest); // If we got here, then the search was successful. } catch (LDAPSearchException lse) { // The search failed for some reason. lastNameAscendingResult = lse.getSearchResult(); ResultCode resultCode = lse.getResultCode(); String errorMessageFromServer = lse.getDiagnosticMessage(); } // Get the response control and retrieve the result code for the sort // processing. LDAPTestUtils.assertHasControl(lastNameAscendingResult, ServerSideSortResponseControl.SERVER_SIDE_SORT_RESPONSE_OID); ServerSideSortResponseControl lastNameAscendingResponseControl = ServerSideSortResponseControl.get(lastNameAscendingResult); ResultCode lastNameSortResult = lastNameAscendingResponseControl.getResultCode(); // Perform the same search, but this time request the results to be sorted // in descending order by first name, then last name. searchRequest.setControls(new ServerSideSortRequestControl( new SortKey("givenName", true), new SortKey("sn", true))); SearchResult firstNameDescendingResult; try { firstNameDescendingResult = connection.search(searchRequest); // If we got here, then the search was successful. } catch (LDAPSearchException lse) { // The search failed for some reason. firstNameDescendingResult = lse.getSearchResult(); ResultCode resultCode = lse.getResultCode(); String errorMessageFromServer = lse.getDiagnosticMessage(); } // Get the response control and retrieve the result code for the sort // processing. LDAPTestUtils.assertHasControl(firstNameDescendingResult, ServerSideSortResponseControl.SERVER_SIDE_SORT_RESPONSE_OID); ServerSideSortResponseControl firstNameDescendingResponseControl = ServerSideSortResponseControl.get(firstNameDescendingResult); ResultCode firstNameSortResult = firstNameDescendingResponseControl.getResultCode();
Client-Side Sorting
The UnboundID LDAP SDK for Java provides support for client-side sorting as an alternative to server-side sorting. Client-side sorting may be useful in cases in which the target server does not support the use of the server-side sort control, or when it is desirable to perform the sort processing on the client systems rather than on the directory server systems. See theEntrySorter
class for details on performing client-side sorting in the LDAP SDK.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SERVER_SIDE_SORT_REQUEST_OID
The OID (1.2.840.113556.1.4.473) for the server-side sort request control.
-
Constructor Summary
Constructors Constructor Description ServerSideSortRequestControl(boolean isCritical, SortKey... sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.ServerSideSortRequestControl(boolean isCritical, java.util.List<SortKey> sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.ServerSideSortRequestControl(Control control)
Creates a new server-side sort request control which is decoded from the provided generic control.ServerSideSortRequestControl(SortKey... sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.ServerSideSortRequestControl(java.util.List<SortKey> sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getControlName()
Retrieves the user-friendly name for this control, if available.SortKey[]
getSortKeys()
Retrieves the set of sort keys that define the desired order in which the results should be returned.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
-
SERVER_SIDE_SORT_REQUEST_OID
public static final java.lang.String SERVER_SIDE_SORT_REQUEST_OID
The OID (1.2.840.113556.1.4.473) for the server-side sort request control.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ServerSideSortRequestControl
public ServerSideSortRequestControl(SortKey... sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.- Parameters:
sortKeys
- The set of sort keys to define the desired order in which the results should be returned. It must not benull
or empty.
-
ServerSideSortRequestControl
public ServerSideSortRequestControl(java.util.List<SortKey> sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.- Parameters:
sortKeys
- The set of sort keys to define the desired order in which the results should be returned. It must not benull
or empty.
-
ServerSideSortRequestControl
public ServerSideSortRequestControl(boolean isCritical, SortKey... sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.- Parameters:
isCritical
- Indicates whether this control should be marked critical.sortKeys
- The set of sort keys to define the desired order in which the results should be returned. It must not benull
or empty.
-
ServerSideSortRequestControl
public ServerSideSortRequestControl(boolean isCritical, java.util.List<SortKey> sortKeys)
Creates a new server-side sort control that will sort the results based on the provided set of sort keys.- Parameters:
isCritical
- Indicates whether this control should be marked critical.sortKeys
- The set of sort keys to define the desired order in which the results should be returned. It must not benull
or empty.
-
ServerSideSortRequestControl
public ServerSideSortRequestControl(Control control) throws LDAPException
Creates a new server-side sort request control which is decoded from the provided generic control.- Parameters:
control
- The generic control to be decoded as a server-side sort request control.- Throws:
LDAPException
- If the provided control cannot be decoded as a server-side sort request control.
-
-
Method Detail
-
getSortKeys
public SortKey[] getSortKeys()
Retrieves the set of sort keys that define the desired order in which the results should be returned.- Returns:
- The set of sort keys that define the desired order in which the results should be returned.
-
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.
-
-