diff --git a/querydsl-core/src/main/java/com/mysema/query/types/expr/CollectionExpressionBase.java b/querydsl-core/src/main/java/com/mysema/query/types/expr/CollectionExpressionBase.java index 2e29e83a0..2b7534127 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/expr/CollectionExpressionBase.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/expr/CollectionExpressionBase.java @@ -5,8 +5,6 @@ */ package com.mysema.query.types.expr; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.Collection; import javax.annotation.Nullable; @@ -15,7 +13,6 @@ import com.mysema.query.types.CollectionExpression; import com.mysema.query.types.ConstantImpl; import com.mysema.query.types.Expression; import com.mysema.query.types.Ops; -import com.mysema.query.types.PathMetadata; /** * CollectionExpressionBase is an abstract base class for CollectionExpression implementations @@ -34,14 +31,9 @@ public abstract class CollectionExpressionBase, E> exten @Nullable private volatile NumberExpression size; - @Nullable - private transient volatile Constructor constructor; - public CollectionExpressionBase(Class type) { super(type); } - - public abstract SimpleExpression any(); public final BooleanExpression contains(E child) { return contains(new ConstantImpl(child)); @@ -71,22 +63,6 @@ public abstract class CollectionExpressionBase, E> exten return size; } - @SuppressWarnings("unchecked") - protected > Q newInstance(Class queryType, boolean typed, PathMetadata pm) throws NoSuchMethodException, - InstantiationException, IllegalAccessException, - InvocationTargetException { - if (constructor == null) { - if (typed){ - constructor = queryType.getConstructor(Class.class, PathMetadata.class); - }else{ - constructor = queryType.getConstructor(PathMetadata.class); - } - } - if (typed){ - return (Q)constructor.newInstance(getElementType(), pm); - }else{ - return (Q)constructor.newInstance(pm); - } - } + } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java index aad11294e..946b1908f 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java @@ -17,7 +17,6 @@ import com.mysema.query.types.Path; import com.mysema.query.types.PathImpl; import com.mysema.query.types.PathMetadata; import com.mysema.query.types.Visitor; -import com.mysema.query.types.expr.CollectionExpressionBase; import com.mysema.query.types.expr.SimpleExpression; /** @@ -27,7 +26,7 @@ import com.mysema.query.types.expr.SimpleExpression; * * @param component type */ -public class CollectionPath> extends CollectionExpressionBase,E> implements Path>{ +public class CollectionPath> extends CollectionPathBase,E>{ private static final long serialVersionUID = -4982311799113762600L; @@ -57,7 +56,7 @@ public class CollectionPath> extends Collection public Q any(){ if (any == null){ try { - any = newInstance(queryType, Constants.isTyped(queryType), pathMixin.getMetadata()); + any = newInstance(queryType, pathMixin.getMetadata()); } catch (NoSuchMethodException e) { throw new ExpressionException(e); } catch (InstantiationException e) { diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPathBase.java b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPathBase.java new file mode 100644 index 000000000..320c2dfc2 --- /dev/null +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPathBase.java @@ -0,0 +1,53 @@ +package com.mysema.query.types.path; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; + +import javax.annotation.Nullable; + +import com.mysema.query.types.Path; +import com.mysema.query.types.PathMetadata; +import com.mysema.query.types.expr.CollectionExpressionBase; +import com.mysema.query.types.expr.SimpleExpression; + +/** + * CollectionPath is a base class for collection typed paths + * + * @author tiwe + * + * @param + * @param + */ +public abstract class CollectionPathBase, E> extends CollectionExpressionBase implements Path{ + + private static final long serialVersionUID = -9004995667633601298L; + + public CollectionPathBase(Class type) { + super(type); + } + + @Nullable + private transient volatile Constructor constructor; + + public abstract SimpleExpression any(); + + @SuppressWarnings("unchecked") + protected > Q newInstance(Class queryType, PathMetadata pm) throws NoSuchMethodException, + InstantiationException, IllegalAccessException, + InvocationTargetException { + if (constructor == null) { + if (Constants.isTyped(queryType)){ + constructor = queryType.getConstructor(Class.class, PathMetadata.class); + }else{ + constructor = queryType.getConstructor(PathMetadata.class); + } + } + if (Constants.isTyped(queryType)){ + return (Q)constructor.newInstance(getElementType(), pm); + }else{ + return (Q)constructor.newInstance(pm); + } + } + +} diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java index fe29a6ca9..caefc108d 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java @@ -21,7 +21,6 @@ import com.mysema.query.types.PathImpl; import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathMetadataFactory; import com.mysema.query.types.Visitor; -import com.mysema.query.types.expr.CollectionExpressionBase; import com.mysema.query.types.expr.ListExpression; import com.mysema.query.types.expr.SimpleExpression; @@ -32,7 +31,7 @@ import com.mysema.query.types.expr.SimpleExpression; * * @param component type */ -public class ListPath> extends CollectionExpressionBase,E> implements ListExpression, Path>{ +public class ListPath> extends CollectionPathBase,E> implements ListExpression { private static final long serialVersionUID = 3302301599074388860L; @@ -64,7 +63,7 @@ public class ListPath> extends CollectionExpres public Q any(){ if (any == null){ try { - any = newInstance(pathMixin.getMetadata()); + any = newInstance(queryType, pathMixin.getMetadata()); } catch (NoSuchMethodException e) { throw new ExpressionException(e); } catch (InstantiationException e) { @@ -89,7 +88,7 @@ public class ListPath> extends CollectionExpres private Q create(int index){ try { PathMetadata md = forListAccess(index); - return newInstance(md); + return newInstance(queryType, md); } catch (NoSuchMethodException e) { throw new ExpressionException(e); } catch (InstantiationException e) { @@ -110,7 +109,7 @@ public class ListPath> extends CollectionExpres public Q get(Expression index) { try { PathMetadata md = forListAccess(index); - return newInstance(md); + return newInstance(queryType, md); } catch (NoSuchMethodException e) { throw new ExpressionException(e); } catch (InstantiationException e) { @@ -122,10 +121,6 @@ public class ListPath> extends CollectionExpres } } - private Q newInstance(PathMetadata md) throws NoSuchMethodException, InstantiationException, - IllegalAccessException, InvocationTargetException { - return newInstance(queryType, Constants.isTyped(queryType), md); - } @Override public Q get(int index) { diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java index ff8040d8a..611006adc 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java @@ -14,10 +14,9 @@ import javax.annotation.Nullable; import com.mysema.commons.lang.Assert; import com.mysema.query.types.ExpressionException; import com.mysema.query.types.Path; -import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathImpl; +import com.mysema.query.types.PathMetadata; import com.mysema.query.types.Visitor; -import com.mysema.query.types.expr.CollectionExpressionBase; import com.mysema.query.types.expr.SimpleExpression; /** @@ -27,7 +26,7 @@ import com.mysema.query.types.expr.SimpleExpression; * * @param component type */ -public class SetPath> extends CollectionExpressionBase,E> implements Path> { +public class SetPath> extends CollectionPathBase,E> { private static final long serialVersionUID = 4145848445507037373L; @@ -57,7 +56,7 @@ public class SetPath> extends CollectionExpress public Q any(){ if (any == null){ try { - any = newInstance(queryType, Constants.isTyped(queryType), pathMixin.getMetadata()); + any = newInstance(queryType, pathMixin.getMetadata()); } catch (NoSuchMethodException e) { throw new ExpressionException(e); } catch (InstantiationException e) { diff --git a/querydsl-core/src/main/java/com/mysema/query/types/query/ListSubQuery.java b/querydsl-core/src/main/java/com/mysema/query/types/query/ListSubQuery.java index 848968ffc..5a2279d44 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/query/ListSubQuery.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/query/ListSubQuery.java @@ -51,11 +51,6 @@ public final class ListSubQuery extends CollectionExpressionBase,A> i return v.visit(this, context); } - @Override - public SimpleExpression any(){ - throw new UnsupportedOperationException(); - } - @Override public boolean equals(Object o) { return subQueryMixin.equals(o); diff --git a/querydsl-core/src/test/java/com/mysema/query/types/ConstantImplTest.java b/querydsl-core/src/test/java/com/mysema/query/types/ConstantImplTest.java new file mode 100644 index 000000000..2ff57bb14 --- /dev/null +++ b/querydsl-core/src/test/java/com/mysema/query/types/ConstantImplTest.java @@ -0,0 +1,21 @@ +package com.mysema.query.types; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ConstantImplTest { + + @Test + public void Create(){ + assertNotNull(ConstantImpl.create(true)); + assertNotNull(ConstantImpl.create((byte)1)); + assertNotNull(ConstantImpl.create(ConstantImplTest.class)); + assertNotNull(ConstantImpl.create(1)); + assertNotNull(ConstantImpl.create(1l)); + assertNotNull(ConstantImpl.create((short)1)); + assertNotNull(ConstantImpl.create("x")); + assertNotNull(ConstantImpl.create("x",true)); + } + +} diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java index 4a23ed817..815ec5380 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java @@ -150,7 +150,11 @@ public class PathTest { paths.add(new StringPath("p")); paths.add(new TimePath(Time.class,"p")); - // TODO : assertions + for (Path path : paths){ + assertNotNull(path.getMetadata()); + assertNotNull(path.getType()); + assertEquals(path, path.getRoot()); + } } }