mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
* 1476 - Query plan capture, initial wip capturing bind params * No effective change - Reset test default db to H2 * #1476 - Query plan capture, initial wip capturing bind params #1477 Update with consumer * #1476 - Query plan capture, initial wip capturing bind params #1477 Update with query plan request * #1476 - Query plan capture, initial wip capturing bind params #1477 Extract interface * #1476 - Query plan capture, initial wip capturing bind params #1477 Extract interface
62 lines
1.5 KiB
Java
62 lines
1.5 KiB
Java
package io.ebeaninternal.server.el;
|
|
|
|
import io.ebean.bean.EntityBean;
|
|
|
|
import java.util.Comparator;
|
|
|
|
/**
|
|
* Comparator based on a ElGetValue.
|
|
*/
|
|
public final class ElComparatorProperty<T> implements Comparator<T>, ElComparator<T> {
|
|
|
|
private static final long serialVersionUID = -2735738237263956073L;
|
|
|
|
private final ElPropertyValue elGetValue;
|
|
|
|
private final int nullOrder;
|
|
|
|
private final int asc;
|
|
|
|
public ElComparatorProperty(ElPropertyValue elGetValue, boolean ascending, boolean nullsHigh) {
|
|
this.elGetValue = elGetValue;
|
|
this.asc = ascending ? 1 : -1;
|
|
this.nullOrder = asc * (nullsHigh ? 1 : -1);
|
|
}
|
|
|
|
@Override
|
|
public int compare(T o1, T o2) {
|
|
|
|
Object val1 = elGetValue.pathGet(o1);
|
|
Object val2 = elGetValue.pathGet(o2);
|
|
return compareValues(val1, val2);
|
|
}
|
|
|
|
@Override
|
|
public int compareValue(Object value, T o2) {
|
|
|
|
Object val2 = elGetValue.pathGet(o2);
|
|
return compareValues(value, val2);
|
|
}
|
|
|
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
public int compareValues(Object val1, Object val2) {
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
}
|