use of io.jans.orm.model.Sort in project jans by JanssenProject.
the class SpannerEntryManager method findEntriesImpl.
protected <T> PagedResult<EntryData> findEntriesImpl(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, BatchOperation<T> batchOperation, SearchReturnDataType returnDataType, int start, int count, int chunkSize) {
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
String[] currentLdapReturnAttributes = ldapReturnAttributes;
if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
}
Filter searchFilter;
if (objectClasses.length > 0) {
LOG.trace("Filter: {}", filter);
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Find entries
LOG.trace("-------------------------------------------------------");
LOG.trace("Filter: {}", filter);
LOG.trace("objectClasses count: {} ", objectClasses.length);
LOG.trace("objectClasses: {}", ArrayHelper.toString(objectClasses));
LOG.trace("Search filter: {}", searchFilter);
// Prepare default sort
Sort[] defaultSort = getDefaultSort(entryClass);
if (StringHelper.isNotEmpty(sortBy)) {
Sort requestedSort = buildSort(sortBy, sortOrder);
if (ArrayHelper.isEmpty(defaultSort)) {
defaultSort = new Sort[] { requestedSort };
} else {
defaultSort = ArrayHelper.arrayMerge(new Sort[] { requestedSort }, defaultSort);
}
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
String key = toSQLKey(baseDN).getKey();
ConvertedExpression convertedExpression;
try {
convertedExpression = toSqlFilter(key, objectClasses[0], searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter), ex);
}
PagedResult<EntryData> searchResult = null;
try {
SpannerBatchOperationWraper<T> batchOperationWraper = null;
if (batchOperation != null) {
batchOperationWraper = new SpannerBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
}
searchResult = searchImpl(key, objectClasses[0], convertedExpression, scope, currentLdapReturnAttributes, defaultSort, batchOperationWraper, returnDataType, start, count, chunkSize);
if (searchResult == null) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", key, convertedExpression));
}
return searchResult;
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s'", key), ex);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", key, convertedExpression), ex);
}
}
use of io.jans.orm.model.Sort in project jans by JanssenProject.
the class SpannerEntryManager method getDefaultSort.
protected <T> Sort[] getDefaultSort(Class<T> entryClass) {
String[] sortByProperties = getEntrySortByNames(entryClass);
if (ArrayHelper.isEmpty(sortByProperties)) {
// Fall back to sortBy property name
sortByProperties = getEntrySortByProperties(entryClass);
if (ArrayHelper.isEmpty(sortByProperties)) {
return null;
}
}
Sort[] sort = new Sort[sortByProperties.length];
for (int i = 0; i < sortByProperties.length; i++) {
sort[i] = new Sort(sortByProperties[i], SortOrder.ASCENDING);
}
return sort;
}
Aggregations