package quile.CayenneQuery;

import org.apache.cayenne.BaseContext;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.query.SelectQuery;
import org.apache.cayenne.query.Ordering;
import java.util.List;
import java.util.ArrayList;

class Query {

    private ObjectContext _objectContext;
    private int _limit;
    private int _offset;
    private boolean _distinct;
    private List<Ordering> _sortOrderings = new ArrayList<Ordering>();

    public ObjectContext _objectContext() {
        if (_objectContext == null) {
            _objectContext = BaseContext.getThreadObjectContext();
        }
        return _objectContext;
    }

    public Query() {
        // initialise empty query object with sensible defaults
    }

    public Query(ObjectContext objectContext) {
        this._objectContext = objectContext;
    }

    public Query(DataContext dataContext) {
        this._objectContext = dataContext;
    }

    public Query limit(int limit) {
        _limit = limit;
        return this;
    }

    public Query offset(int offset) {
        _offset = offset;
        return this;
    }

    public static void main(String args[]) {
        System.out.println("foo!");
    }
}

@@ -235,16 +235,102 @@
 dering;%0A
+import org.apache.cayenne.query.SortOrder;%0Aimport org.apache.cayenne.exp.Expression;%0A%0A
 import j
@@ -344,16 +344,16 @@
 l.List;%0A
-
 import j
@@ -580,16 +580,153 @@
 ring%3E();
+%0A    private List%3CExpression%3E _expressions = new ArrayList%3CExpression%3E();%0A    private List%3CObject%3E _parameters = new ArrayList%3CObject%3E();
 %0A%0A    pu
@@ -1324,24 +1324,24 @@
 t offset) %7B%0A
-
         _off
@@ -1374,32 +1374,1108 @@
 rn this;%0A    %7D%0A%0A
+    public Query orderBy(String path, boolean isAscending, boolean ignoreCase) %7B%0A        SortOrder sortOrder = SortOrder.ASCENDING;%0A%0A        if (isAscending) %7B%0A            if (ignoreCase) %7B%0A                sortOrder = SortOrder.ASCENDING_INSENSITIVE;%0A            %7D%0A        %7D else %7B%0A            if (ignoreCase) %7B%0A                sortOrder = SortOrder.DESCENDING_INSENSITIVE;%0A            %7D else %7B%0A                sortOrder = SortOrder.DESCENDING;%0A            %7D%0A        %7D%0A        Ordering o = new Ordering(path, sortOrder);%0A        return this;%0A    %7D%0A%0A    public Query orderBy(String path, boolean isAscending) %7B%0A        return orderBy(path, isAscending, false);%0A    %7D%0A%0A    public Query orderBy(String path) %7B%0A        return orderBy(path, true, false);%0A    %7D%0A%0A    public Query filter(String filter, Object... args) %7B%0A        Expression exp = Expression.fromString(filter);%0A        _expressions.add(exp);%0A%0A        if (args != null) %7B%0A            for (int i = 0; i %3C args.length; i++) %7B%0A                _parameters.add(args%5Bi%5D);%0A            %7D%0A        %7D%0A        return this;%0A    %7D%0A%0A
     public stati

Filling in the gaps