mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
Add some sanity checks when creating sort comparators (#1538)
This commit is contained in:
1 parent
cfba4d2deb
commit
ec24374d72
4 files changed
+43
No files matched your search
@@ -0,0 +1,23 @@
|
||||
package io.ebeaninternal.server.el;
|
||||
|
||||
/**
|
||||
* Comparator with no operation for unsortable properties.
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
public class ElComparatorNoop<T> implements ElComparator<T> {
|
||||
|
||||
private static final long serialVersionUID = -9060871822183687180L;
|
||||
|
||||
@Override
|
||||
public int compare(T o1, T o2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareValue(Object value, T o2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package io.ebeaninternal.server.el;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import io.ebean.bean.EntityBean;
|
||||
|
||||
/**
|
||||
* Comparator based on a ElGetValue.
|
||||
*/
|
||||
@@ -42,9 +44,15 @@ public final class ElComparatorProperty<T> implements Comparator<T>, ElComparato
|
||||
if (val1 == null) {
|
||||
return val2 == null ? 0 : nullOrder;
|
||||
}
|
||||
if (elGetValue.isAssocId()) {
|
||||
val1 = elGetValue.getAssocIdValues((EntityBean) val1)[0]; // TODO: compound key not yet supported
|
||||
}
|
||||
if (val2 == null) {
|
||||
return -1 * nullOrder;
|
||||
}
|
||||
if (elGetValue.isAssocId()) {
|
||||
val2 = elGetValue.getAssocIdValues((EntityBean) val2)[0];
|
||||
}
|
||||
Comparable c = (Comparable) val1;
|
||||
return asc * c.compareTo(val2);
|
||||
}
|
||||
|
||||
@@ -266,6 +266,9 @@ public class ElPropertyChain implements ElPropertyValue {
|
||||
@Override
|
||||
public Object pathGet(Object bean) {
|
||||
for (ElPropertyValue aChain : chain) {
|
||||
if (aChain.isAssocMany()) {
|
||||
throw new UnsupportedOperationException("pathGet not supported on [" + expression + "], because " + aChain + " is an assocMany property");
|
||||
}
|
||||
bean = aChain.pathGet(bean);
|
||||
if (bean == null) {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user