Skip to content

Commit

Permalink
#182 disallowed joins to subqueries in JPA module
Browse files Browse the repository at this point in the history
  • Loading branch information
timowest committed Jun 28, 2012
1 parent e51659a commit 684e932
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,7 +82,7 @@ public boolean exists(){
}
}

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);
}

Expand Down Expand Up @@ -109,7 +110,7 @@ protected QueryEngine getQueryEngine(){
}

@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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;
Expand All @@ -44,26 +43,16 @@ public ColQueryMixin(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;
}

@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 {
Context context = new Context();
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package com.mysema.query.support;

import java.util.Collection;
import java.util.UUID;

import com.mysema.commons.lang.Assert;
Expand Down Expand Up @@ -94,7 +95,7 @@ public <RT> Expression<RT> convert(Expression<RT> expr){
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());
Expand All @@ -105,7 +106,7 @@ public <RT> Expression<RT> convert(Expression<RT> expr){
}
}

public Expression<?>[] convert(Expression<?>[] exprs){
public final Expression<?>[] convert(Expression<?>[] exprs){
for (int i = 0; i < exprs.length; i++) {
exprs[i] = convert(exprs[i]);
}
Expand All @@ -118,7 +119,7 @@ protected <D> Expression<D> createAlias(Expression<D> path, Path<D> alias){
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);
}
Expand Down Expand Up @@ -162,12 +163,12 @@ public <P> T fullJoin(EntityPath<P> target, EntityPath<P> alias) {
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;
}
Expand Down Expand Up @@ -216,12 +217,12 @@ public <P> T innerJoin(EntityPath<P> target, EntityPath<P> alias) {
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;
}
Expand Down Expand Up @@ -260,12 +261,12 @@ public <P> T join(EntityPath<P> target, EntityPath<P> alias) {
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();
}
Expand Down Expand Up @@ -296,12 +297,12 @@ public <P> T leftJoin(EntityPath<P> target, EntityPath<P> alias) {
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();
}
Expand Down Expand Up @@ -359,12 +360,12 @@ public <P> T rightJoin(EntityPath<P> target, EntityPath<P> alias) {
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();
}
Expand Down Expand Up @@ -407,7 +408,16 @@ public T where(Predicate... o) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +45,7 @@ public Q from(EntityPath<?>... args) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,9 @@ public JDOQLQueryMixin(QueryMetadata metadata) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,11 +66,11 @@ public Q from(EntityPath<?>... o) {
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);
}

Expand All @@ -89,11 +90,11 @@ public <P> Q fullJoin(MapExpression<?,P> target, Path<P> alias) {
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);
}

Expand All @@ -113,11 +114,11 @@ public <P> Q innerJoin(MapExpression<?,P> target, Path<P> alias) {
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);
}

Expand All @@ -137,11 +138,11 @@ public <P> Q join(MapExpression<?,P> target, Path<P> alias) {
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);
}

Expand All @@ -161,11 +162,11 @@ public <P> Q leftJoin(MapExpression<?,P> target, Path<P> alias) {
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);
}

Expand Down
Loading

0 comments on commit 684e932

Please sign in to comment.