From 36da4da8307445c9d05fa2a37d22fc17b20eefff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Thu, 26 Mar 2009 14:03:43 +0000 Subject: [PATCH] added OperationPatterns / Visitor based abstract syntax which is accessible via Expr.toString() --- .../query/collections/AbstractColQuery.java | 45 ++++++++++++++++--- .../query/collections/ColQueryTest.java | 7 +++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/querydsl-collections/src/main/java/com/mysema/query/collections/AbstractColQuery.java b/querydsl-collections/src/main/java/com/mysema/query/collections/AbstractColQuery.java index 33b9b1c6a..d6f9162b8 100644 --- a/querydsl-collections/src/main/java/com/mysema/query/collections/AbstractColQuery.java +++ b/querydsl-collections/src/main/java/com/mysema/query/collections/AbstractColQuery.java @@ -9,6 +9,7 @@ import static com.mysema.query.collections.utils.QueryIteratorUtils.multiArgFilt import static com.mysema.query.collections.utils.QueryIteratorUtils.toArrayIterator; import static com.mysema.query.collections.utils.QueryIteratorUtils.transform; +import java.io.Closeable; import java.io.IOException; import java.util.*; @@ -49,7 +50,7 @@ import com.mysema.query.util.CloseableIterator; * @author tiwe * @version $Id$ */ -public class AbstractColQuery> { +public class AbstractColQuery> implements Closeable{ @SuppressWarnings("unchecked") private final SubType _this = (SubType)this; @@ -79,6 +80,9 @@ public class AbstractColQuery> { return new DefaultIndexSupport(new SimpleIteratorSource(exprToIt), ops, sources); } + /** + * Close the Query and related datasource connection + */ public void close(){ // overwrite } @@ -108,6 +112,14 @@ public class AbstractColQuery> { return _this; } + /** + * Query and project an array with the given variables + * + * @param e1 + * @param e2 + * @param rest + * @return + */ @SuppressWarnings("unchecked") public CloseableIterator iterate(Expr e1, Expr e2, Expr... rest) { // TODO : move this code to querydsl-core @@ -129,6 +141,13 @@ public class AbstractColQuery> { return iterate(new Expr.EArrayConstructor(type, full)); } + /** + * Query and project the given projection + * + * @param + * @param projection + * @return + */ public CloseableIterator iterate(Expr projection) { return wrap(query.iterate(projection)); } @@ -137,6 +156,11 @@ public class AbstractColQuery> { return iterate(MiniApi.getAny(alias)); } + /** + * Count all results for a query formed from the FROM and WHERE parts + * + * @return + */ public long count(){ try { return query.count(); @@ -146,6 +170,7 @@ public class AbstractColQuery> { } /** + * List the results for the given projection * NOTE : use iterate for huge projections * * @param e1 @@ -167,6 +192,7 @@ public class AbstractColQuery> { } /** + * List the results for the given projection * NOTE : use iterate for huge projections * * @param @@ -250,6 +276,10 @@ public class AbstractColQuery> { }; } + protected EBoolean normalize(EBoolean e) { + return e; + } + public class InnerQuery extends QueryBase { private Iterator createIterator(Expr projection) throws Exception { @@ -269,10 +299,10 @@ public class AbstractColQuery> { } // select - return wrap(handleSelect(it, sources, projection)); + return handleSelect(it, sources, projection); }else{ - return wrap(Collections.emptyList().iterator()); + return Collections.emptyList().iterator(); } } @@ -292,6 +322,11 @@ public class AbstractColQuery> { } return count; } + + @Override + protected EBoolean normalize(EBoolean e){ + return AbstractColQuery.this.normalize(e); + } protected Iterator handleFromAndWhere(List> sources) throws Exception{ EBoolean condition = where.create(); @@ -394,8 +429,4 @@ public class AbstractColQuery> { } } - - - - } diff --git a/querydsl-collections/src/test/java/com/mysema/query/collections/ColQueryTest.java b/querydsl-collections/src/test/java/com/mysema/query/collections/ColQueryTest.java index e09b55582..fb43d0196 100644 --- a/querydsl-collections/src/test/java/com/mysema/query/collections/ColQueryTest.java +++ b/querydsl-collections/src/test/java/com/mysema/query/collections/ColQueryTest.java @@ -115,6 +115,13 @@ public class ColQueryTest extends AbstractQueryTest{ } + @Test + public void testAlias11(){ + QCat cat = new QCat("cat"); + Cat c = alias(Cat.class, cat); + assertEquals(cat.name, $(c.getName())); + } + @Test public void testAlias2(){ query().from(cat, c1, c2).from(otherCat, c2, c3)