mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
This commit is contained in:
parent
f732d4adce
commit
29e33b3750
@ -21,8 +21,7 @@ public interface Query<A extends Query<A>>{
|
||||
A join(EEntity<?> o);
|
||||
A fullJoin(EEntity<?> o);
|
||||
A leftJoin(EEntity<?> o);
|
||||
A with(Expr.EBoolean o);
|
||||
A where(Expr.EBoolean... o);
|
||||
A on(Expr.EBoolean o);
|
||||
A groupBy(Expr<?>... o);
|
||||
A having(Expr.EBoolean... o);
|
||||
A orderBy(OrderSpecifier<?>... o);
|
||||
|
||||
@ -11,6 +11,7 @@ import java.util.List;
|
||||
|
||||
import com.mysema.query.grammar.OrderSpecifier;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Expr.EBoolean;
|
||||
import com.mysema.query.grammar.types.Expr.EEntity;
|
||||
|
||||
/**
|
||||
@ -42,7 +43,7 @@ public class QueryBase<JoinMeta,A extends QueryBase<JoinMeta,A>> implements Quer
|
||||
|
||||
private final Metadata metadata = new Metadata();
|
||||
|
||||
public A from(Expr.EEntity<?>... o) {
|
||||
public A from(EEntity<?>... o) {
|
||||
for (EEntity<?> expr : o){
|
||||
joins.add(new JoinExpression<JoinMeta>(JoinType.DEFAULT,expr));
|
||||
}
|
||||
@ -51,56 +52,56 @@ public class QueryBase<JoinMeta,A extends QueryBase<JoinMeta,A>> implements Quer
|
||||
|
||||
public A groupBy(Expr<?>... o) {
|
||||
groupBy.addAll(Arrays.asList(o));
|
||||
return (A) this;
|
||||
return self;
|
||||
}
|
||||
|
||||
public A having(Expr.EBoolean... o) {
|
||||
for (Expr.EBoolean b : o) having.and(b);
|
||||
return (A) this;
|
||||
public A having(EBoolean... o) {
|
||||
for (EBoolean b : o) having.and(b);
|
||||
return self;
|
||||
}
|
||||
|
||||
public A innerJoin(EEntity<?> o) {
|
||||
joins.add(new JoinExpression<JoinMeta>(JoinType.INNERJOIN,o));
|
||||
return (A) this;
|
||||
return self;
|
||||
}
|
||||
|
||||
public A fullJoin(EEntity<?> o) {
|
||||
joins.add(new JoinExpression<JoinMeta>(JoinType.FULLJOIN,o));
|
||||
return (A) this;
|
||||
return self;
|
||||
}
|
||||
|
||||
public A join(EEntity<?> o) {
|
||||
joins.add(new JoinExpression<JoinMeta>(JoinType.JOIN,o));
|
||||
return (A) this;
|
||||
return self;
|
||||
}
|
||||
|
||||
public A leftJoin(EEntity<?> o) {
|
||||
joins.add(new JoinExpression<JoinMeta>(JoinType.LEFTJOIN,o));
|
||||
return (A) this;
|
||||
return self;
|
||||
}
|
||||
|
||||
public A on(EBoolean o) {
|
||||
if (!joins.isEmpty()){
|
||||
joins.get(joins.size()-1).setCondition(o);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
public A orderBy(OrderSpecifier<?>... o) {
|
||||
orderBy.addAll(Arrays.asList(o));
|
||||
return (A) this;
|
||||
return self;
|
||||
}
|
||||
|
||||
protected A select(Expr<?>... o) {
|
||||
select.addAll(Arrays.asList(o));
|
||||
return (A) this;
|
||||
return self;
|
||||
}
|
||||
|
||||
public A where(Expr.EBoolean... o) {
|
||||
for (Expr.EBoolean b : o) where.and(b);
|
||||
return (A) this;
|
||||
public A where(EBoolean... o) {
|
||||
for (EBoolean b : o) where.and(b);
|
||||
return self;
|
||||
}
|
||||
|
||||
public A with(Expr.EBoolean o) {
|
||||
if (!joins.isEmpty()){
|
||||
joins.get(joins.size()-1).setCondition(o);
|
||||
}
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
|
||||
public Metadata getMetadata(){
|
||||
return metadata;
|
||||
}
|
||||
@ -112,7 +113,7 @@ public class QueryBase<JoinMeta,A extends QueryBase<JoinMeta,A>> implements Quer
|
||||
public List<Expr<?>> getGroupBy() {
|
||||
return groupBy;
|
||||
}
|
||||
public Expr.EBoolean getHaving() {
|
||||
public EBoolean getHaving() {
|
||||
return having.self();
|
||||
}
|
||||
public List<JoinExpression<JoinMeta>> getJoins() {
|
||||
@ -124,7 +125,7 @@ public class QueryBase<JoinMeta,A extends QueryBase<JoinMeta,A>> implements Quer
|
||||
public List<Expr<?>> getSelect() {
|
||||
return select;
|
||||
}
|
||||
public Expr.EBoolean getWhere() {
|
||||
public EBoolean getWhere() {
|
||||
return where.self();
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public class Projection extends Path.PEntity<Object>{
|
||||
ParameterizedType type = (ParameterizedType) field.getGenericType();
|
||||
Class<?> exprType = (Class<?>) type.getActualTypeArguments()[0];
|
||||
Expr<?> fieldVal;
|
||||
if (Boolean.class.isAssignableFrom(exprType)){
|
||||
if (Boolean.class.isAssignableFrom(exprType)){
|
||||
fieldVal = _boolean(field.getName());
|
||||
}else if (Number.class.isAssignableFrom(exprType)){
|
||||
fieldVal = (Expr<?>) _numberMethod.invoke(this, field.getName(), exprType);
|
||||
@ -74,7 +74,11 @@ public class Projection extends Path.PEntity<Object>{
|
||||
}else{
|
||||
fieldVal = _simple(field.getName(), exprType);
|
||||
}
|
||||
field.set(this, fieldVal);
|
||||
if (field.getType().isAssignableFrom(fieldVal.getClass())){
|
||||
field.set(this, fieldVal);
|
||||
}else{
|
||||
// unsupported
|
||||
}
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
|
||||
@ -37,11 +37,11 @@ public class SubQuery<JM,A> extends Expr<A> implements Query<SubQuery<JM,A>>, Co
|
||||
public SubQuery<JM,A> innerJoin(EEntity<?> o) {query.innerJoin(o); return this;}
|
||||
public SubQuery<JM,A> join(EEntity<?> o) {query.join(o); return this;}
|
||||
public SubQuery<JM,A> leftJoin(EEntity<?> o) {query.leftJoin(o); return this;}
|
||||
public SubQuery<JM,A> on(EBoolean o) {query.on(o); return this;}
|
||||
public SubQuery<JM,A> orderBy(OrderSpecifier<?>... o) {query.orderBy(o); return this;}
|
||||
public SubQuery<JM,A> select(Expr<?>... o) {
|
||||
query.s(o); return this;}
|
||||
public SubQuery<JM,A> where(EBoolean... o) {query.where(o); return this;}
|
||||
public SubQuery<JM,A> with(EBoolean o) {query.with(o); return this;}
|
||||
// TODO : add some validation that the given Projection is valid for this subquery
|
||||
public Alias.ASimple<A> as(Projection to) {
|
||||
to.accept(this);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user