use of org.forgerock.opendj.ldap.controls.SimplePagedResultsControl in project OpenAM by OpenRock.
the class LdapQueryBuilder method getEntries.
private Collection<Entry> getEntries(Connection connection) throws CoreTokenException {
// Prepare the search
Filter ldapFilter = getLDAPFilter();
SearchRequest searchRequest = LDAPRequests.newSearchRequest(dataLayerConfiguration.getTokenStoreRootSuffix(), SearchScope.WHOLE_SUBTREE, ldapFilter, requestedAttributes);
searchRequest.setSizeLimit(sizeLimit);
if (isPagingResults()) {
searchRequest = searchRequest.addControl(SimplePagedResultsControl.newControl(true, pageSize, pagingCookie));
}
// Perform the search
Collection<Entry> entries = createResultsList();
final Result result = handler.performSearch(connection, searchRequest, entries);
if (isPagingResults()) {
try {
SimplePagedResultsControl control = result.getControl(SimplePagedResultsControl.DECODER, new DecodeOptions());
if (control == null) {
if (debug.warningEnabled()) {
debug.warning("There was no paged result control in the search response, it is recommended to " + "set the CTS user's size-limit at least to " + (pageSize + 1));
}
pagingCookie = getEmptyPagingCookie();
} else {
pagingCookie = control.getCookie();
}
} catch (DecodeException e) {
throw new CoreTokenException("Failed to decode Paging Cookie", e);
}
}
if (debug.messageEnabled()) {
debug.message(MessageFormat.format(CoreTokenConstants.DEBUG_HEADER + "Query: matched {0} results\n" + "Search Request: {1}\n" + "Filter: {2}\n" + "Result: {3}", entries.size(), searchRequest, ldapFilter.toString(), result));
}
return entries;
}
Aggregations