mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-21 21:14:12 +08:00
updated
This commit is contained in:
parent
69db91bc75
commit
38225517b2
41
src/main/java/com/mysema/query/ExtQueryBase.java
Normal file
41
src/main/java/com/mysema/query/ExtQueryBase.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Mysema Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import com.mysema.query.grammar.Types.BooleanExpr;
|
||||
import com.mysema.query.grammar.Types.EntityExpr;
|
||||
|
||||
/**
|
||||
* ExtQueryBased provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ExtQueryBase<A extends ExtQueryBase<A>> extends QueryBase<A> implements ExtQuery<A> {
|
||||
|
||||
public A innerJoin(EntityExpr<?> object) {
|
||||
joins.add(new JoinExpression(JoinType.IJ,object));
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A join(EntityExpr<?> object) {
|
||||
joins.add(new JoinExpression(JoinType.J,object));
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A leftJoin(EntityExpr<?> object) {
|
||||
joins.add(new JoinExpression(JoinType.LJ,object));
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A with(BooleanExpr... objects) {
|
||||
if (!joins.isEmpty()){
|
||||
joins.get(joins.size()-1).conditions = objects;
|
||||
}
|
||||
return (A) this;
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Mysema Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -14,7 +19,7 @@ import com.mysema.query.grammar.Types.OrderSpecifier;
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class QueryBase<A extends QueryBase<A>> implements ExtQuery<A> {
|
||||
public class QueryBase<A extends QueryBase<A>> implements Query<A> {
|
||||
public enum JoinType{
|
||||
DEFAULT,IJ,LJ,J
|
||||
}
|
||||
@ -35,7 +40,6 @@ public class QueryBase<A extends QueryBase<A>> implements ExtQuery<A> {
|
||||
protected OrderSpecifier<?>[] orderBy;
|
||||
protected Expr<?>[] select;
|
||||
protected BooleanExpr[] where;
|
||||
protected BooleanExpr[] with;
|
||||
|
||||
protected void clear(){
|
||||
joins.clear();
|
||||
@ -47,7 +51,9 @@ public class QueryBase<A extends QueryBase<A>> implements ExtQuery<A> {
|
||||
}
|
||||
|
||||
public A from(EntityExpr<?>... objects) {
|
||||
// TODO
|
||||
for (EntityExpr<?> expr : objects){
|
||||
joins.add(new JoinExpression(JoinType.DEFAULT,expr));
|
||||
}
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
@ -61,20 +67,6 @@ public class QueryBase<A extends QueryBase<A>> implements ExtQuery<A> {
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A innerJoin(EntityExpr<?> object) {
|
||||
// innerJoin = objects;
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A join(EntityExpr<?> object) {
|
||||
// join = objects;
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A leftJoin(EntityExpr<?> object) {
|
||||
// leftJoin = objects;
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A orderBy(OrderSpecifier<?>... objects) {
|
||||
orderBy = objects;
|
||||
@ -91,9 +83,4 @@ public class QueryBase<A extends QueryBase<A>> implements ExtQuery<A> {
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public A with(BooleanExpr... objects) {
|
||||
with = objects;
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -121,6 +121,10 @@ public class Grammar {
|
||||
public static <D> EntityExpr<D> as(DomainType<D> from, DomainType<D> to) {
|
||||
return new Alias<D>(from, to);
|
||||
}
|
||||
|
||||
public static <D> EntityExpr<D> as(CollectionReference<D> from, DomainType<D> to) {
|
||||
return new CollectionAlias<D>(from, to);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> OrderSpecifier<A> asc(Expr<A> target) {
|
||||
return _orderAsc(target);
|
||||
|
||||
@ -5,6 +5,9 @@
|
||||
*/
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Types provides the types of the fluent grammar
|
||||
*
|
||||
@ -32,8 +35,8 @@ public class Types {
|
||||
* arguments don't need to be of same type as return type
|
||||
*/
|
||||
public Expr<L> left;
|
||||
public Expr<R> right;
|
||||
public Op<OP> operator;
|
||||
public Expr<R> right;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +50,7 @@ public class Types {
|
||||
public static class BooleanProperty extends Reference<Boolean> implements BooleanExpr{
|
||||
public BooleanProperty(String path) {super(path);}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Boolean operators (operators used with boolean operands)
|
||||
*/
|
||||
@ -58,9 +61,26 @@ public class Types {
|
||||
BoOp<Boolean> XNOR = new BoOpImpl<Boolean>();
|
||||
BoOp<Boolean> XOR = new BoOpImpl<Boolean>();
|
||||
}
|
||||
|
||||
|
||||
static class BoOpImpl<RT> implements BoOp<RT>{}
|
||||
|
||||
public static class CollectionAlias<D> extends Reference<D> implements EntityExpr<D>{
|
||||
public final CollectionReference<D> from;
|
||||
public final Reference<D> to;
|
||||
CollectionAlias(CollectionReference<D> from, Reference<D> to) {
|
||||
super(to.toString());
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CollectionReference<A> extends Reference<Collection<A>> implements
|
||||
EntityExpr<Collection<A>>{
|
||||
public CollectionReference(String p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operators for Comparable objects
|
||||
*/
|
||||
@ -70,10 +90,10 @@ public class Types {
|
||||
CompOp<Boolean> GT = new CompOpImpl<Boolean>();
|
||||
CompOp<Boolean> LOE = new CompOpImpl<Boolean>();
|
||||
CompOp<Boolean> LT = new CompOpImpl<Boolean>();
|
||||
}
|
||||
|
||||
static class CompOpImpl<RT> implements CompOp<RT> {}
|
||||
}
|
||||
|
||||
static class CompOpImpl<RT> implements CompOp<RT> {}
|
||||
|
||||
public static class ConstantExpr<A> implements Expr<A>{
|
||||
public A constant;
|
||||
}
|
||||
@ -96,6 +116,9 @@ public class Types {
|
||||
protected BooleanProperty _boolean(String path){
|
||||
return new BooleanProperty(this+"."+path);
|
||||
}
|
||||
protected <A>CollectionReference<A> _collection(String path,Class<A> type) {
|
||||
return new CollectionReference<A>(this+"."+path);
|
||||
}
|
||||
protected <A> Reference<A> _prop(String path,Class<A> type) {
|
||||
return new Reference<A>(this+"."+path);
|
||||
}
|
||||
@ -126,11 +149,11 @@ public class Types {
|
||||
*/
|
||||
public interface Op<RT> {
|
||||
Op<Boolean> EQ = new OpImpl<Boolean>();
|
||||
Op<Boolean> IN = new OpImpl<Boolean>();
|
||||
Op<Boolean> ISNOTNULL = new OpImpl<Boolean>();
|
||||
Op<Boolean> ISNULL = new OpImpl<Boolean>();
|
||||
Op<Boolean> ISTYPEOF = new OpImpl<Boolean>();
|
||||
Op<Boolean> NE = new OpImpl<Boolean>();
|
||||
Op<Boolean> IN = new OpImpl<Boolean>();
|
||||
Op<Boolean> ISNULL = new OpImpl<Boolean>();
|
||||
Op<Boolean> ISNOTNULL = new OpImpl<Boolean>();
|
||||
}
|
||||
|
||||
public interface Operation<RT> extends Expr<RT> {}
|
||||
@ -177,9 +200,9 @@ public class Types {
|
||||
* arguments don't need to be of same type as return type
|
||||
*/
|
||||
public Expr<F> first;
|
||||
public Op<OP> operator;
|
||||
public Expr<S> second;
|
||||
public Expr<T> third;
|
||||
public Op<OP> operator;
|
||||
public Expr<T> third;
|
||||
}
|
||||
|
||||
public static class UnaryBooleanOperation<A> extends UnaryOperation<Boolean,Boolean,A>
|
||||
|
||||
@ -64,6 +64,10 @@ public abstract class Visitor<T extends Visitor<T>> {
|
||||
|
||||
protected abstract void visit(BooleanProperty expr);
|
||||
|
||||
protected abstract void visit(CollectionAlias<?> expr);
|
||||
|
||||
protected abstract void visit(CollectionReference<?> expr);
|
||||
|
||||
protected abstract void visit(ConstantExpr<?> expr);
|
||||
|
||||
protected abstract void visit(DomainType<?> expr);
|
||||
|
||||
@ -25,6 +25,16 @@ public abstract class VisitorAdapter<V extends VisitorAdapter<V>> extends Visito
|
||||
visit((Reference<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(CollectionAlias<?> expr){
|
||||
visit((Reference<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(CollectionReference<?> expr){
|
||||
visit((Reference<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(DomainType<?> expr) {
|
||||
visit((Reference<?>)expr);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user