mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-21 21:14:12 +08:00
simplified type system
This commit is contained in:
parent
5fff8bc50f
commit
ee66fd80f8
@ -1,4 +1,4 @@
|
||||
#Sat Feb 23 01:22:49 EET 2008
|
||||
#Fri Feb 29 23:10:45 EET 2008
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -20,7 +20,7 @@
|
||||
<groupId>com.mysema.commons</groupId>
|
||||
<artifactId>mysema-core</artifactId>
|
||||
<version>0.3.3</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
7
readme.txt
Normal file
7
readme.txt
Normal file
@ -0,0 +1,7 @@
|
||||
* more testing
|
||||
|
||||
* possibly Elmo evaluation
|
||||
|
||||
* Query DSL is promoted on website
|
||||
+ open Maven repo
|
||||
+
|
||||
@ -18,23 +18,17 @@ import com.mysema.query.grammar.Types.*;
|
||||
*/
|
||||
public class Grammar {
|
||||
|
||||
static <L, R> ExprBoolean _binOp(Op<Boolean> operator, Expr<L> left,
|
||||
Expr<R> right) {
|
||||
// TODO : should be cached if both arguments are paths
|
||||
OperationBinaryBoolean<L, R> op = new OperationBinaryBoolean<L, R>();
|
||||
static ExprBoolean _op(Op<Boolean> operator, Expr<?>... args) {
|
||||
OperationBoolean op = new OperationBoolean();
|
||||
op.operator = operator;
|
||||
op.left = left;
|
||||
op.right = right;
|
||||
op.args = args;
|
||||
return op;
|
||||
}
|
||||
|
||||
static <OP, RT extends OP, L, R> Operation<RT> _binOp(Op<OP> operator,
|
||||
Expr<L> left, Expr<R> right) {
|
||||
// TODO : should be cached if both arguments are paths
|
||||
OperationBinary<OP, RT, L, R> op = new OperationBinary<OP, RT, L, R>();
|
||||
static <OP, RT extends OP> Operation<OP,RT> _op(Op<OP> operator, Expr<?>... args) {
|
||||
Operation<OP, RT> op = new Operation<OP, RT>();
|
||||
op.operator = operator;
|
||||
op.left = left;
|
||||
op.right = right;
|
||||
op.args = args;
|
||||
return op;
|
||||
}
|
||||
|
||||
@ -63,53 +57,12 @@ public class Grammar {
|
||||
return os;
|
||||
}
|
||||
|
||||
static <F, S, T> ExprBoolean _terOp(Op<Boolean> type, Expr<F> fst,
|
||||
Expr<S> snd, Expr<T> trd) {
|
||||
OperationTertiaryBoolean<F, S, T> op = new OperationTertiaryBoolean<F, S, T>();
|
||||
op.operator = type;
|
||||
op.first = fst;
|
||||
op.second = snd;
|
||||
op.third = trd;
|
||||
return op;
|
||||
}
|
||||
|
||||
static <OP, RT extends OP, F, S, T> Operation<RT> _terOp(Op<OP> type,
|
||||
Expr<F> fst, Expr<S> snd, Expr<T> trd) {
|
||||
OperationTertiary<OP, RT, F, S, T> op = new OperationTertiary<OP, RT, F, S, T>();
|
||||
op.operator = type;
|
||||
op.first = fst;
|
||||
op.second = snd;
|
||||
op.third = trd;
|
||||
return op;
|
||||
}
|
||||
|
||||
static <A> ExprBoolean _unOp(Op<Boolean> type, Expr<A> left) {
|
||||
// TODO : unop call results should be cached
|
||||
OperationUnaryBoolean<A> op = new OperationUnaryBoolean<A>();
|
||||
op.operator = type;
|
||||
op.left = left;
|
||||
return op;
|
||||
}
|
||||
|
||||
static <OP, RT extends OP, A> Operation<RT> _unOp(Op<OP> type, Expr<A> left) {
|
||||
OperationUnary<OP, RT, A> op = new OperationUnary<OP, RT, A>();
|
||||
op.operator = type;
|
||||
op.left = left;
|
||||
return op;
|
||||
}
|
||||
|
||||
static <OP, RT extends OP> Operation<RT> _unOp(Op<OP> type) {
|
||||
OperationNoArg<OP, RT> op = new OperationNoArg<OP, RT>();
|
||||
op.operator = type;
|
||||
return op;
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> add(Expr<A> left, A right) {
|
||||
return _binOp(OpNumber.ADD, left, _const(right));
|
||||
return _op(OpNumber.ADD, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> add(Expr<A> left, Expr<A> right) {
|
||||
return _binOp(OpNumber.ADD, left, right);
|
||||
return _op(OpNumber.ADD, left, right);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean after(Expr<A> left,
|
||||
@ -117,7 +70,7 @@ public class Grammar {
|
||||
// NOTE : signature is for Comparables to support other than Java's date
|
||||
// types
|
||||
// NOTE : basically same as gt
|
||||
return _binOp(OpDate.AFTER, left, _const(right));
|
||||
return _op(OpDate.AFTER, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean after(Expr<A> left,
|
||||
@ -125,11 +78,11 @@ public class Grammar {
|
||||
// NOTE : signature is for Comparables to support other than Java's date
|
||||
// types
|
||||
// NOTE : basically same as gt
|
||||
return _binOp(OpDate.AFTER, left, right);
|
||||
return _op(OpDate.AFTER, left, right);
|
||||
}
|
||||
|
||||
public static ExprBoolean and(ExprBoolean left, ExprBoolean right) {
|
||||
return _binOp(OpBoolean.AND, left, right);
|
||||
static ExprBoolean and(ExprBoolean left, ExprBoolean right) {
|
||||
return _op(OpBoolean.AND, left, right);
|
||||
}
|
||||
|
||||
public static <D> AliasNoEntity<D> as(ExprNoEntity<D> from, String to) {
|
||||
@ -151,32 +104,30 @@ public class Grammar {
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean before(Expr<A> left,
|
||||
A right) {
|
||||
// NOTE : signature is for Comparables to support other than Java's date
|
||||
// types
|
||||
// NOTE : signature is for Comparables to support other than Java's date types
|
||||
// NOTE : basically same as lt
|
||||
return _binOp(OpDate.BEFORE, left, _const(right));
|
||||
return _op(OpDate.BEFORE, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean before(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
// NOTE : signature is for Comparables to support other than Java's date
|
||||
// types
|
||||
// NOTE : signature is for Comparables to support other than Java's date types
|
||||
// NOTE : basically same as lt
|
||||
return _binOp(OpDate.BEFORE, left, right);
|
||||
return _op(OpDate.BEFORE, left, right);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean between(Expr<A> left,
|
||||
A start, A end) {
|
||||
return _terOp(OpComparable.BETWEEN, left, _const(start), _const(end));
|
||||
return _op(OpComparable.BETWEEN, left, _const(start), _const(end));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean between(Expr<A> left,
|
||||
Expr<A> start, Expr<A> end) {
|
||||
return _terOp(OpComparable.BETWEEN, left, start, end);
|
||||
return _op(OpComparable.BETWEEN, left, start, end);
|
||||
}
|
||||
|
||||
public static ExprNoEntity<String> concat(Expr<String> left, Expr<String> right) {
|
||||
return _binOp(OpString.CONCAT, left, right);
|
||||
return _op(OpString.CONCAT, left, right);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> OrderSpecifier<A> desc(
|
||||
@ -185,134 +136,133 @@ public class Grammar {
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> div(Expr<A> left, A right) {
|
||||
return _binOp(OpNumber.DIV, left, _const(right));
|
||||
return _op(OpNumber.DIV, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> div(Expr<A> left, Expr<A> right) {
|
||||
return _binOp(OpNumber.DIV, left, right);
|
||||
return _op(OpNumber.DIV, left, right);
|
||||
}
|
||||
|
||||
public static <A, B extends A> ExprBoolean eq(Expr<A> left, B right) {
|
||||
return _binOp(Op.EQ, left, _const(right));
|
||||
return _op(Op.EQ, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A, B extends A> ExprBoolean eq(Expr<A> left, Expr<B> right) {
|
||||
return _binOp(Op.EQ, left, right);
|
||||
return _op(Op.EQ, left, right);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean goe(Expr<A> left,
|
||||
A right) {
|
||||
return _binOp(OpComparable.GOE, left, _const(right));
|
||||
return _op(OpComparable.GOE, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean goe(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
return _binOp(OpComparable.GOE, left, right);
|
||||
return _op(OpComparable.GOE, left, right);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean gt(Expr<A> left, A right) {
|
||||
return _binOp(OpComparable.GT, left, _const(right));
|
||||
return _op(OpComparable.GT, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean gt(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
return _binOp(OpComparable.GT, left, right);
|
||||
return _op(OpComparable.GT, left, right);
|
||||
}
|
||||
|
||||
public static <A> ExprBoolean in(A left, ExprEntity<Collection<A>> right){
|
||||
return _binOp(Op.INELEMENTS, _const(left), right);
|
||||
return _op(Op.INELEMENTS, _const(left), right);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean in(Expr<A> left,
|
||||
A... rest) {
|
||||
return _binOp(Op.INARRAY, left, _const(rest));
|
||||
return _op(Op.INARRAY, left, _const(rest));
|
||||
}
|
||||
|
||||
public static <A> ExprBoolean in(ExprEntity<A> left, ExprEntity<Collection<A>> right){
|
||||
return _binOp(Op.INELEMENTS, left, right);
|
||||
return _op(Op.INELEMENTS, left, right);
|
||||
}
|
||||
|
||||
public static <A> ExprBoolean isnotnull(Expr<A> left) {
|
||||
return _unOp(Op.ISNOTNULL, left);
|
||||
return _op(Op.ISNOTNULL, left);
|
||||
}
|
||||
|
||||
public static <A> ExprBoolean isnull(Expr<A> left) {
|
||||
return _unOp(Op.ISNULL, left);
|
||||
return _op(Op.ISNULL, left);
|
||||
}
|
||||
|
||||
public static ExprBoolean like(Expr<String> left, String right) {
|
||||
return _binOp(OpString.LIKE, left, _const(right));
|
||||
return _op(OpString.LIKE, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean loe(Expr<A> left,
|
||||
A right) {
|
||||
return _binOp(OpComparable.LOE, left, _const(right));
|
||||
return _op(OpComparable.LOE, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean loe(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
return _binOp(OpComparable.LOE, left, right);
|
||||
return _op(OpComparable.LOE, left, right);
|
||||
}
|
||||
|
||||
public static ExprNoEntity<String> lower(Expr<String> left) {
|
||||
return _unOp(OpString.LOWER, left);
|
||||
return _op(OpString.LOWER, left);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean lt(Expr<A> left, A right) {
|
||||
return _binOp(OpComparable.LT, left, _const(right));
|
||||
return _op(OpComparable.LT, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprBoolean lt(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
return _binOp(OpComparable.LT, left, right);
|
||||
return _op(OpComparable.LT, left, right);
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> mult(Expr<A> left, A right) {
|
||||
return _binOp(OpNumber.MULT, left, _const(right));
|
||||
return _op(OpNumber.MULT, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> mult(Expr<A> left, Expr<A> right) {
|
||||
return _binOp(OpNumber.MULT, left, right);
|
||||
return _op(OpNumber.MULT, left, right);
|
||||
}
|
||||
|
||||
public static <A, B extends A> ExprBoolean ne(Expr<A> left, B right) {
|
||||
return _binOp(Op.NE, left, _const(right));
|
||||
return _op(Op.NE, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A, B extends A> ExprBoolean ne(Expr<A> left, Expr<B> right) {
|
||||
return _binOp(Op.NE, left, right);
|
||||
return _op(Op.NE, left, right);
|
||||
}
|
||||
|
||||
public static ExprBoolean not(ExprBoolean left) {
|
||||
return _unOp(OpBoolean.NOT, left);
|
||||
return _op(OpBoolean.NOT, left);
|
||||
}
|
||||
|
||||
public static ExprBoolean or(ExprBoolean left, ExprBoolean right) {
|
||||
return _binOp(OpBoolean.OR, left, right);
|
||||
static ExprBoolean or(ExprBoolean left, ExprBoolean right) {
|
||||
return _op(OpBoolean.OR, left, right);
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> sub(Expr<A> left, A right) {
|
||||
return _binOp(OpNumber.SUB, left, _const(right));
|
||||
return _op(OpNumber.SUB, left, _const(right));
|
||||
}
|
||||
|
||||
public static <A extends Number> ExprNoEntity<A> sub(Expr<A> left, Expr<A> right) {
|
||||
return _binOp(OpNumber.SUB, left, right);
|
||||
return _op(OpNumber.SUB, left, right);
|
||||
}
|
||||
|
||||
public static ExprNoEntity<String> substr(Expr<String> left, int start) {
|
||||
return _binOp(OpString.SUBSTR, left, _const(start));
|
||||
return _op(OpString.SUBSTR, left, _const(start));
|
||||
}
|
||||
|
||||
public static ExprNoEntity<String> substr(Expr<String> left, int start, int offset) {
|
||||
return _terOp(OpString.SUBSTR, left, _const(start), _const(offset));
|
||||
return _op(OpString.SUBSTR, left, _const(start), _const(offset));
|
||||
}
|
||||
|
||||
public static <A, B extends A> ExprBoolean typeOf(Expr<A> left,
|
||||
Class<B> right) {
|
||||
return _binOp(Op.ISTYPEOF, left, _const(right));
|
||||
public static <A, B extends A> ExprBoolean typeOf(Expr<A> left, Class<B> right) {
|
||||
return _op(Op.ISTYPEOF, left, _const(right));
|
||||
}
|
||||
|
||||
public static ExprNoEntity<String> upper(Expr<String> left) {
|
||||
return _unOp(OpString.UPPER, left);
|
||||
return _op(OpString.UPPER, left);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,60 +91,23 @@ public class Types {
|
||||
public <B extends D> ExprBoolean ne(Expr<B> right){return Grammar.ne(this, right);}
|
||||
}
|
||||
|
||||
public abstract static class Operation<RT> extends ExprNoEntityImpl<RT> {
|
||||
public static class Operation<OP,RT extends OP> extends ExprNoEntityImpl<RT>{
|
||||
/**
|
||||
* arguments don't need to be of same type as return type
|
||||
*/
|
||||
public Op<OP> operator;
|
||||
public Expr<?>[] args;
|
||||
public Expr<RT> as(String to) {
|
||||
return Grammar.as(this, to);
|
||||
}
|
||||
}
|
||||
|
||||
public static class OperationBinary<OP,RT extends OP,L,R> extends Operation<RT>{
|
||||
/**
|
||||
* arguments don't need to be of same type as return type
|
||||
*/
|
||||
public Expr<L> left;
|
||||
public Op<OP> operator;
|
||||
public Expr<R> right;
|
||||
}
|
||||
|
||||
public static class OperationBinaryBoolean<L,R> extends OperationBinary<Boolean,Boolean,L,R>
|
||||
public static class OperationBoolean extends Operation<Boolean,Boolean>
|
||||
implements ExprBoolean {
|
||||
public ExprBoolean and(ExprBoolean right) {return Grammar.and(this, right);}
|
||||
public ExprBoolean or(ExprBoolean right) {return Grammar.or(this, right);}
|
||||
}
|
||||
|
||||
public static class OperationNoArg<OP,RT extends OP> extends Operation<RT>{
|
||||
public Op<OP> operator;
|
||||
}
|
||||
|
||||
public static class OperationTertiary<OP,RT extends OP,F,S,T> extends Operation<RT>{
|
||||
/**
|
||||
* 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 static class OperationTertiaryBoolean<F,S,T> extends OperationTertiary<Boolean,Boolean,F,S,T>
|
||||
implements ExprBoolean{
|
||||
public ExprBoolean and(ExprBoolean right) {return Grammar.and(this, right);}
|
||||
public ExprBoolean or(ExprBoolean right) {return Grammar.or(this, right);}
|
||||
}
|
||||
|
||||
public static class OperationUnary<OP,RT extends OP,A> extends Operation<RT>{
|
||||
/**
|
||||
* argument doesn't need to be of same type as return type
|
||||
*/
|
||||
public Expr<A> left;
|
||||
public Op<OP> operator;
|
||||
}
|
||||
|
||||
public static class OperationUnaryBoolean<A> extends OperationUnary<Boolean,Boolean,A>
|
||||
implements ExprBoolean{
|
||||
public ExprBoolean and(ExprBoolean right) {return Grammar.and(this, right);}
|
||||
public ExprBoolean or(ExprBoolean right) {return Grammar.or(this, right);}
|
||||
}
|
||||
|
||||
public enum Order{ ASC,DESC }
|
||||
|
||||
|
||||
@ -68,19 +68,9 @@ public abstract class Visitor<T extends Visitor<T>> {
|
||||
|
||||
protected abstract void visit(ConstantExpr<?> expr);
|
||||
|
||||
protected abstract void visit(OperationBinary<?,?,?,?> expr);
|
||||
protected abstract void visit(Operation<?,?> expr);
|
||||
|
||||
protected abstract void visit(OperationBinaryBoolean<?,?> expr);
|
||||
|
||||
protected abstract void visit(OperationNoArg<?,?> expr);
|
||||
|
||||
protected abstract void visit(OperationTertiary<?,?,?,?,?> expr);
|
||||
|
||||
protected abstract void visit(OperationTertiaryBoolean<?,?,?> expr);
|
||||
|
||||
protected abstract void visit(OperationUnary<?,?,?> expr);
|
||||
|
||||
protected abstract void visit(OperationUnaryBoolean<?> expr);
|
||||
protected abstract void visit(OperationBoolean expr);
|
||||
|
||||
protected abstract void visit(Path<?> expr);
|
||||
|
||||
|
||||
@ -16,11 +16,6 @@ import com.mysema.query.grammar.Types.*;
|
||||
*/
|
||||
public abstract class VisitorAdapter<V extends VisitorAdapter<V>> extends Visitor<V>{
|
||||
|
||||
@Override
|
||||
protected void visit(AliasNoEntity<?> expr) {
|
||||
visit((Alias<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(AliasCollection<?> expr){
|
||||
visit((Alias<?>)expr);
|
||||
@ -32,8 +27,13 @@ public abstract class VisitorAdapter<V extends VisitorAdapter<V>> extends Visito
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(OperationBinaryBoolean<?,?> expr) {
|
||||
visit((OperationBinary<?,?,?,?>)expr);
|
||||
protected void visit(AliasNoEntity<?> expr) {
|
||||
visit((Alias<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(OperationBoolean expr) {
|
||||
visit((Operation<Boolean,Boolean>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,13 +42,13 @@ public abstract class VisitorAdapter<V extends VisitorAdapter<V>> extends Visito
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(PathEntityCollection<?> expr){
|
||||
visit((Path<?>)expr);
|
||||
protected void visit(PathEntity<?> expr) {
|
||||
visit((Path<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(PathEntity<?> expr) {
|
||||
visit((Path<?>)expr);
|
||||
protected void visit(PathEntityCollection<?> expr){
|
||||
visit((Path<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,14 +56,4 @@ public abstract class VisitorAdapter<V extends VisitorAdapter<V>> extends Visito
|
||||
visit((Path<?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(OperationTertiaryBoolean<?,?,?> expr) {
|
||||
visit((OperationTertiary<?,?,?,?,?>)expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(OperationUnaryBoolean<?> expr) {
|
||||
visit((OperationUnary<?,?,?>)expr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user