if (q.getMaxFeatures() > 0) {
query.setRows(q.getMaxFeatures());
}
// Sort
ORDER naturalSortOrder = ORDER.asc;
if (q.getSortBy() != null) {
for (SortBy sort : q.getSortBy()) {
if (sort.getPropertyName() != null) {
query.addSort(sort.getPropertyName().getPropertyName(), sort.getSortOrder()
.equals(SortOrder.ASCENDING) ? ORDER.asc : ORDER.desc);