mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-16 21:01:10 +08:00
refactored type system
This commit is contained in:
parent
94aac30f3c
commit
c0586de50f
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
<artifactId>querydsl-root</artifactId>
|
||||
<version>0.2.3</version>
|
||||
<version>0.2.4</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
*/
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
import static com.mysema.query.grammar.types.Factory.createBoolean;
|
||||
import static com.mysema.query.grammar.types.Factory.createComparable;
|
||||
import static com.mysema.query.grammar.types.Factory.createNumber;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
@ -15,7 +19,9 @@ import com.mysema.query.grammar.HqlOps.OpHql;
|
||||
import com.mysema.query.grammar.HqlOps.OpNumberAgg;
|
||||
import com.mysema.query.grammar.HqlOps.OpQuant;
|
||||
import com.mysema.query.grammar.Ops.Op;
|
||||
import com.mysema.query.grammar.Types.*;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Path;
|
||||
import com.mysema.query.grammar.types.PathMetadata;
|
||||
|
||||
/**
|
||||
* HqlGrammar extends the Query DSL base grammar to provide HQL specific syntax elements
|
||||
@ -25,169 +31,169 @@ import com.mysema.query.grammar.Types.*;
|
||||
*/
|
||||
public class HqlGrammar extends Grammar{
|
||||
|
||||
public static <D> Expr<D> all(CollectionType<D> col){
|
||||
public static <D> Expr<D> all(Expr.CollectionType<D> col){
|
||||
return new ExprQuantSimple<D>(OpQuant.ALL, col);
|
||||
}
|
||||
public static <D extends Comparable<D>> ExprComparable<D> all(CollectionType<D> col){
|
||||
public static <D extends Comparable<D>> Expr.Comparable<D> all(Expr.CollectionType<D> col){
|
||||
return new ExprQuantComparable<D>(OpQuant.ALL, col);
|
||||
}
|
||||
|
||||
public static <D> Expr<D> any(CollectionType<D> col){
|
||||
public static <D> Expr<D> any(Expr.CollectionType<D> col){
|
||||
return new ExprQuantSimple<D>(OpQuant.ANY, col);
|
||||
}
|
||||
public static <D extends Comparable<D>> ExprComparable<D> any(CollectionType<D> col){
|
||||
public static <D extends Comparable<D>> Expr.Comparable<D> any(Expr.CollectionType<D> col){
|
||||
return new ExprQuantComparable<D>(OpQuant.ANY, col);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprComparable<A> avg(Expr<A> left){
|
||||
return _number(OpNumberAgg.AVG, left);
|
||||
public static <A extends Comparable<A>> Expr.Comparable<A> avg(Expr<A> left){
|
||||
return createNumber(OpNumberAgg.AVG, left);
|
||||
}
|
||||
public static <A extends Comparable<A>> ExprComparable<A> avg(PathCollection<A> left){
|
||||
public static <A extends Comparable<A>> Expr.Comparable<A> avg(Path.Collection<A> left){
|
||||
return new ExprQuantComparable<A>(OpQuant.AVG_IN_COL, left);
|
||||
}
|
||||
|
||||
public static ExprComparable<Long> count(){
|
||||
public static Expr.Comparable<Long> count(){
|
||||
return new CountExpr(null);
|
||||
}
|
||||
|
||||
public static ExprComparable<Long> count(Expr<?> expr){
|
||||
public static Expr.Comparable<Long> count(Expr<?> expr){
|
||||
return new CountExpr(expr);
|
||||
}
|
||||
public static ExprComparable<Date> current_date(){
|
||||
return _comparable(OpHql.CURRENT_DATE);
|
||||
public static Expr.Comparable<Date> current_date(){
|
||||
return createComparable(OpHql.CURRENT_DATE);
|
||||
}
|
||||
public static ExprComparable<Date> current_time(){
|
||||
return _comparable(OpHql.CURRENT_TIME);
|
||||
public static Expr.Comparable<Date> current_time(){
|
||||
return createComparable(OpHql.CURRENT_TIME);
|
||||
}
|
||||
public static ExprComparable<Date> current_timestamp(){
|
||||
return _comparable(OpHql.CURRENT_TIMESTAMP);
|
||||
public static Expr.Comparable<Date> current_timestamp(){
|
||||
return createComparable(OpHql.CURRENT_TIMESTAMP);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> day(Expr<Date> date){
|
||||
return _comparable(OpHql.DAY, date);
|
||||
public static Expr.Comparable<Date> day(Expr<Date> date){
|
||||
return createComparable(OpHql.DAY, date);
|
||||
}
|
||||
public static <T> Expr<T> distinct(PathEntity<T> left){
|
||||
public static <T> Expr<T> distinct(Path.Entity<T> left){
|
||||
return new DistinctPath<T>(left);
|
||||
}
|
||||
|
||||
public static <T> Expr<T> distinct(PathNoEntity<T> left){
|
||||
public static <T> Expr<T> distinct(Path.NoEntity<T> left){
|
||||
return new DistinctPath<T>(left);
|
||||
}
|
||||
|
||||
public static <D> ExprBoolean exists(CollectionType<D> col){
|
||||
public static <D> Expr.Boolean exists(Expr.CollectionType<D> col){
|
||||
return new ExprQuantBoolean<D>(OpQuant.EXISTS, col);
|
||||
}
|
||||
|
||||
public static <A> SubQuery<A> from(ExprEntity<A> select){
|
||||
public static <A> SubQuery<A> from(Expr.Entity<A> select){
|
||||
return new SubQuery<A>(select).from(select);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> hour(Expr<Date> date){
|
||||
return _comparable(OpHql.HOUR, date);
|
||||
public static Expr.Comparable<Date> hour(Expr<Date> date){
|
||||
return createComparable(OpHql.HOUR, date);
|
||||
}
|
||||
|
||||
public static PathComponentCollection<Integer> indices(PathCollection<?> col){
|
||||
return new PathComponentCollection<Integer>(Integer.class, new PathMetadata<Collection<Integer>>(col, null, HqlPathType.LISTINDICES));
|
||||
public static Path.ComponentCollection<Integer> indices(Path.Collection<?> col){
|
||||
return new Path.ComponentCollection<Integer>(Integer.class, new PathMetadata<Collection<Integer>>(col, null, HqlPathType.LISTINDICES));
|
||||
}
|
||||
|
||||
public static <K,V> PathComponentCollection<K> indices(PathMap<K,V> col){
|
||||
return new PathComponentCollection<K>(col.getKeyType(), new PathMetadata<Collection<Integer>>(col, null, HqlPathType.LISTINDICES));
|
||||
public static <K,V> Path.ComponentCollection<K> indices(Path.Map<K,V> col){
|
||||
return new Path.ComponentCollection<K>(col.getKeyType(), new PathMetadata<Collection<Integer>>(col, null, HqlPathType.LISTINDICES));
|
||||
}
|
||||
|
||||
public static ExprBoolean isempty(PathComponentCollection<?> collection) {
|
||||
return _boolean(OpHql.ISEMPTY, collection);
|
||||
public static Expr.Boolean isempty(Path.ComponentCollection<?> collection) {
|
||||
return createBoolean(OpHql.ISEMPTY, collection);
|
||||
}
|
||||
|
||||
public static ExprBoolean isempty(PathEntityCollection<?> collection) {
|
||||
return _boolean(OpHql.ISEMPTY, collection);
|
||||
public static Expr.Boolean isempty(Path.EntityCollection<?> collection) {
|
||||
return createBoolean(OpHql.ISEMPTY, collection);
|
||||
}
|
||||
|
||||
public static ExprBoolean isnotempty(PathComponentCollection<?> collection) {
|
||||
return _boolean(OpHql.ISNOTEMPTY, collection);
|
||||
public static Expr.Boolean isnotempty(Path.ComponentCollection<?> collection) {
|
||||
return createBoolean(OpHql.ISNOTEMPTY, collection);
|
||||
}
|
||||
|
||||
public static ExprBoolean isnotempty(PathEntityCollection<?> collection) {
|
||||
return _boolean(OpHql.ISNOTEMPTY, collection);
|
||||
public static Expr.Boolean isnotempty(Path.EntityCollection<?> collection) {
|
||||
return createBoolean(OpHql.ISNOTEMPTY, collection);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprComparable<A> max(Expr<A> left){
|
||||
return _number(OpNumberAgg.MAX, left);
|
||||
public static <A extends Comparable<A>> Expr.Comparable<A> max(Expr<A> left){
|
||||
return createNumber(OpNumberAgg.MAX, left);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprComparable<A> max(PathCollection<A> left){
|
||||
public static <A extends Comparable<A>> Expr.Comparable<A> max(Path.Collection<A> left){
|
||||
return new ExprQuantComparable<A>(OpQuant.MAX_IN_COL, left);
|
||||
}
|
||||
|
||||
public static <A> PathEntity<A> maxelement(PathEntityCollection<A> col) {
|
||||
return new PathEntity<A>(col.getElementType(), new PathMetadata<A>(col, null, HqlPathType.MINELEMENT));
|
||||
public static <A> Path.Entity<A> maxelement(Path.EntityCollection<A> col) {
|
||||
return new Path.Entity<A>(col.getElementType(), new PathMetadata<A>(col, null, HqlPathType.MINELEMENT));
|
||||
}
|
||||
|
||||
public static <A> PathComparable<Integer> maxindex(PathComponentCollection<A> col) {
|
||||
return new PathComparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MAXINDEX));
|
||||
public static <A> Path.Comparable<Integer> maxindex(Path.ComponentCollection<A> col) {
|
||||
return new Path.Comparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MAXINDEX));
|
||||
}
|
||||
|
||||
public static <A> PathComparable<Integer> maxindex(PathEntityCollection<A> col) {
|
||||
return new PathComparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MAXINDEX));
|
||||
public static <A> Path.Comparable<Integer> maxindex(Path.EntityCollection<A> col) {
|
||||
return new Path.Comparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MAXINDEX));
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprComparable<A> min(Expr<A> left){
|
||||
return _number(OpNumberAgg.MIN, left);
|
||||
public static <A extends Comparable<A>> Expr.Comparable<A> min(Expr<A> left){
|
||||
return createNumber(OpNumberAgg.MIN, left);
|
||||
}
|
||||
|
||||
public static <A extends Comparable<A>> ExprComparable<A> min(PathCollection<A> left){
|
||||
public static <A extends Comparable<A>> Expr.Comparable<A> min(Path.Collection<A> left){
|
||||
return new ExprQuantComparable<A>(OpQuant.MIN_IN_COL, left);
|
||||
}
|
||||
|
||||
public static <A> PathEntity<A> minelement(PathEntityCollection<A> col) {
|
||||
return new PathEntity<A>(col.getElementType(), new PathMetadata<A>(col, null, HqlPathType.MINELEMENT));
|
||||
public static <A> Path.Entity<A> minelement(Path.EntityCollection<A> col) {
|
||||
return new Path.Entity<A>(col.getElementType(), new PathMetadata<A>(col, null, HqlPathType.MINELEMENT));
|
||||
}
|
||||
|
||||
public static <A> PathComparable<Integer> minindex(PathComponentCollection<A> col) {
|
||||
return new PathComparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MININDEX));
|
||||
public static <A> Path.Comparable<Integer> minindex(Path.ComponentCollection<A> col) {
|
||||
return new Path.Comparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MININDEX));
|
||||
}
|
||||
|
||||
public static <A> PathComparable<Integer> minindex(PathEntityCollection<A> col) {
|
||||
return new PathComparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MININDEX));
|
||||
public static <A> Path.Comparable<Integer> minindex(Path.EntityCollection<A> col) {
|
||||
return new Path.Comparable<Integer>(Integer.class, new PathMetadata<Integer>(col, null, HqlPathType.MININDEX));
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> minute(Expr<Date> date){
|
||||
return _comparable(OpHql.MINUTE, date);
|
||||
public static Expr.Comparable<Date> minute(Expr<Date> date){
|
||||
return createComparable(OpHql.MINUTE, date);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> month(Expr<Date> date){
|
||||
return _comparable(OpHql.MONTH, date);
|
||||
public static Expr.Comparable<Date> month(Expr<Date> date){
|
||||
return createComparable(OpHql.MONTH, date);
|
||||
}
|
||||
|
||||
public static <A> Expr<A> newInstance(Class<A> a, Expr<?>... args){
|
||||
return new Constructor<A>(a,args);
|
||||
}
|
||||
|
||||
public static <D> ExprBoolean notExists(CollectionType<D> col){
|
||||
public static <D> Expr.Boolean notExists(Expr.CollectionType<D> col){
|
||||
return new ExprQuantBoolean<D>(OpQuant.NOTEXISTS, col);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> second(Expr<Date> date){
|
||||
return _comparable(OpHql.SECOND, date);
|
||||
public static Expr.Comparable<Date> second(Expr<Date> date){
|
||||
return createComparable(OpHql.SECOND, date);
|
||||
}
|
||||
|
||||
public static <A> SubQuery<A> select(Expr<A> select){
|
||||
return new SubQuery<A>(select);
|
||||
}
|
||||
|
||||
public static <D> Expr<D> some(CollectionType<D> col){
|
||||
public static <D> Expr<D> some(Expr.CollectionType<D> col){
|
||||
return any(col);
|
||||
}
|
||||
|
||||
public static <D extends Comparable<D>> ExprComparable<D> sum(Expr<D> left){
|
||||
return _number(OpHql.SUM, left);
|
||||
public static <D extends Comparable<D>> Expr.Comparable<D> sum(Expr<D> left){
|
||||
return createNumber(OpHql.SUM, left);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> sysdate(){
|
||||
return _comparable(OpHql.SYSDATE);
|
||||
public static Expr.Comparable<Date> sysdate(){
|
||||
return createComparable(OpHql.SYSDATE);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> year(Expr<Date> date){
|
||||
return _comparable(OpHql.YEAR, date);
|
||||
public static Expr.Comparable<Date> year(Expr<Date> date){
|
||||
return createComparable(OpHql.YEAR, date);
|
||||
}
|
||||
|
||||
public static class Constructor<D> extends Expr<D>{
|
||||
@ -199,7 +205,7 @@ public class HqlGrammar extends Grammar{
|
||||
public Expr<?>[] getArgs(){ return args; }
|
||||
}
|
||||
|
||||
public static class CountExpr extends ExprComparable<Long>{
|
||||
public static class CountExpr extends Expr.Comparable<Long>{
|
||||
private final Expr<?> target;
|
||||
CountExpr(Expr<?> expr) {
|
||||
super(Long.class);
|
||||
@ -223,10 +229,10 @@ public class HqlGrammar extends Grammar{
|
||||
Expr<?> getTarget();
|
||||
}
|
||||
|
||||
public static class ExprQuantBoolean<Q> extends ExprBoolean implements ExprQuant{
|
||||
public static class ExprQuantBoolean<Q> extends Expr.Boolean implements ExprQuant{
|
||||
private final Expr<?> col;
|
||||
private final Op<?> op;
|
||||
ExprQuantBoolean(Op<?> op, CollectionType<Q> col) {
|
||||
ExprQuantBoolean(Op<?> op, Expr.CollectionType<Q> col) {
|
||||
this.op = op;
|
||||
this.col = (Expr<?>) col;
|
||||
}
|
||||
@ -234,10 +240,10 @@ public class HqlGrammar extends Grammar{
|
||||
public Expr<?> getTarget() {return col;}
|
||||
}
|
||||
|
||||
public static class ExprQuantComparable<Q extends Comparable<Q>> extends ExprComparable<Q> implements ExprQuant{
|
||||
public static class ExprQuantComparable<Q extends Comparable<Q>> extends Expr.Comparable<Q> implements ExprQuant{
|
||||
private final Expr<?> col;
|
||||
private final Op<?> op;
|
||||
ExprQuantComparable(Op<?> op, CollectionType<Q> col) {
|
||||
ExprQuantComparable(Op<?> op, Expr.CollectionType<Q> col) {
|
||||
super(null);
|
||||
this.op = op;
|
||||
this.col = (Expr<?>)col;
|
||||
@ -258,25 +264,26 @@ public class HqlGrammar extends Grammar{
|
||||
public Expr<?> getTarget() {return col;}
|
||||
}
|
||||
|
||||
public static class SubQuery<A> extends Expr<A> implements Query<SubQuery<A>>,CollectionType<A>{
|
||||
public static class SubQuery<A> extends Expr<A> implements Query<SubQuery<A>>, Expr.CollectionType<A>{
|
||||
@SuppressWarnings("unchecked")
|
||||
private QueryBase<?> query = new QueryBase();
|
||||
SubQuery(Expr<A> select) {
|
||||
super(null);
|
||||
query.select(select);
|
||||
}
|
||||
public SubQuery<A> from(ExprEntity<?>... o) {query.from(o); return this;}
|
||||
public SubQuery<A> fullJoin(ExprEntity<?> o) {query.fullJoin(o); return this;}
|
||||
public SubQuery<A> from(Expr.Entity<?>... o) {query.from(o); return this;}
|
||||
public SubQuery<A> fullJoin(Expr.Entity<?> o) {query.fullJoin(o); return this;}
|
||||
public QueryBase<?> getQuery(){ return query;}
|
||||
public SubQuery<A> groupBy(Expr<?>... o) {query.groupBy(o); return this;}
|
||||
public SubQuery<A> having(ExprBoolean... o) {query.having(o); return this;}
|
||||
public SubQuery<A> innerJoin(ExprEntity<?> o) {query.innerJoin(o); return this;}
|
||||
public SubQuery<A> join(ExprEntity<?> o) {query.join(o); return this;}
|
||||
public SubQuery<A> leftJoin(ExprEntity<?> o) {query.leftJoin(o); return this;}
|
||||
public SubQuery<A> having(Expr.Boolean... o) {query.having(o); return this;}
|
||||
public SubQuery<A> innerJoin(Expr.Entity<?> o) {query.innerJoin(o); return this;}
|
||||
public SubQuery<A> join(Expr.Entity<?> o) {query.join(o); return this;}
|
||||
public SubQuery<A> leftJoin(Expr.Entity<?> o) {query.leftJoin(o); return this;}
|
||||
public SubQuery<A> orderBy(OrderSpecifier<?>... o) {query.orderBy(o); return this;}
|
||||
public SubQuery<A> select(Expr<?>... o) {query.select(o); return this;}
|
||||
public SubQuery<A> where(ExprBoolean... o) {query.where(o); return this;}
|
||||
public SubQuery<A> with(ExprBoolean... o) {query.with(o); return this;}
|
||||
public SubQuery<A> where(Expr.Boolean... o) {query.where(o); return this;}
|
||||
public SubQuery<A> with(Expr.Boolean... o) {query.with(o); return this;}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,10 +5,17 @@
|
||||
*/
|
||||
package com.mysema.query.grammar;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mysema.query.grammar.PathMetadata.PathType;
|
||||
import com.mysema.query.grammar.PathMetadata.PathTypeImpl;
|
||||
import com.mysema.query.grammar.Ops;
|
||||
import com.mysema.query.grammar.Ops.Op;
|
||||
import com.mysema.query.grammar.Ops.OpImpl;
|
||||
import com.mysema.query.grammar.types.PathMetadata.PathType;
|
||||
import com.mysema.query.grammar.types.PathMetadata.PathTypeImpl;
|
||||
|
||||
/**
|
||||
* Ops provides
|
||||
@ -16,7 +23,7 @@ import com.mysema.query.grammar.PathMetadata.PathTypeImpl;
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class HqlOps extends Ops {
|
||||
public class HqlOps {
|
||||
|
||||
public static final Set<Op<?>> wrapCollectionsForOp;
|
||||
|
||||
@ -31,36 +38,36 @@ public class HqlOps extends Ops {
|
||||
wrapCollectionsForOp = Collections.unmodifiableSet(ops);
|
||||
}
|
||||
|
||||
private static final Map<Op<?>,String> patterns = new HashMap<Op<?>,String>();
|
||||
private static final Map<Op<?>,java.lang.String> patterns = new HashMap<Op<?>,java.lang.String>();
|
||||
|
||||
private static final Map<Op<?>,Integer> precedence = new HashMap<Op<?>,Integer>();
|
||||
|
||||
static{
|
||||
// boolean
|
||||
add(OpBoolean.AND, "%s and %s",36);
|
||||
add(OpBoolean.NOT, "not %s",3);
|
||||
add(OpBoolean.OR, "%s or %s",38);
|
||||
add(OpBoolean.XNOR, "%s xnor %s",39);
|
||||
add(OpBoolean.XOR, "%s xor %s",39);
|
||||
add(Ops.AND, "%s and %s",36);
|
||||
add(Ops.NOT, "not %s",3);
|
||||
add(Ops.OR, "%s or %s",38);
|
||||
add(Ops.XNOR, "%s xnor %s",39);
|
||||
add(Ops.XOR, "%s xor %s",39);
|
||||
|
||||
// comparison
|
||||
add(OpComparable.BETWEEN, "%s between %s and %s",30);
|
||||
add(OpComparable.NOTBETWEEN, "%s not between %s and %s",30);
|
||||
add(OpComparable.GOE, "%s >= %s",20);
|
||||
add(OpComparable.GT, "%s > %s",21);
|
||||
add(OpComparable.LOE, "%s <= %s",22);
|
||||
add(OpComparable.LT, "%s < %s",23);
|
||||
add(Ops.BETWEEN, "%s between %s and %s",30);
|
||||
add(Ops.NOTBETWEEN, "%s not between %s and %s",30);
|
||||
add(Ops.GOE, "%s >= %s",20);
|
||||
add(Ops.GT, "%s > %s",21);
|
||||
add(Ops.LOE, "%s <= %s",22);
|
||||
add(Ops.LT, "%s < %s",23);
|
||||
|
||||
add(OpDate.AFTER, "%s > %s",21);
|
||||
add(OpDate.BEFORE, "%s < %s",23);
|
||||
add(Ops.AFTER, "%s > %s",21);
|
||||
add(Ops.BEFORE, "%s < %s",23);
|
||||
|
||||
// numeric
|
||||
add(OpNumber.ADD, "%s + %s",13);
|
||||
add(OpNumber.DIV, "%s / %s",8);
|
||||
add(OpNumber.MOD, "%s % %s",10);
|
||||
add(OpNumber.MULT,"%s * %s",7);
|
||||
add(OpNumber.SUB, "%s - %s",12);
|
||||
add(OpNumber.SQRT, "sqrt(%s)");
|
||||
add(Ops.ADD, "%s + %s",13);
|
||||
add(Ops.DIV, "%s / %s",8);
|
||||
add(Ops.MOD, "%s % %s",10);
|
||||
add(Ops.MULT,"%s * %s",7);
|
||||
add(Ops.SUB, "%s - %s",12);
|
||||
add(Ops.SQRT, "sqrt(%s)");
|
||||
|
||||
// numeric aggregates
|
||||
add(OpNumberAgg.AVG, "avg(%s)");
|
||||
@ -78,13 +85,13 @@ public class HqlOps extends Ops {
|
||||
// add(Op.SIZE, "size(%s)");
|
||||
|
||||
// string
|
||||
add(OpString.CONCAT, "%s || %s",37);
|
||||
add(OpString.LIKE, "%s like %s",27);
|
||||
add(OpString.LOWER, "lower(%s)");
|
||||
add(OpString.SUBSTR1ARG, "substring(%s,%s)");
|
||||
add(OpString.SUBSTR2ARGS, "substring(%s,%s,%s)");
|
||||
add(OpString.TRIM, "trim(%s)");
|
||||
add(OpString.UPPER, "upper(%s)");
|
||||
add(Ops.CONCAT, "%s || %s",37);
|
||||
add(Ops.LIKE, "%s like %s",27);
|
||||
add(Ops.LOWER, "lower(%s)");
|
||||
add(Ops.SUBSTR1ARG, "substring(%s,%s)");
|
||||
add(Ops.SUBSTR2ARGS, "substring(%s,%s,%s)");
|
||||
add(Ops.TRIM, "trim(%s)");
|
||||
add(Ops.UPPER, "upper(%s)");
|
||||
|
||||
// HQL specific
|
||||
add(OpHql.SUM, "sum(%s)");
|
||||
@ -126,16 +133,16 @@ public class HqlOps extends Ops {
|
||||
add(HqlPathType.MAPINDICES, "indices(%s)");
|
||||
}
|
||||
|
||||
private static void add(Op<?> op, String pattern){
|
||||
private static void add(Op<?> op, java.lang.String pattern){
|
||||
patterns.put(op, pattern);
|
||||
}
|
||||
|
||||
private static void add(Op<?> op, String pattern, int pre){
|
||||
private static void add(Op<?> op, java.lang.String pattern, int pre){
|
||||
patterns.put(op, pattern);
|
||||
precedence.put(op,pre);
|
||||
}
|
||||
|
||||
public static String getPattern(Op<?> op){
|
||||
public static java.lang.String getPattern(Op<?> op){
|
||||
return patterns.get(op);
|
||||
}
|
||||
|
||||
@ -148,31 +155,31 @@ public class HqlOps extends Ops {
|
||||
}
|
||||
|
||||
public interface OpHql{
|
||||
Op<Date> CURRENT_DATE = new OpImpl<Date>();
|
||||
Op<Date> CURRENT_TIME = new OpImpl<Date>();
|
||||
Op<Date> CURRENT_TIMESTAMP = new OpImpl<Date>();
|
||||
Op<Date> DAY = new OpImpl<Date>();
|
||||
Op<Date> HOUR = new OpImpl<Date>();
|
||||
Op<Boolean> ISEMPTY = new OpImpl<Boolean>();
|
||||
Op<Boolean> ISNOTEMPTY = new OpImpl<Boolean>();
|
||||
Op<Date> MINUTE = new OpImpl<Date>();
|
||||
Op<Date> MONTH = new OpImpl<Date>();
|
||||
Op<Date> SECOND = new OpImpl<Date>();
|
||||
Op<Number> SUM = new OpImpl<Number>();
|
||||
Op<Date> SYSDATE = new OpImpl<Date>();
|
||||
Op<Date> YEAR = new OpImpl<Date>();
|
||||
Op<java.util.Date> CURRENT_DATE = new OpImpl<java.util.Date>();
|
||||
Op<java.util.Date> CURRENT_TIME = new OpImpl<java.util.Date>();
|
||||
Op<java.util.Date> CURRENT_TIMESTAMP = new OpImpl<java.util.Date>();
|
||||
Op<java.util.Date> DAY = new OpImpl<java.util.Date>();
|
||||
Op<java.util.Date> HOUR = new OpImpl<java.util.Date>();
|
||||
Op<java.lang.Boolean> ISEMPTY = new OpImpl<java.lang.Boolean>();
|
||||
Op<java.lang.Boolean> ISNOTEMPTY = new OpImpl<java.lang.Boolean>();
|
||||
Op<java.util.Date> MINUTE = new OpImpl<java.util.Date>();
|
||||
Op<java.util.Date> MONTH = new OpImpl<java.util.Date>();
|
||||
Op<java.util.Date> SECOND = new OpImpl<java.util.Date>();
|
||||
Op<java.lang.Number> SUM = new OpImpl<java.lang.Number>();
|
||||
Op<java.util.Date> SYSDATE = new OpImpl<java.util.Date>();
|
||||
Op<java.util.Date> YEAR = new OpImpl<java.util.Date>();
|
||||
}
|
||||
|
||||
public interface OpNumberAgg{
|
||||
Op<Number> AVG = new OpImpl<Number>();
|
||||
Op<Number> MAX = new OpImpl<Number>();
|
||||
Op<Number> MIN = new OpImpl<Number>();
|
||||
Op<java.lang.Number> AVG = new OpImpl<java.lang.Number>();
|
||||
Op<java.lang.Number> MAX = new OpImpl<java.lang.Number>();
|
||||
Op<java.lang.Number> MIN = new OpImpl<java.lang.Number>();
|
||||
}
|
||||
|
||||
public interface OpQuant{
|
||||
Op<Number> AVG_IN_COL = new OpImpl<Number>();
|
||||
Op<Number> MAX_IN_COL = new OpImpl<Number>();
|
||||
Op<Number> MIN_IN_COL = new OpImpl<Number>();
|
||||
Op<java.lang.Number> AVG_IN_COL = new OpImpl<java.lang.Number>();
|
||||
Op<java.lang.Number> MAX_IN_COL = new OpImpl<java.lang.Number>();
|
||||
Op<java.lang.Number> MIN_IN_COL = new OpImpl<java.lang.Number>();
|
||||
|
||||
// some / any = true for any
|
||||
// all = true for all
|
||||
|
||||
@ -13,9 +13,13 @@ import com.mysema.query.JoinExpression;
|
||||
import com.mysema.query.QueryBase;
|
||||
import com.mysema.query.grammar.HqlGrammar.*;
|
||||
import com.mysema.query.grammar.Ops.Op;
|
||||
import com.mysema.query.grammar.Types.*;
|
||||
import com.mysema.query.grammar.types.Alias;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Operation;
|
||||
import com.mysema.query.grammar.types.Path;
|
||||
import com.mysema.query.grammar.types.VisitorAdapter;
|
||||
import com.mysema.query.grammar.types.PathMetadata.PathType;
|
||||
|
||||
import com.mysema.query.grammar.PathMetadata.PathType;
|
||||
|
||||
/**
|
||||
* HqlSerializer provides
|
||||
@ -61,7 +65,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
|
||||
public void serialize(List<Expr<?>> select, List<JoinExpression> joins,
|
||||
ExprBoolean where, List<Expr<?>> groupBy, List<ExprBoolean> having,
|
||||
Expr.Boolean where, List<Expr<?>> groupBy, List<Expr.Boolean> having,
|
||||
List<OrderSpecifier<?>> orderBy, boolean forCountRow){
|
||||
if (forCountRow){
|
||||
_append("select count(*)\n");
|
||||
@ -82,8 +86,8 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
_append(sep);
|
||||
}
|
||||
// type specifier
|
||||
if (je.getTarget() instanceof PathEntity){
|
||||
PathEntity<?> pe = (PathEntity<?>)je.getTarget();
|
||||
if (je.getTarget() instanceof Path.Entity){
|
||||
Path.Entity<?> pe = (Path.Entity<?>)je.getTarget();
|
||||
if (pe.getMetadata().getParent() == null){
|
||||
String pn = pe.getType().getPackage().getName();
|
||||
String typeName = pe.getType().getName().substring(pn.length()+1);
|
||||
@ -123,17 +127,17 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
public String toString(){ return builder.toString(); }
|
||||
|
||||
@Override
|
||||
protected void visit(AliasSimple expr) {
|
||||
protected void visit(Alias.Simple expr) {
|
||||
handle(expr.getFrom())._append(" as ")._append(expr.getTo());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(AliasToPath expr) {
|
||||
protected void visit(Alias.ToPath expr) {
|
||||
handle(expr.getFrom())._append(" as ").visit(expr.getTo());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(ConstantExpr<?> expr) {
|
||||
protected void visit(Expr.Constant<?> expr) {
|
||||
boolean wrap = expr.getConstant().getClass().isArray();
|
||||
if (wrap) _append("(");
|
||||
_append(":a");
|
||||
@ -209,7 +213,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void visit(PathCollection<?> expr){
|
||||
protected void visit(Path.Collection<?> expr){
|
||||
// only wrap a PathCollection, if it the pathType is PROPERTY
|
||||
boolean wrap = wrapElements && expr.getMetadata().getPathType().equals(PathType.PROPERTY);
|
||||
if (wrap) _append("elements(");
|
||||
|
||||
@ -14,8 +14,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mysema.query.grammar.HqlQueryBase;
|
||||
import com.mysema.query.grammar.Types.ExprBoolean;
|
||||
import com.mysema.query.grammar.Types.PathEntity;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Path;
|
||||
|
||||
/**
|
||||
* HqlQuery provides a fluent statically typed interface for creating HQL queries
|
||||
@ -44,11 +44,11 @@ public class HqlQuery<RT> extends HqlQueryBase<HqlQuery<RT>>{
|
||||
return query;
|
||||
}
|
||||
|
||||
public HqlQuery<RT> forExample(PathEntity<?> entity, Map<String, Object> map) {
|
||||
public HqlQuery<RT> forExample(Path.Entity<?> entity, Map<String, Object> map) {
|
||||
select(entity).from(entity);
|
||||
try {
|
||||
List<ExprBoolean> conds = QueryUtil.createQBEConditions(entity,map);
|
||||
where(conds.toArray(new ExprBoolean[conds.size()]));
|
||||
List<Expr.Boolean> conds = QueryUtil.createQBEConditions(entity,map);
|
||||
where(conds.toArray(new Expr.Boolean[conds.size()]));
|
||||
return this;
|
||||
} catch (Exception e) {
|
||||
String error = "Caught " + e.getClass().getName();
|
||||
|
||||
@ -12,10 +12,9 @@ import java.util.Map;
|
||||
|
||||
import org.hibernate.Query;
|
||||
|
||||
import com.mysema.query.grammar.PathMetadata;
|
||||
import com.mysema.query.grammar.Types.ExprBoolean;
|
||||
import com.mysema.query.grammar.Types.PathEntity;
|
||||
import com.mysema.query.grammar.Types.PathNoEntitySimple;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
import com.mysema.query.grammar.types.Path;
|
||||
import com.mysema.query.grammar.types.PathMetadata;
|
||||
|
||||
|
||||
/**
|
||||
@ -40,12 +39,12 @@ public class QueryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ExprBoolean> createQBEConditions(PathEntity<?> entity,
|
||||
public static List<Expr.Boolean> createQBEConditions(Path.Entity<?> entity,
|
||||
Map<String, Object> map) {
|
||||
List<ExprBoolean> conds = new ArrayList<ExprBoolean>(map.size());
|
||||
List<Expr.Boolean> conds = new ArrayList<Expr.Boolean>(map.size());
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()){
|
||||
PathMetadata<String> md = PathMetadata.forProperty(entity, entry.getKey());
|
||||
PathNoEntitySimple<Object> path = new PathNoEntitySimple<Object>(Object.class, md);
|
||||
Path.NoEntitySimple<Object> path = new Path.NoEntitySimple<Object>(Object.class, md);
|
||||
if (entry.getValue() != null){
|
||||
conds.add(path.eq(entry.getValue()));
|
||||
}else{
|
||||
|
||||
@ -21,7 +21,7 @@ import com.mysema.query.grammar.HqlGrammar;
|
||||
import com.mysema.query.grammar.HqlQueryBase;
|
||||
import com.mysema.query.grammar.HqlSerializer;
|
||||
import com.mysema.query.grammar.HqlGrammar.Constructor;
|
||||
import com.mysema.query.grammar.Types.Expr;
|
||||
import com.mysema.query.grammar.types.Expr;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user