package foam.dao;

import foam.core.*;
import foam.dao.*;
import foam.mlang.*;
import foam.mlang.predicate.*;
import foam.mlang.order.*;

public abstract class AbstractDAO extends ContextAwareSupport implements DAO {
  public DAO where(Predicate predicate) {
    return ((FilteredDAO)getX().create(FilteredDAO.class)).setPredicate(predicate);
  }

  public DAO orderBy(Comparator comparator) {
    return ((OrderedDAO)getX().create(OrderedDAO.class)).setOrder(comparator);
  }

  public DAO skip(int count) {
    return ((SkipDAO)getX().create(SkipDAO.class)).setSkip(count);
  }

  public DAO limit(int count) {
    return ((LimitedDAO)getX().create(LimitedDAO.class)).setLimit(count);
  }

  public void pipe(foam.dao.Sink sink) {
    throw new UnsupportedOperationException();
  }

  protected Sink decorateSink_(Sink sink, Integer skip, Integer limit, Comparator order, Predicate predicate) {
    if ( limit != null ) {
      sink = ((LimitedSink)getX().create(LimitedSink.class)).setLimit(limit.intValue());
    }

    if ( skip != null ) {
      sink = ((SkipSink)getX().create(SkipSink.class)).setSkip(skip.intValue());
    }

    if ( order != null ) {
      sink = ((OrderedSink)getX().create(OrderedSink.class)).setComparator(order);
    }

    if ( predicate != null ) {
      sink = ((PredicatedSink)getX().create(PredicatedSink.class)).setPredicate(predicate);
    }

    return sink;
  }
}

@@ -330,24 +330,42 @@
 e(predicate)
+.setDelegate(this)
 ;%0A  %7D%0A%0A  pub
@@ -482,16 +482,34 @@
 parator)
+.setDelegate(this)
 ;%0A  %7D%0A%0A 
@@ -599,24 +599,42 @@
 tSkip(count)
+.setDelegate(this)
 ;%0A  %7D%0A%0A  pub
@@ -732,16 +732,34 @@
 t(count)
+.setDelegate(this)
 ;%0A  %7D%0A%0A 
@@ -1068,32 +1068,50 @@
 imit.intValue())
+.setDelegate(sink)
 ;%0A    %7D%0A%0A    if 
@@ -1208,16 +1208,34 @@
 Value())
+.setDelegate(sink)
 ;%0A    %7D%0A
@@ -1343,16 +1343,34 @@
 r(order)
+.setDelegate(sink)
 ;%0A    %7D%0A
@@ -1491,16 +1491,34 @@
 edicate)
+.setDelegate(sink)
 ;%0A    %7D%0A

Add DAO and Sink decoration to AbstractDAO.