protected void validateOrdering( Entity entity, Ordering ordering, ProjectPath path, Validator validator) { if (ordering == null) { return; } try { testExpression(entity, ordering.getSortSpec()); } catch (ExpressionException e) { validator .registerWarning(buildValidationMessage(e, "Invalid ordering"), path); } }
Expression exp = ord.getSortSpec();
/** * Encodes itself as a query ordering. * * @since 1.1 */ public void encodeAsXML(XMLEncoder encoder) { encoder.print("<ordering"); if (!ascending) { encoder.print(" descending=\"true\""); } if (caseInsensitive) { encoder.print(" ignore-case=\"true\""); } encoder.print(">"); if (getSortSpec() != null) { getSortSpec().encodeAsXML(encoder); } encoder.println("</ordering>"); }
Expression exp = ord.getSortSpec();
/** * Encodes itself as a query ordering. * * @since 1.1 */ @Override public void encodeAsXML(XMLEncoder encoder) { encoder.print("<ordering"); if (isDescending()) { encoder.print(" descending=\"true\""); } if (isCaseInsensitive()) { encoder.print(" ignore-case=\"true\""); } encoder.print(">"); if (getSortSpec() != null) { getSortSpec().encodeAsXML(encoder); } encoder.println("</ordering>"); }
/** * Comparable interface implementation. Can compare two Java Beans based on the stored * expression. */ public int compare(Object o1, Object o2) { Expression exp = getSortSpec(); Object value1 = exp.evaluate(o1); Object value2 = exp.evaluate(o2); // nulls first policy... maybe make this configurable as some DB do if (value1 == null) { return (value2 == null) ? 0 : -1; } else if (value2 == null) { return 1; } if (this.caseInsensitive) { // 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 (ascending) ? compareResult : -compareResult; }
Expression exp = getSortSpec(); Object value1 = null; Object value2 = null;