mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-24 21:07:26 +08:00
added support for 'inner join fetch' and 'left join fetch'
This commit is contained in:
parent
777084a134
commit
56622abb49
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
<artifactId>querydsl-root</artifactId>
|
||||
<version>0.2.5</version>
|
||||
<version>0.2.6</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
|
||||
@ -7,7 +7,10 @@ package com.mysema.query.grammar;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mysema.query.JoinExpression;
|
||||
import com.mysema.query.JoinType;
|
||||
import com.mysema.query.QueryBase;
|
||||
import com.mysema.query.grammar.types.Expr.Entity;
|
||||
|
||||
/**
|
||||
* HqlQueryBase provides.
|
||||
@ -15,7 +18,7 @@ import com.mysema.query.QueryBase;
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class HqlQueryBase<A extends HqlQueryBase<A>> extends QueryBase<A>{
|
||||
public class HqlQueryBase<A extends HqlQueryBase<A>> extends QueryBase<JoinMeta,A>{
|
||||
|
||||
private List<Object> constants;
|
||||
|
||||
@ -31,6 +34,16 @@ public class HqlQueryBase<A extends HqlQueryBase<A>> extends QueryBase<A>{
|
||||
return serializer.toString();
|
||||
}
|
||||
|
||||
public A innerJoin(JoinMeta meta, Entity<?> o) {
|
||||
joins.add(new JoinExpression<JoinMeta>(JoinType.INNERJOIN, o, meta));
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A leftJoin(JoinMeta meta, Entity<?> o) {
|
||||
joins.add(new JoinExpression<JoinMeta>(JoinType.LEFTJOIN, o, meta));
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public List<Object> getConstants() {
|
||||
return constants;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
return constants;
|
||||
}
|
||||
|
||||
public void serialize(List<Expr<?>> select, List<JoinExpression> joins,
|
||||
public void serialize(List<Expr<?>> select, List<JoinExpression<JoinMeta>> joins,
|
||||
Expr.Boolean where, List<Expr<?>> groupBy, Expr.Boolean having,
|
||||
List<OrderSpecifier<?>> orderBy, boolean forCountRow){
|
||||
if (forCountRow){
|
||||
@ -77,7 +77,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
_append("from ");
|
||||
for (int i=0; i < joins.size(); i++){
|
||||
JoinExpression je = joins.get(i);
|
||||
JoinExpression<JoinMeta> je = joins.get(i);
|
||||
if (i > 0){
|
||||
String sep = ", ";
|
||||
switch(je.getType()){
|
||||
@ -88,6 +88,12 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
_append(sep);
|
||||
}
|
||||
if (je.getMetadata() != null){
|
||||
switch(je.getMetadata()){
|
||||
case FETCH: _append("fetch "); break;
|
||||
}
|
||||
}
|
||||
|
||||
// type specifier
|
||||
if (je.getTarget() instanceof Path.Entity){
|
||||
Path.Entity<?> pe = (Path.Entity<?>)je.getTarget();
|
||||
@ -245,7 +251,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
|
||||
protected void visit(SubQuery<?> query) {
|
||||
QueryBase<?>.Metadata md = query.getQuery().getMetadata();
|
||||
QueryBase<JoinMeta,?>.Metadata md = query.getQuery().getMetadata();
|
||||
_append("(");
|
||||
serialize(md.getSelect(), md.getJoins(),
|
||||
md.getWhere(), md.getGroupBy(), md.getHaving(),
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
/**
|
||||
* JoinMeta provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public enum JoinMeta {
|
||||
FETCH
|
||||
}
|
||||
@ -7,6 +7,7 @@ package com.mysema.query.grammar.types;
|
||||
|
||||
import com.mysema.query.Query;
|
||||
import com.mysema.query.QueryBase;
|
||||
import com.mysema.query.grammar.JoinMeta;
|
||||
import com.mysema.query.grammar.OrderSpecifier;
|
||||
|
||||
/**
|
||||
@ -59,7 +60,7 @@ public class HqlTypes {
|
||||
*/
|
||||
public static class SubQuery<A> extends Expr<A> implements Query<SubQuery<A>>, CollectionType<A>{
|
||||
@SuppressWarnings("unchecked")
|
||||
private QueryBase<?> query = new QueryBase();
|
||||
private QueryBase<JoinMeta,?> query = new QueryBase();
|
||||
public SubQuery(Expr<A> select) {
|
||||
super(null);
|
||||
query.select(select);
|
||||
@ -67,7 +68,7 @@ public class HqlTypes {
|
||||
@SuppressWarnings("unchecked")
|
||||
public SubQuery<A> from(Entity... o) {query.from(o); return this;}
|
||||
public SubQuery<A> fullJoin(Entity<?> o) {query.fullJoin(o); return this;}
|
||||
public QueryBase<?> getQuery(){ return query;}
|
||||
public QueryBase<JoinMeta,?> getQuery(){ return query;}
|
||||
public SubQuery<A> groupBy(Expr<?>... o) {query.groupBy(o); return this;}
|
||||
public SubQuery<A> having(Boolean o) {query.having(o); return this;}
|
||||
public SubQuery<A> innerJoin(Entity<?> o) {query.innerJoin(o); return this;}
|
||||
|
||||
@ -28,6 +28,7 @@ import com.mysema.query.Domain1Dtos;
|
||||
import com.mysema.query.Domain1.Catalog;
|
||||
import com.mysema.query.grammar.HqlGrammar;
|
||||
import com.mysema.query.grammar.HqlQueryBase;
|
||||
import com.mysema.query.grammar.JoinMeta;
|
||||
import com.mysema.query.grammar.hql.HqlDomain.Color;
|
||||
import com.mysema.query.grammar.hql.HqlDomain.DomesticCat;
|
||||
import com.mysema.query.grammar.hql.HqlDomain.Payment;
|
||||
@ -73,7 +74,7 @@ public class HqlParserTest extends HqlQueryBase<HqlParserTest> implements Domain
|
||||
// parse( "from eg.Cat as cat join cat.mate as mate left join cat.kittens as kitten" );
|
||||
from(cat).join(cat.mate.as(mate)).leftJoin(cat.kittens.as(kitten)).parse();
|
||||
// parse( "from eg.Cat as cat\ninner join fetch cat.mate\nleft join fetch cat.kittens" );
|
||||
from(cat).innerJoin(cat.mate).leftJoin(cat.kittens).parse();
|
||||
from(cat).innerJoin(cat.mate).leftJoin(JoinMeta.FETCH, cat.kittens).parse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user