#182 disallowed joins to subqueries in JPA module

This commit is contained in:
Timo Westkämper 2012-06-28 23:40:36 +03:00
parent e51659aa66
commit 684e932a1d
10 changed files with 75 additions and 87 deletions

View File

@ -13,6 +13,7 @@
*/
package com.mysema.query.collections;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -81,7 +82,7 @@ public abstract class AbstractColQuery<Q extends AbstractColQuery<Q>> extends P
}
}
private <D> Expression<D> createAlias(CollectionExpression<?,D> target, Path<D> alias){
private <D> Expression<D> createAlias(Path<? extends Collection<D>> target, Path<D> alias){
return OperationImpl.create(alias.getType(), Ops.ALIAS, target, alias);
}
@ -109,7 +110,7 @@ public abstract class AbstractColQuery<Q extends AbstractColQuery<Q>> extends P
}
@SuppressWarnings("unchecked")
public <P> Q innerJoin(CollectionExpression<?, P> target, Path<P> alias) {
public <P> Q innerJoin(Path<? extends Collection<P>> target, Path<P> alias) {
getMetadata().addJoin(JoinType.INNERJOIN, createAlias(target, alias));
return (Q)this;
}

View File

@ -13,9 +13,10 @@
*/
package com.mysema.query.collections;
import java.util.Collection;
import com.mysema.query.Projectable;
import com.mysema.query.SimpleQuery;
import com.mysema.query.types.CollectionExpression;
import com.mysema.query.types.MapExpression;
import com.mysema.query.types.Path;
@ -61,7 +62,7 @@ public interface ColQuery extends SimpleQuery<ColQuery>, Projectable {
* @param alias
* @return
*/
<P> ColQuery innerJoin(CollectionExpression<?, P> collectionPath, Path<P> alias);
<P> ColQuery innerJoin(Path<? extends Collection<P>> collectionPath, Path<P> alias);
/**
* Define an inner join from the Map typed path to the alias

View File

@ -18,7 +18,6 @@ import com.mysema.query.QueryMetadata;
import com.mysema.query.support.CollectionAnyVisitor;
import com.mysema.query.support.Context;
import com.mysema.query.support.QueryMixin;
import com.mysema.query.types.CollectionExpression;
import com.mysema.query.types.Path;
import com.mysema.query.types.Predicate;
import com.mysema.query.types.template.BooleanTemplate;
@ -44,18 +43,8 @@ public class ColQueryMixin<T> extends QueryMixin<T> {
super(self, metadata);
}
@Override
protected Predicate[] normalize(Predicate[] conditions, boolean where) {
for (int i = 0; i < conditions.length; i++) {
if (conditions[i] != null) {
conditions[i] = normalize(conditions[i], where);
}
}
return conditions;
}
@SuppressWarnings("unchecked")
private Predicate normalize(Predicate predicate, boolean where) {
protected Predicate normalize(Predicate predicate, boolean where) {
if (predicate instanceof BooleanBuilder && ((BooleanBuilder)predicate).getValue() == null) {
return predicate;
} else {
@ -63,7 +52,7 @@ public class ColQueryMixin<T> extends QueryMixin<T> {
Predicate transformed = (Predicate) predicate.accept(CollectionAnyVisitor.DEFAULT, context);
for (int i = 0; i < context.paths.size(); i++) {
innerJoin(
(CollectionExpression)context.paths.get(i).getMetadata().getParent(),
(Path)context.paths.get(i).getMetadata().getParent(),
(Path)context.replacements.get(i));
on(ANY);
}

View File

@ -13,6 +13,7 @@
*/
package com.mysema.query.support;
import java.util.Collection;
import java.util.UUID;
import com.mysema.commons.lang.Assert;
@ -94,7 +95,7 @@ public class QueryMixin<T> {
String suffix = UUID.randomUUID().toString().replace("-", "").substring(0,5);
String name = uncapitalize(path.getType().getSimpleName()) + suffix;
Path joined = new PathImpl(path.getType(), name);
this.innerJoin((CollectionExpression)path.getMetadata().getParent(), joined);
this.innerJoin((Path)path.getMetadata().getParent(), joined);
return joined;
} else if (expr instanceof ProjectionRole<?>) {
return convert(((ProjectionRole) expr).getProjection());
@ -105,7 +106,7 @@ public class QueryMixin<T> {
}
}
public Expression<?>[] convert(Expression<?>[] exprs){
public final Expression<?>[] convert(Expression<?>[] exprs){
for (int i = 0; i < exprs.length; i++) {
exprs[i] = convert(exprs[i]);
}
@ -118,7 +119,7 @@ public class QueryMixin<T> {
return ExpressionUtils.as(path, alias);
}
protected <D> Expression<D> createAlias(CollectionExpression<?,D> target, Path<D> alias){
protected <D> Expression<D> createAlias(Path<? extends Collection<D>> target, Path<D> alias){
assertRoot(alias);
return OperationImpl.create(alias.getType(), Ops.ALIAS, target, alias);
}
@ -162,12 +163,12 @@ public class QueryMixin<T> {
return self;
}
public <P> T fullJoin(CollectionExpression<?,P> target) {
public <P> T fullJoin(Path<? extends Collection<P>> target) {
metadata.addJoin(JoinType.FULLJOIN, target);
return self;
}
public <P> T fullJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> T fullJoin(Path<? extends Collection<P>> target, Path<P> alias) {
metadata.addJoin(JoinType.FULLJOIN, createAlias(target, alias));
return self;
}
@ -216,12 +217,12 @@ public class QueryMixin<T> {
return self;
}
public <P> T innerJoin(CollectionExpression<?,P> target) {
public <P> T innerJoin(Path<? extends Collection<P>> target) {
metadata.addJoin(JoinType.INNERJOIN, target);
return self;
}
public <P> T innerJoin(CollectionExpression<?,P>target, Path<P> alias) {
public <P> T innerJoin(Path<? extends Collection<P>>target, Path<P> alias) {
metadata.addJoin(JoinType.INNERJOIN, createAlias(target, alias));
return self;
}
@ -260,12 +261,12 @@ public class QueryMixin<T> {
return getSelf();
}
public <P> T join(CollectionExpression<?,P> target) {
public <P> T join(Path<? extends Collection<P>> target) {
metadata.addJoin(JoinType.JOIN, target);
return getSelf();
}
public <P> T join(CollectionExpression<?,P> target, Path<P> alias) {
public <P> T join(Path<? extends Collection<P>> target, Path<P> alias) {
metadata.addJoin(JoinType.JOIN, createAlias(target, alias));
return getSelf();
}
@ -296,12 +297,12 @@ public class QueryMixin<T> {
return getSelf();
}
public <P> T leftJoin(CollectionExpression<?,P> target) {
public <P> T leftJoin(Path<? extends Collection<P>> target) {
metadata.addJoin(JoinType.LEFTJOIN, target);
return getSelf();
}
public <P> T leftJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> T leftJoin(Path<? extends Collection<P>> target, Path<P> alias) {
metadata.addJoin(JoinType.LEFTJOIN, createAlias(target, alias));
return getSelf();
}
@ -359,12 +360,12 @@ public class QueryMixin<T> {
return getSelf();
}
public <P> T rightJoin(CollectionExpression<?,P> target) {
public <P> T rightJoin(Path<? extends Collection<P>> target) {
metadata.addJoin(JoinType.RIGHTJOIN, target);
return getSelf();
}
public <P> T rightJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> T rightJoin(Path<? extends Collection<P>> target, Path<P> alias) {
metadata.addJoin(JoinType.RIGHTJOIN, createAlias(target, alias));
return getSelf();
}
@ -407,7 +408,16 @@ public class QueryMixin<T> {
return self;
}
protected Predicate[] normalize(Predicate[] conditions, boolean where) {
protected Predicate normalize(Predicate condition, boolean where) {
return condition;
}
protected final Predicate[] normalize(Predicate[] conditions, boolean where) {
for (int i = 0; i < conditions.length; i++) {
if (conditions[i] != null) {
conditions[i] = normalize(conditions[i], where);
}
}
return conditions;
}

View File

@ -13,12 +13,14 @@
*/
package com.mysema.query.jdo;
import java.util.Collection;
import com.mysema.query.DefaultQueryMetadata;
import com.mysema.query.QueryMetadata;
import com.mysema.query.support.DetachableQuery;
import com.mysema.query.types.CollectionExpression;
import com.mysema.query.types.EntityPath;
import com.mysema.query.types.Expression;
import com.mysema.query.types.Path;
/**
* Abstract superclass for SubQuery implementations
@ -43,7 +45,7 @@ public class AbstractJDOQLSubQuery<Q extends AbstractJDOQLSubQuery<Q>> extends D
return queryMixin.from(args);
}
public <P> Q from(CollectionExpression<?,P> target, EntityPath<P> alias) {
public <P> Q from(Path<? extends Collection<P>> target, EntityPath<P> alias) {
return queryMixin.join(target, alias);
}

View File

@ -42,18 +42,9 @@ public class JDOQLQueryMixin<T> extends QueryMixin<T> {
public JDOQLQueryMixin(T self, QueryMetadata metadata) {
super(self, metadata);
}
@Override
protected Predicate[] normalize(Predicate[] conditions, boolean where) {
for (int i = 0; i < conditions.length; i++) {
if (conditions[i] != null) {
conditions[i] = normalize(conditions[i], where);
}
}
return conditions;
}
private Predicate normalize(Predicate predicate, boolean where) {
protected Predicate normalize(Predicate predicate, boolean where) {
if (predicate instanceof BooleanBuilder && ((BooleanBuilder)predicate).getValue() == null) {
return predicate;
} else {

View File

@ -13,12 +13,13 @@
*/
package com.mysema.query.jpa;
import java.util.Collection;
import com.mysema.query.DefaultQueryMetadata;
import com.mysema.query.JoinExpression;
import com.mysema.query.JoinType;
import com.mysema.query.QueryMetadata;
import com.mysema.query.support.DetachableQuery;
import com.mysema.query.types.CollectionExpression;
import com.mysema.query.types.EntityPath;
import com.mysema.query.types.MapExpression;
import com.mysema.query.types.Path;
@ -65,11 +66,11 @@ public class AbstractJPQLSubQuery<Q extends AbstractJPQLSubQuery<Q>> extends Det
return queryMixin.from(o);
}
public <P> Q fullJoin(CollectionExpression<?,P> target) {
public <P> Q fullJoin(Path<? extends Collection<P>> target) {
return queryMixin.fullJoin(target);
}
public <P> Q fullJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q fullJoin(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.fullJoin(target, alias);
}
@ -89,11 +90,11 @@ public class AbstractJPQLSubQuery<Q extends AbstractJPQLSubQuery<Q>> extends Det
return queryMixin.fullJoin(target, alias);
}
public <P> Q innerJoin(CollectionExpression<?,P> target) {
public <P> Q innerJoin(Path<? extends Collection<P>> target) {
return queryMixin.innerJoin(target);
}
public <P> Q innerJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q innerJoin(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.innerJoin(target, alias);
}
@ -113,11 +114,11 @@ public class AbstractJPQLSubQuery<Q extends AbstractJPQLSubQuery<Q>> extends Det
return queryMixin.innerJoin(target, alias);
}
public <P> Q join(CollectionExpression<?,P> target) {
public <P> Q join(Path<? extends Collection<P>> target) {
return queryMixin.join(target);
}
public <P> Q join(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q join(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.join(target, alias);
}
@ -137,11 +138,11 @@ public class AbstractJPQLSubQuery<Q extends AbstractJPQLSubQuery<Q>> extends Det
return queryMixin.join(target, alias);
}
public <P> Q leftJoin(CollectionExpression<?,P> target) {
public <P> Q leftJoin(Path<? extends Collection<P>> target) {
return queryMixin.leftJoin(target);
}
public <P> Q leftJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q leftJoin(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.leftJoin(target, alias);
}
@ -161,11 +162,11 @@ public class AbstractJPQLSubQuery<Q extends AbstractJPQLSubQuery<Q>> extends Det
return queryMixin.leftJoin(target, alias);
}
public <P> Q rightJoin(CollectionExpression<?,P> target) {
public <P> Q rightJoin(Path<? extends Collection<P>> target) {
return queryMixin.rightJoin(target);
}
public <P> Q rightJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q rightJoin(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.rightJoin(target, alias);
}

View File

@ -13,6 +13,8 @@
*/
package com.mysema.query.jpa;
import java.util.Collection;
import com.mysema.query.Query;
import com.mysema.query.types.CollectionExpression;
import com.mysema.query.types.EntityPath;
@ -66,7 +68,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param target
* @return
*/
<P> Q innerJoin(CollectionExpression<?,P> target);
<P> Q innerJoin(Path<? extends Collection<P>> target);
/**
* Create a inner join with the given target and alias.
@ -76,7 +78,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param alias
* @return
*/
<P> Q innerJoin(CollectionExpression<?,P> target, Path<P> alias);
<P> Q innerJoin(Path<? extends Collection<P>> target, Path<P> alias);
/**
* Create a inner join with the given target.
@ -126,7 +128,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param target
* @return
*/
<P> Q join(CollectionExpression<?,P> target);
<P> Q join(Path<? extends Collection<P>> target);
/**
* @param <P>
@ -134,7 +136,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param alias
* @return
*/
<P> Q join(CollectionExpression<?,P> target, Path<P> alias);
<P> Q join(Path<? extends Collection<P>> target, Path<P> alias);
/**
* Create a join with the given target.
@ -184,7 +186,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param target
* @return
*/
<P> Q leftJoin(CollectionExpression<?,P> target);
<P> Q leftJoin(Path<? extends Collection<P>> target);
/**
* Create a left join with the given target and alias.
@ -194,7 +196,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param alias
* @return
*/
<P> Q leftJoin(CollectionExpression<?,P> target, Path<P> alias);
<P> Q leftJoin(Path<? extends Collection<P>> target, Path<P> alias);
/**
* Create a left join with the given target.
@ -244,7 +246,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param target
* @return
*/
<P> Q rightJoin(CollectionExpression<?,P> target);
<P> Q rightJoin(Path<? extends Collection<P>> target);
/**
* Create a right join with the given target and alias.
@ -254,7 +256,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param alias
* @return
*/
<P> Q rightJoin(CollectionExpression<?,P> target, Path<P> alias);
<P> Q rightJoin(Path<? extends Collection<P>> target, Path<P> alias);
/**
* Create a right join with the given target.
@ -305,7 +307,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param target
* @return
*/
<P> Q fullJoin(CollectionExpression<?,P> target);
<P> Q fullJoin(Path<? extends Collection<P>> target);
/**
* Create a full join with the given target and alias.
@ -315,7 +317,7 @@ public interface JPQLCommonQuery<Q extends JPQLCommonQuery<Q>> extends Query<Q>
* @param alias
* @return
*/
<P> Q fullJoin(CollectionExpression<?,P> target, Path<P> alias);
<P> Q fullJoin(Path<? extends Collection<P>> target, Path<P> alias);
/**
* Create a full join with the given target.

View File

@ -13,6 +13,7 @@
*/
package com.mysema.query.jpa;
import java.util.Collection;
import java.util.Map;
import javax.annotation.Nullable;
@ -20,7 +21,6 @@ import javax.persistence.EntityManager;
import com.mysema.query.QueryMetadata;
import com.mysema.query.support.ProjectableQuery;
import com.mysema.query.types.CollectionExpression;
import com.mysema.query.types.EntityPath;
import com.mysema.query.types.MapExpression;
import com.mysema.query.types.Path;
@ -96,11 +96,11 @@ public abstract class JPQLQueryBase<Q extends JPQLQueryBase<Q>> extends Projecta
return queryMixin.from(args);
}
public <P> Q fullJoin(CollectionExpression<?,P> target) {
public <P> Q fullJoin(Path<? extends Collection<P>> target) {
return queryMixin.fullJoin(target);
}
public <P> Q fullJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q fullJoin(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.fullJoin(target, alias);
}
@ -124,11 +124,11 @@ public abstract class JPQLQueryBase<Q extends JPQLQueryBase<Q>> extends Projecta
return constants;
}
public <P> Q innerJoin(CollectionExpression<?,P> target) {
public <P> Q innerJoin(Path<? extends Collection<P>> target) {
return queryMixin.innerJoin(target);
}
public <P> Q innerJoin(CollectionExpression<?,P>target, Path<P> alias) {
public <P> Q innerJoin(Path<? extends Collection<P>>target, Path<P> alias) {
return queryMixin.innerJoin(target, alias);
}
@ -148,11 +148,11 @@ public abstract class JPQLQueryBase<Q extends JPQLQueryBase<Q>> extends Projecta
return queryMixin.innerJoin(target, alias);
}
public <P> Q join(CollectionExpression<?,P> target) {
public <P> Q join(Path<? extends Collection<P>> target) {
return queryMixin.join(target);
}
public <P> Q join(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q join(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.join(target, alias);
}
@ -172,11 +172,11 @@ public abstract class JPQLQueryBase<Q extends JPQLQueryBase<Q>> extends Projecta
return queryMixin.join(target, alias);
}
public <P> Q leftJoin(CollectionExpression<?,P> target) {
public <P> Q leftJoin(Path<? extends Collection<P>> target) {
return queryMixin.leftJoin(target);
}
public <P> Q leftJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q leftJoin(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.leftJoin(target, alias);
}
@ -196,11 +196,11 @@ public abstract class JPQLQueryBase<Q extends JPQLQueryBase<Q>> extends Projecta
return queryMixin.leftJoin(target, alias);
}
public <P> Q rightJoin(CollectionExpression<?,P> target) {
public <P> Q rightJoin(Path<? extends Collection<P>> target) {
return queryMixin.rightJoin(target);
}
public <P> Q rightJoin(CollectionExpression<?,P> target, Path<P> alias) {
public <P> Q rightJoin(Path<? extends Collection<P>> target, Path<P> alias) {
return queryMixin.rightJoin(target, alias);
}

View File

@ -76,17 +76,8 @@ public class JPQLQueryMixin<T> extends QueryMixin<T> {
return getSelf();
}
@Override
protected Predicate[] normalize(Predicate[] conditions, boolean where) {
for (int i = 0; i < conditions.length; i++){
if (conditions[i] != null) {
conditions[i] = normalize(conditions[i], where);
}
}
return conditions;
}
private Predicate normalize(Predicate predicate, boolean where) {
@Override
protected Predicate normalize(Predicate predicate, boolean where) {
if (predicate instanceof BooleanBuilder && ((BooleanBuilder)predicate).getValue() == null){
return predicate;
} else {