Commit 314e8178 by Alexey Gobzhelyan

PLAY-174 Don't use default value for ORDER BY

To calculate count entities buildSearchCriteria() is used and for this case ORDER BY should not be added to query (it doesn't make sense and doesn't work correctly with H2)
parent 12305f87
package service;
import ch.insign.cms.services.AbstractDatatableService;
import ch.insign.playauth.PlayAuth;
import ch.insign.playauth.PlayAuthApi;
import crud.data.entity.Brand;
import crud.data.entity.Car;
......@@ -127,16 +126,16 @@ public class CarDatatableService extends AbstractDatatableService<Car> {
conditionsAnd.add(builder.or(likeConditions));
}
Expression orderByFieldExpression;
query.where(builder.and(conditionsAnd.toArray(new Predicate[]{})));
orderByField = StringUtils.defaultIfEmpty(orderByField, "model");
if (StringUtils.isNotEmpty(orderByField)) {
Expression orderByFieldExpression = cars.get(orderByField);
orderByFieldExpression = cars.get(orderByField);
query.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
}
return query
.where(builder.and(conditionsAnd.toArray(new Predicate[]{})))
.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
return query;
}
}
......@@ -71,21 +71,22 @@ public class UserDatatableService extends PartyDatatableService<User> {
conditionsAnd.add(builder.or(likeConditions));
}
Expression orderByFieldExpression;
orderByField = StringUtils.defaultIfEmpty(orderByField, "name");
if (orderByField.equals("roleName")) {
users.fetch("partyRoles", JoinType.LEFT);
orderByFieldExpression = users.get("partyRoles").get("name");
} else {
orderByFieldExpression = users.get(orderByField);
query.where(builder.and(conditionsAnd.toArray(new Predicate[]{})));
if (StringUtils.isNotEmpty(orderByField)) {
Expression orderByFieldExpression;
if (orderByField.equals("roleName")) {
users.fetch("partyRoles", JoinType.LEFT);
orderByFieldExpression = users.get("partyRoles").get("name");
} else {
orderByFieldExpression = users.get(orderByField);
}
query.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
}
return query
.where(builder.and(conditionsAnd.toArray(new Predicate[]{})))
.orderBy(StringUtils.defaultIfEmpty(orderByDirection, "desc").equals("desc")
? builder.desc(orderByFieldExpression)
: builder.asc(orderByFieldExpression));
return query;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment