/*
* Copyright (c) 2009 Mysema Ltd.
* All rights reserved.
*
*/
package com.mysema.query.collections;
import static com.mysema.query.collections.utils.QueryIteratorUtils.multiArgFilter;
import static com.mysema.query.collections.utils.QueryIteratorUtils.toArrayIterator;
import static com.mysema.query.collections.utils.QueryIteratorUtils.transform;
import java.io.IOException;
import java.util.*;
import org.apache.commons.collections15.IteratorUtils;
import org.apache.commons.collections15.iterators.IteratorChain;
import com.mysema.query.JoinExpression;
import com.mysema.query.QueryBase;
import com.mysema.query.collections.eval.Evaluator;
import com.mysema.query.collections.iterators.FilteringMultiIterator;
import com.mysema.query.collections.iterators.MultiIterator;
import com.mysema.query.collections.support.DefaultIndexSupport;
import com.mysema.query.collections.support.DefaultSourceSortingSupport;
import com.mysema.query.collections.support.MultiComparator;
import com.mysema.query.collections.support.SimpleIteratorSource;
import com.mysema.query.collections.utils.EvaluatorUtils;
import com.mysema.query.grammar.JavaOps;
import com.mysema.query.grammar.Ops;
import com.mysema.query.grammar.Order;
import com.mysema.query.grammar.OrderSpecifier;
import com.mysema.query.grammar.types.Expr;
import com.mysema.query.grammar.types.Operation;
import com.mysema.query.grammar.types.Expr.EBoolean;
import com.mysema.query.util.CloseableIterator;
/**
* AbstractColQuery provides a base class for Collection query implementations.
* Extend it like this
*
*
* public class MyType extends AbstractColQuery{
* ...
* }
*
*
* @see ColQuery
*
* @author tiwe
* @version $Id$
*/
public class AbstractColQuery> {
@SuppressWarnings("unchecked")
private final SubType _this = (SubType)this;
private final Map, Iterable>> exprToIt = new HashMap, Iterable>>();
private QueryIndexSupport indexSupport;
private final JavaOps ops;
private final InnerQuery query = new InnerQuery();
private boolean sortSources = true, wrapIterators = true, sequentialUnion = false;
private SourceSortingSupport sourceSortingSupport;
public AbstractColQuery() {
this(JavaOps.DEFAULT);
}
public AbstractColQuery(JavaOps ops) {
this.ops = ops;
this.sourceSortingSupport = new DefaultSourceSortingSupport();
}
protected QueryIndexSupport createIndexSupport(Map, Iterable>> exprToIt, JavaOps ops, List> sources){
return new DefaultIndexSupport(new SimpleIteratorSource(exprToIt), ops, sources);
}
public void close(){
// overwrite
}
protected SubType alias(Expr path, Iterable col) {
exprToIt.put(path, col);
return _this;
}
private A[] asArray(A[] target, A first, A second, A... rest) {
target[0] = first;
target[1] = second;
System.arraycopy(rest, 0, target, 2, rest.length);
return target;
}
public SubType from(Expr entity, A first, A... rest) {
List list = new ArrayList(rest.length + 1);
list.add(first);
list.addAll(Arrays.asList(rest));
return from(entity, list);
}
public SubType from(Expr entity, Iterable col) {
alias(entity, col);
query.from((Expr>)entity);
return _this;
}
@SuppressWarnings("unchecked")
public CloseableIterator