Skip to content

Commit

Permalink
Do not sort query for any object
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Nov 26, 2024
1 parent 5d020a0 commit 96af397
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -328,6 +329,16 @@ public void defineSorting(String sortField, SortOrder sortOrder) {
sorting = Pair.of(varName + '.' + sortField, SortOrder.DESCENDING.equals(sortOrder) ? "DESC" : "ASC");
}

/**
* Disables the sort order of the query. This can speed up the check whether
* there is <i>any</i> object for a specific search query. However, you no
* longer have a reliable order when navigating the result list, and should
* therefore only be used in special cases.
*/
public void setUnordered() {
sorting = null;
}

/**
* Forms and returns a query to count all objects.
*
Expand All @@ -351,7 +362,9 @@ public String formQueryForAll() {
query.append("SELECT ").append(varName).append(' ');
}
innerFormQuery(query);
query.append(" ORDER BY ").append(sorting.getKey()).append(' ').append(sorting.getValue());
if (Objects.nonNull(sorting)) {
query.append(" ORDER BY ").append(sorting.getKey()).append(' ').append(sorting.getValue());
}
return query.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ public Collection<?> findByDocket(int docketId) throws DAOException {
public Collection<?> findByTemplate(int templateId) throws DAOException {
BeanQuery query = new BeanQuery(Process.class);
query.addIntegerRestriction("template.id", templateId);
query.setUnordered();
return getByQuery(query.formQueryForAll(), query.getQueryParameters(), 0, 1);
}

Expand Down

0 comments on commit 96af397

Please sign in to comment.