Refs #1407 Table sorting: sort by reference column with null value

This commit is contained in:
Konstantin Krivopustov 2012-08-08 15:07:47 +00:00
parent 10f4c8c067
commit 9c584198bb
3 changed files with 14 additions and 20 deletions

View File

@ -482,6 +482,19 @@ public abstract class AbstractCollectionDatasource<T extends Entity<K>, K>
}
}
protected void setSortDirection(LoadContext.Query q) {
boolean asc = Sortable.Order.ASC.equals(sortInfos[0].getOrder());
MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath();
// Sort on DB only if the property is not transient and it is not an entity. Sorting by entity in JPQL
// translates to order by entity's id in SQL, that makes no sense.
if (MetadataHelper.isPersistent(propertyPath) && !propertyPath.getMetaProperty().getRange().isClass()) {
QueryTransformer transformer = QueryTransformerFactory.createTransformer(q.getQueryString(), metaClass.getName());
transformer.replaceOrderBy(propertyPath.toString(), !asc);
String jpqlQuery = transformer.getResult();
q.setQueryString(jpqlQuery);
}
}
private class ComponentValueListener implements ValueListener {
public void valueChanged(Object source, String property, Object prevValue, Object value) {
refresh();

View File

@ -496,17 +496,6 @@ public class CollectionDatasourceImpl<T extends Entity<K>, K>
detachListener((Instance) obj);
}
}
protected void setSortDirection(LoadContext.Query q) {
boolean asc = Order.ASC.equals(sortInfos[0].getOrder());
MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath();
if (MetadataHelper.isPersistent(propertyPath)) {
QueryTransformer transformer = QueryTransformerFactory.createTransformer(q.getQueryString(), metaClass.getName());
transformer.replaceOrderBy(propertyPath.toString(), !asc);
String jpqlQuery = transformer.getResult();
q.setQueryString(jpqlQuery);
}
}
@SuppressWarnings("unchecked")
public Map<Object, String> aggregate(AggregationInfo[] aggregationInfos, Collection itemIds) {

View File

@ -359,15 +359,7 @@ public class LazyCollectionDatasource<T extends Entity<K>, K>
LoadContext.Query q = createLoadContextQuery(ctx, params);
if (q != null) {
if (sortInfos != null) {
QueryTransformer transformer = QueryTransformerFactory.createTransformer(q.getQueryString(), metaClass.getName());
boolean asc = Order.ASC.equals(sortInfos[0].getOrder());
MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath();
transformer.replaceOrderBy(propertyPath.toString(), !asc);
String jpqlQuery = transformer.getResult();
q.setQueryString(jpqlQuery);
setSortDirection(q);
}
if (maxResults == 0 || data.size() < maxResults) {