mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
reduced query where to single ExprBoolean for simplification of serialization
This commit is contained in:
parent
c90f5debb5
commit
57bb28a117
@ -5,6 +5,8 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mysema.query.grammar.Grammar;
|
||||
import com.mysema.query.grammar.Types.ExprBoolean;
|
||||
|
||||
@ -22,14 +24,18 @@ public class CascadingBoolean {
|
||||
else expr = expr.and(right);
|
||||
return this;
|
||||
}
|
||||
public void clear(){
|
||||
expr = null;
|
||||
}
|
||||
public CascadingBoolean not(ExprBoolean right){
|
||||
return and(Grammar.not(right));
|
||||
}
|
||||
|
||||
public CascadingBoolean or(ExprBoolean right) {
|
||||
if (expr == null) expr = right;
|
||||
else expr = expr.or(right);
|
||||
return this;
|
||||
}
|
||||
public CascadingBoolean not(ExprBoolean right){
|
||||
return and(Grammar.not(right));
|
||||
}
|
||||
|
||||
public ExprBoolean self(){
|
||||
return expr;
|
||||
|
||||
@ -5,11 +5,11 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import com.mysema.query.grammar.Types.Expr;
|
||||
import com.mysema.query.grammar.Types.ExprBoolean;
|
||||
import com.mysema.query.grammar.Types.ExprEntity;
|
||||
|
||||
public class JoinExpression {
|
||||
private Expr<Boolean>[] conditions;
|
||||
private ExprBoolean condition;
|
||||
private final ExprEntity<?> target;
|
||||
private final JoinType type;
|
||||
|
||||
@ -18,12 +18,12 @@ public class JoinExpression {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Expr<Boolean>[] getConditions() {
|
||||
return conditions;
|
||||
public ExprBoolean getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setConditions(Expr<Boolean>[] conditions) {
|
||||
this.conditions = conditions;
|
||||
public void setCondition(ExprBoolean condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public ExprEntity<?> getTarget() {
|
||||
|
||||
@ -28,7 +28,7 @@ public class QueryBase<A extends QueryBase<A>> implements Query<A> {
|
||||
protected final List<JoinExpression> joins = new ArrayList<JoinExpression>();
|
||||
protected final List<OrderSpecifier<?>> orderBy = new ArrayList<OrderSpecifier<?>>();
|
||||
protected final List<Expr<?>> select = new ArrayList<Expr<?>>();
|
||||
protected final List<ExprBoolean> where = new ArrayList<ExprBoolean>();
|
||||
protected final CascadingBoolean where = new CascadingBoolean();
|
||||
protected void clear(){
|
||||
joins.clear();
|
||||
groupBy.clear();
|
||||
@ -88,13 +88,17 @@ public class QueryBase<A extends QueryBase<A>> implements Query<A> {
|
||||
}
|
||||
|
||||
public A where(ExprBoolean... o) {
|
||||
where.addAll(Arrays.asList(o));
|
||||
for (ExprBoolean expr : o){
|
||||
where.and(expr);
|
||||
}
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A with(ExprBoolean... o) {
|
||||
if (!joins.isEmpty()){
|
||||
joins.get(joins.size()-1).setConditions(o);
|
||||
CascadingBoolean cb = new CascadingBoolean();
|
||||
for (ExprBoolean expr : o) cb.and(expr);
|
||||
joins.get(joins.size()-1).setCondition(cb.self());
|
||||
}
|
||||
return (A) this;
|
||||
}
|
||||
@ -119,8 +123,8 @@ public class QueryBase<A extends QueryBase<A>> implements Query<A> {
|
||||
public List<Expr<?>> getSelect() {
|
||||
return select;
|
||||
}
|
||||
public List<ExprBoolean> getWhere() {
|
||||
return where;
|
||||
public ExprBoolean getWhere() {
|
||||
return where.self();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user