protected Ordering ordering( DynamicOperand operand, Order order, NullOrder nullOrder ) { return new Ordering(operand, order, nullOrder); }
@Override public void visit( Ordering obj ) { verifyOrdering(obj.getOperand()); }
@Override public String getOrder() { switch (order()) { case ASCENDING: return QueryObjectModelConstants.JCR_ORDER_ASCENDING; case DESCENDING: return QueryObjectModelConstants.JCR_ORDER_DESCENDING; } assert false; return null; }
@Override public void visit( Ordering ordering ) { ordering.getOperand().accept(this); append(' ').append(ordering.order().symbol()); }
/** * Create an {@link ExtractFromRow} instance that produces for given row a single object that can be used to sort all rows in * the specified order. * * @param ordering the specification of the sort order; may not be null or empty * @param sourceNamesByAlias the map of selector names keyed by their aliases; may not be null but may be empty * @param context the context in which the query is to be executed; may not be null * @param columns the result column definition; may not be null * @param sources the query sources for the repository; may not be null * @return the extractor; never null */ protected ExtractFromRow createSortingExtractor( Ordering ordering, Map<SelectorName, SelectorName> sourceNamesByAlias, QueryContext context, Columns columns, QuerySources sources ) { DynamicOperand operand = ordering.getOperand(); TypeFactory<?> defaultType = context.getTypeSystem().getStringFactory();// only when ordered column is residual or not // defined ExtractFromRow extractor = createExtractFromRow(operand, context, columns, sources, defaultType, false, false); return RowExtractors.extractorWith(extractor, ordering.order(), ordering.nullOrder()); }
node.getSelectors().clear(); for (Ordering ordering : orderings) { DynamicOperand operand = ordering.getOperand(); DynamicOperand newOperand = replaceViewReferences(context, operand, mappings, node); if (newOperand != operand) { ordering = new Ordering(newOperand, ordering.order(), ordering.nullOrder());
@Override public String getNullOrder() { switch (nullOrder()) { case NULLS_FIRST: return QueryObjectModelConstants.JCR_ORDER_NULLS_FIRST; case NULLS_LAST: return QueryObjectModelConstants.JCR_ORDER_NULLS_LAST; } assert false; return null; }
if (isFirst) isFirst = false; else append(", "); ordering.accept(this);
@Override public void visit( Ordering ordering ) { ordering.getOperand().accept(this); append(' ').append(ordering.order().symbol()); }
/** * Create an {@link ExtractFromRow} instance that produces for given row a single object that can be used to sort all rows in * the specified order. * * @param ordering the specification of the sort order; may not be null or empty * @param sourceNamesByAlias the map of selector names keyed by their aliases; may not be null but may be empty * @param context the context in which the query is to be executed; may not be null * @param columns the result column definition; may not be null * @param sources the query sources for the repository; may not be null * @return the extractor; never null */ protected ExtractFromRow createSortingExtractor( Ordering ordering, Map<SelectorName, SelectorName> sourceNamesByAlias, QueryContext context, Columns columns, QuerySources sources ) { DynamicOperand operand = ordering.getOperand(); TypeFactory<?> defaultType = context.getTypeSystem().getStringFactory();// only when ordered column is residual or not // defined ExtractFromRow extractor = createExtractFromRow(operand, context, columns, sources, defaultType, false, false); return RowExtractors.extractorWith(extractor, ordering.order(), ordering.nullOrder()); }
node.getSelectors().clear(); for (Ordering ordering : orderings) { DynamicOperand operand = ordering.getOperand(); DynamicOperand newOperand = replaceViewReferences(context, operand, mappings, node); if (newOperand != operand) { ordering = new Ordering(newOperand, ordering.order(), ordering.nullOrder());
@Override public String getNullOrder() { switch (nullOrder()) { case NULLS_FIRST: return QueryObjectModelConstants.JCR_ORDER_NULLS_FIRST; case NULLS_LAST: return QueryObjectModelConstants.JCR_ORDER_NULLS_LAST; } assert false; return null; }
if (isFirst) isFirst = false; else append(", "); ordering.accept(this);
@Test public void shouldParserOrderByWithTwoOrderings() { List<Ordering> orderBy = parser.parseOrderBy(tokens("ORDER BY NAME(tableA) ASC, SCORE(tableB) DESC"), typeSystem, mock(Source.class)); assertThat(orderBy.size(), is(2)); Ordering first = orderBy.get(0); assertThat(first.getOperand(), is(instanceOf(NodeName.class))); assertThat(first.order(), is(Order.ASCENDING)); Ordering second = orderBy.get(1); assertThat(second.getOperand(), is(instanceOf(FullTextSearchScore.class))); assertThat(second.order(), is(Order.DESCENDING)); }
@Override public void visit( Ordering ordering ) { ordering.getOperand().accept(this); append(' ').append(ordering.order().symbol()); append(' ').append(ordering.nullOrder().symbol()); } }
protected Ordering ordering( DynamicOperand operand, Order order, NullOrder nullOrder ) { return new Ordering(operand, order, nullOrder); }
@Override public void visit( Ordering obj ) { verifyOrdering(obj.getOperand()); }
@Override public String getOrder() { switch (order()) { case ASCENDING: return QueryObjectModelConstants.JCR_ORDER_ASCENDING; case DESCENDING: return QueryObjectModelConstants.JCR_ORDER_DESCENDING; } assert false; return null; }
nullOrder = orderings.get(0).nullOrder();
@Test public void shouldParserOrderByWithOneOrdering() { List<Ordering> orderBy = parser.parseOrderBy(tokens("ORDER BY NAME(tableA) ASC"), typeSystem, mock(Source.class)); assertThat(orderBy.size(), is(1)); Ordering first = orderBy.get(0); assertThat(first.getOperand(), is(instanceOf(NodeName.class))); assertThat(first.order(), is(Order.ASCENDING)); }