/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.dao;

import foam.core.X;
import foam.mlang.predicate.And;
import foam.mlang.predicate.Predicate;
import foam.mlang.order.Comparator;
import foam.dao.Sink;

public class OrderedDAO
  extends ProxyDAO
{
  protected foam.mlang.order.Comparator order_;

  public OrderedDAO(Comparator order, DAO delegate) {
    order_ = order;
    setDelegate(delegate);
  }

  public OrderedDAO setOrder(foam.mlang.order.Comparator order) {
    order_ = order;
    return this;
  }

  public Sink select_(X x,Sink s, long skip, long limit, Comparator order, Predicate predicate) {
    return super.select_(x, s, skip, limit, order_ == null ? order : order_, predicate);
  }

  public void removeAll_(X x, long skip, long limit, Comparator order, Predicate predicate) {
    super.removeAll_(x, skip, limit, order_ == null ? order : order_, predicate);
  }
}

@@ -264,16 +264,42 @@
 arator;%0A
+import foam.dao.ListSink;%0A
 import f
@@ -647,16 +647,17 @@
 ct_(X x,
+ 
 Sink s, 
@@ -716,24 +716,65 @@
 redicate) %7B%0A
+    if ( s == null ) s = new ListSink();%0A
     return s

Fix for OrderedDAO not treating null Sink as a ListSink.