refactored PathMetadata.PathType class and instances

This commit is contained in:
Timo Westkämper 2008-04-03 21:21:47 +00:00
parent 2cfe17028b
commit 407af3bec2
3 changed files with 50 additions and 51 deletions

View File

@ -193,7 +193,6 @@ public class HqlGrammar extends Grammar{
public static Expr.Comparable<Date> year(Expr<Date> date){
return createComparable(OpHql.YEAR, date);
}
}

View File

@ -11,14 +11,12 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
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;
import com.mysema.query.grammar.types.PathMetadata.PathType;
import com.mysema.query.grammar.types.PathMetadata.PathTypeImpl;
/**
* Ops provides
* HqlOps provides
*
* @author tiwe
* @version $Id$
@ -29,8 +27,8 @@ public class HqlOps {
static{
Set<Op<?>> ops = new HashSet<Op<?>>();
ops.add(Op.IN);
ops.add(Op.NOTIN);
ops.add(Ops.IN);
ops.add(Ops.NOTIN);
ops.add(OpQuant.ALL);
ops.add(OpQuant.ANY);
ops.add(OpQuant.EXISTS);
@ -75,13 +73,13 @@ public class HqlOps {
add(OpNumberAgg.MIN, "min(%s)");
// various
add(Op.EQ, "%s = %s",18);
add(Op.ISTYPEOF, "%s.class = %s");
add(Op.NE, "%s != %s",25);
add(Op.IN, "%s in %s");
add(Op.NOTIN, "%s not in %s");
add(Op.ISNULL, "%s is null",26);
add(Op.ISNOTNULL, "%s is not null",26);
add(Ops.EQ, "%s = %s",18);
add(Ops.ISTYPEOF, "%s.class = %s");
add(Ops.NE, "%s != %s",25);
add(Ops.IN, "%s in %s");
add(Ops.NOTIN, "%s not in %s");
add(Ops.ISNULL, "%s is null",26);
add(Ops.ISNOTNULL, "%s is not null",26);
// add(Op.SIZE, "size(%s)");
// string
@ -117,12 +115,12 @@ public class HqlOps {
add(OpQuant.NOTEXISTS, "not exists %s");
// path types
for (PathType type : new PathType[]{PathType.LISTVALUE, PathType.LISTVALUE_CONSTANT, PathType.MAPVALUE, PathType.MAPVALUE_CONSTANT}){
for (PathType type : new PathType[]{PathMetadata.LISTVALUE, PathMetadata.LISTVALUE_CONSTANT, PathMetadata.MAPVALUE, PathMetadata.MAPVALUE_CONSTANT}){
add(type,"%s[%s]");
}
add(PathType.PROPERTY,"%s.%s"); // TODO : as string
add(PathType.SIZE,"%s.size");
add(PathType.VARIABLE,"%s"); // TODO : as string
add(PathMetadata.PROPERTY,"%s.%s"); // TODO : as string
add(PathMetadata.SIZE,"%s.size");
add(PathMetadata.VARIABLE,"%s"); // TODO : as string
// HQL types
add(HqlPathType.MINELEMENT, "minelement(%s)");
@ -155,49 +153,49 @@ public class HqlOps {
}
public interface OpHql{
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>();
Op<java.util.Date> CURRENT_DATE = new Op<java.util.Date>();
Op<java.util.Date> CURRENT_TIME = new Op<java.util.Date>();
Op<java.util.Date> CURRENT_TIMESTAMP = new Op<java.util.Date>();
Op<java.util.Date> DAY = new Op<java.util.Date>();
Op<java.util.Date> HOUR = new Op<java.util.Date>();
Op<java.lang.Boolean> ISEMPTY = new Op<java.lang.Boolean>();
Op<java.lang.Boolean> ISNOTEMPTY = new Op<java.lang.Boolean>();
Op<java.util.Date> MINUTE = new Op<java.util.Date>();
Op<java.util.Date> MONTH = new Op<java.util.Date>();
Op<java.util.Date> SECOND = new Op<java.util.Date>();
Op<java.lang.Number> SUM = new Op<java.lang.Number>();
Op<java.util.Date> SYSDATE = new Op<java.util.Date>();
Op<java.util.Date> YEAR = new Op<java.util.Date>();
}
public interface OpNumberAgg{
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>();
Op<java.lang.Number> AVG = new Op<java.lang.Number>();
Op<java.lang.Number> MAX = new Op<java.lang.Number>();
Op<java.lang.Number> MIN = new Op<java.lang.Number>();
}
public interface OpQuant{
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>();
Op<java.lang.Number> AVG_IN_COL = new Op<java.lang.Number>();
Op<java.lang.Number> MAX_IN_COL = new Op<java.lang.Number>();
Op<java.lang.Number> MIN_IN_COL = new Op<java.lang.Number>();
// some / any = true for any
// all = true for all
// exists = true is subselect matches
// not exists = true if subselect doesn't match
Op<?> ANY = new OpImpl<Object>();
Op<?> ALL = new OpImpl<Object>();
Op<?> EXISTS = new OpImpl<Object>();
Op<?> NOTEXISTS = new OpImpl<Object>();
Op<?> ANY = new Op<Object>();
Op<?> ALL = new Op<Object>();
Op<?> EXISTS = new Op<Object>();
Op<?> NOTEXISTS = new Op<Object>();
}
public interface HqlPathType{
PathType MINELEMENT = new PathTypeImpl();
PathType MAXELEMENT = new PathTypeImpl();
PathType MININDEX = new PathTypeImpl();
PathType MAXINDEX = new PathTypeImpl();
PathType LISTINDICES = new PathTypeImpl();
PathType MAPINDICES = new PathTypeImpl();
PathType MINELEMENT = new PathType();
PathType MAXELEMENT = new PathType();
PathType MININDEX = new PathType();
PathType MAXINDEX = new PathType();
PathType LISTINDICES = new PathType();
PathType MAPINDICES = new PathType();
}
}

View File

@ -20,6 +20,8 @@ import com.mysema.query.grammar.types.VisitorAdapter;
import com.mysema.query.grammar.types.HqlTypes.*;
import com.mysema.query.grammar.types.PathMetadata.PathType;
import static com.mysema.query.grammar.types.PathMetadata.*;
/**
* HqlSerializer provides
@ -196,8 +198,8 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
if (path.getMetadata().getParent() != null){
parentAsString = _toString((Expr<?>)path.getMetadata().getParent(),false);
}
if (pathType == PathType.PROPERTY || pathType == PathType.VARIABLE ||
pathType == PathType.LISTVALUE_CONSTANT){
if (pathType == PROPERTY || pathType == VARIABLE ||
pathType == LISTVALUE_CONSTANT){
exprAsString = path.getMetadata().getExpression().toString();
}else if (path.getMetadata().getExpression() != null){
exprAsString = _toString(path.getMetadata().getExpression(),false);
@ -215,7 +217,7 @@ public class HqlSerializer extends VisitorAdapter<HqlSerializer>{
@Override
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);
boolean wrap = wrapElements && expr.getMetadata().getPathType().equals(PROPERTY);
if (wrap) _append("elements(");
visit((Path<?>)expr);
if (wrap) _append(")");