mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-24 21:07:26 +08:00
This commit is contained in:
parent
6a41c2fa19
commit
a6ae9f1b7e
@ -20,6 +20,8 @@ import com.mysema.query.collections.iterators.FilteringIterator;
|
||||
import com.mysema.query.collections.iterators.MultiIterator;
|
||||
import com.mysema.query.collections.iterators.ProjectingIterator;
|
||||
import com.mysema.query.grammar.JavaSerializer;
|
||||
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.Path;
|
||||
import com.mysema.query.serialization.OperationPatterns;
|
||||
@ -56,11 +58,35 @@ public class InnerQuery extends QueryBase<Object, InnerQuery> {
|
||||
private <RT> Iterator<RT> createIterator(Expr<RT> projection) throws Exception {
|
||||
// from
|
||||
List<Expr<?>> sources = new ArrayList<Expr<?>>();
|
||||
MultiIterator multiIt = new MultiIterator();
|
||||
MultiIterator multiIt = new MultiIterator();
|
||||
|
||||
// order
|
||||
Map<Path<?>,Order> orders = null;
|
||||
boolean sortOnIterate = !orderBy.isEmpty();
|
||||
if (sortOnIterate){
|
||||
orders = new HashMap<Path<?>,Order>();
|
||||
for (OrderSpecifier<?> order : orderBy){
|
||||
if (!(order.target instanceof Path)) sortOnIterate = false;
|
||||
orders.put((Path<?>)order.target, order.order);
|
||||
}
|
||||
}
|
||||
|
||||
for (JoinExpression<?> join : joins) {
|
||||
sources.add(join.getTarget());
|
||||
multiIt.add(pathToIterable.get(join.getTarget()));
|
||||
}
|
||||
if (sortOnIterate){
|
||||
for (JoinExpression<?> join : joins) {
|
||||
Iterable<?> iterable = pathToIterable.get(join.getTarget());
|
||||
if (orders.containsKey(join.getTarget())){
|
||||
// TODO : reorder the iterable instance
|
||||
}
|
||||
multiIt.add(iterable);
|
||||
}
|
||||
}else{
|
||||
for (JoinExpression<?> join : joins) {
|
||||
multiIt.add(pathToIterable.get(join.getTarget()));
|
||||
}
|
||||
}
|
||||
Iterator<?> it = multiIt.init();
|
||||
|
||||
// where
|
||||
@ -70,7 +96,7 @@ public class InnerQuery extends QueryBase<Object, InnerQuery> {
|
||||
boolean.class);
|
||||
it = new FilteringIterator<Object>(it, ev);
|
||||
}
|
||||
|
||||
|
||||
// select
|
||||
ExpressionEvaluator ev = new JavaSerializer(ops).handle(
|
||||
projection).createExpressionEvaluator(sources,
|
||||
|
||||
@ -22,7 +22,6 @@ import org.codehaus.janino.Scanner.ScanException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mysema.query.grammar.Ops.Op;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Path;
|
||||
import com.mysema.query.grammar.types.Alias.ASimple;
|
||||
|
||||
@ -179,6 +179,16 @@ public class MiniApiTest {
|
||||
.iterate($(c)).iterator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlias8(){
|
||||
Cat c = alias(Cat.class, "cat");
|
||||
|
||||
from($(c),cats)
|
||||
.where($(c.getMate().getName()).startsWith("B"))
|
||||
.orderBy($(c.getName()).desc())
|
||||
.iterate($(c)).iterator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapUsage(){
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user