use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class Ordering method compare.
/**
* Comparable interface implementation. Can compare two Java Beans based on
* the stored expression.
*/
@Override
public int compare(Object o1, Object o2) {
Expression exp = getSortSpec();
Object value1 = null;
Object value2 = null;
try {
value1 = exp.evaluate(o1);
} catch (ExpressionException e) {
if (pathExceptionSuppressed && e.getCause() instanceof org.apache.cayenne.reflect.UnresolvablePathException) {
// do nothing, we expect this
} else {
// re-throw
throw e;
}
}
try {
value2 = exp.evaluate(o2);
} catch (ExpressionException e) {
if (pathExceptionSuppressed && e.getCause() instanceof org.apache.cayenne.reflect.UnresolvablePathException) {
// do nothing, we expect this
} else {
// rethrow
throw e;
}
}
if (value1 == null && value2 == null) {
return 0;
} else if (value1 == null) {
return nullSortedFirst ? -1 : 1;
} else if (value2 == null) {
return nullSortedFirst ? 1 : -1;
}
if (isCaseInsensitive()) {
// TODO: to upper case should probably be defined as a separate
// expression
// type
value1 = ConversionUtil.toUpperCase(value1);
value2 = ConversionUtil.toUpperCase(value2);
}
int compareResult = ConversionUtil.toComparable(value1).compareTo(ConversionUtil.toComparable(value2));
return (isAscending()) ? compareResult : -compareResult;
}
use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class ASTNamedParameter method setValue.
@Override
public void setValue(Object value) {
if (value == null) {
throw new ExpressionException("Null Parameter value");
}
String name = value.toString().trim();
if (name.length() == 0) {
throw new ExpressionException("Empty Parameter value");
}
super.setValue(new ExpressionParameter(name));
}
use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class PrefetchModel method isToMany.
private boolean isToMany(String prefetch) {
// totally invalid path would result in ExpressionException
try {
Expression exp = ExpressionFactory.exp(prefetch);
Object object = exp.evaluate(root);
return object instanceof Relationship && ((Relationship) object).isToMany();
} catch (ExpressionException e) {
return false;
}
}
use of org.apache.cayenne.exp.ExpressionException in project cayenne by apache.
the class EOQuery method initBindings.
private void initBindings(Map bindings, Entity entity, Map qualifier) {
if (qualifier == null) {
return;
}
if ("EOKeyValueQualifier".equals(qualifier.get("class"))) {
String key = (String) qualifier.get("key");
if (key == null) {
return;
}
Object value = qualifier.get("value");
if (!(value instanceof Map)) {
return;
}
Map valueMap = (Map) value;
if (!"EOQualifierVariable".equals(valueMap.get("class")) || !valueMap.containsKey("_key")) {
return;
}
String name = (String) valueMap.get("_key");
String className = null;
// so we will use Object type for all DB path...
try {
Object lastObject = new ASTObjPath(key).evaluate(entity);
if (lastObject instanceof ObjAttribute) {
className = ((ObjAttribute) lastObject).getType();
} else if (lastObject instanceof ObjRelationship) {
ObjEntity target = ((ObjRelationship) lastObject).getTargetEntity();
if (target != null) {
className = target.getClassName();
}
}
} catch (ExpressionException ex) {
className = "java.lang.Object";
}
if (className == null) {
className = "java.lang.Object";
}
bindings.put(name, className);
return;
}
List children = (List) qualifier.get("qualifiers");
if (children != null) {
Iterator it = children.iterator();
while (it.hasNext()) {
initBindings(bindings, entity, (Map) it.next());
}
}
}
Aggregations