moved PathType to top level

This commit is contained in:
Timo Westkämper 2009-05-27 09:04:10 +00:00
parent 700753905c
commit c157203d24
15 changed files with 86 additions and 101 deletions

View File

@ -6,7 +6,7 @@
<parent>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-root</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.9-SNAPSHOT</version>
</parent>
<groupId>com.mysema.querydsl</groupId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-root</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.9-SNAPSHOT</version>
</parent>
<groupId>com.mysema.querydsl</groupId>

View File

@ -12,7 +12,7 @@ import com.mysema.query.serialization.OperationPatterns;
import com.mysema.query.types.operation.Operator;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.types.path.PathMetadata;
import com.mysema.query.types.path.PathMetadata.PathType;
import com.mysema.query.types.path.PathType;
/**
* JavaOps extends OperationPatterns to add Java syntax specific operation
@ -96,18 +96,18 @@ public class JavaPatterns extends OperationPatterns {
add(Ops.MOD, "%s %% %s");
// path types
for (PathType type : new PathType[] { PathMetadata.LISTVALUE_CONSTANT }) {
for (PathType type : new PathType[] { PathType.LISTVALUE_CONSTANT }) {
add(type, "%s.get(%s.intValue())");
}
// path types
for (PathType type : new PathType[] { PathMetadata.LISTVALUE,
PathMetadata.LISTVALUE_CONSTANT, PathMetadata.MAPVALUE,
PathMetadata.MAPVALUE_CONSTANT }) {
for (PathType type : new PathType[] { PathType.LISTVALUE,
PathType.LISTVALUE_CONSTANT, PathType.MAPVALUE,
PathType.MAPVALUE_CONSTANT }) {
add(type, "%s.get(%s)");
}
add(PathMetadata.ARRAYVALUE, "%s[%s]");
add(PathMetadata.ARRAYVALUE_CONSTANT, "%s[%s.intValue()]");
add(PathType.ARRAYVALUE, "%s[%s]");
add(PathType.ARRAYVALUE_CONSTANT, "%s[%s.intValue()]");
}
public static <A extends Comparable<? super A>> boolean between(A a, A b, A c) {

View File

@ -5,10 +5,6 @@
*/
package com.mysema.query.collections.eval;
import static com.mysema.query.types.path.PathMetadata.LISTVALUE_CONSTANT;
import static com.mysema.query.types.path.PathMetadata.PROPERTY;
import static com.mysema.query.types.path.PathMetadata.VARIABLE;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
@ -29,7 +25,7 @@ import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.Operator;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.types.path.Path;
import com.mysema.query.types.path.PathMetadata.PathType;
import com.mysema.query.types.path.PathType;
/**
* JavaSerializer is a Serializer implementation for the Java language
@ -136,9 +132,9 @@ public class JavaSerializer extends BaseSerializer<JavaSerializer> {
parentAsString = toString((Expr<?>) path.getMetadata().getParent(),
false);
}
if (pathType == VARIABLE) {
if (pathType == PathType.VARIABLE) {
exprAsString = path.getMetadata().getExpression().toString();
} else if (pathType == PROPERTY) {
} else if (pathType == PathType.PROPERTY) {
String prefix = "get";
if (((Expr<?>) path).getType() != null
&& ((Expr<?>) path).getType().equals(Boolean.class)) {
@ -148,7 +144,7 @@ public class JavaSerializer extends BaseSerializer<JavaSerializer> {
+ StringUtils.capitalize(path.getMetadata().getExpression()
.toString()) + "()";
} else if (pathType == LISTVALUE_CONSTANT) {
} else if (pathType == PathType.LISTVALUE_CONSTANT) {
exprAsString = path.getMetadata().getExpression().toString();
} else if (path.getMetadata().getExpression() != null) {

View File

@ -6,7 +6,7 @@
<parent>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-root</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.9-SNAPSHOT</version>
</parent>
<groupId>com.mysema.querydsl</groupId>

View File

@ -5,11 +5,6 @@
*/
package com.mysema.query.serialization;
import static com.mysema.query.types.path.PathMetadata.ARRAYVALUE_CONSTANT;
import static com.mysema.query.types.path.PathMetadata.LISTVALUE_CONSTANT;
import static com.mysema.query.types.path.PathMetadata.PROPERTY;
import static com.mysema.query.types.path.PathMetadata.VARIABLE;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -23,10 +18,10 @@ import com.mysema.query.types.expr.EArrayConstructor;
import com.mysema.query.types.expr.EConstant;
import com.mysema.query.types.expr.EConstructor;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.Operator;
import com.mysema.query.types.operation.Operation;
import com.mysema.query.types.operation.Operator;
import com.mysema.query.types.path.Path;
import com.mysema.query.types.path.PathMetadata.PathType;
import com.mysema.query.types.path.PathType;
import com.mysema.query.types.quant.Quant;
/**
@ -149,9 +144,9 @@ public abstract class BaseSerializer<SubType extends BaseSerializer<SubType>>
parentAsString = toString((Expr<?>) path.getMetadata().getParent(),
false);
}
if (pathType == PROPERTY || pathType == VARIABLE
|| pathType == LISTVALUE_CONSTANT
|| pathType == ARRAYVALUE_CONSTANT) {
if (pathType == PathType.PROPERTY || pathType == PathType.VARIABLE
|| pathType == PathType.LISTVALUE_CONSTANT
|| pathType == PathType.ARRAYVALUE_CONSTANT) {
exprAsString = path.getMetadata().getExpression().toString();
} else if (path.getMetadata().getExpression() != null) {
exprAsString = toString(path.getMetadata().getExpression(), false);

View File

@ -12,7 +12,7 @@ import com.mysema.query.types.operation.Operator;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.types.operation.Ops.OpNumberAgg;
import com.mysema.query.types.path.PathMetadata;
import com.mysema.query.types.path.PathMetadata.PathType;
import com.mysema.query.types.path.PathType;
/**
* OperationPatterns provides operator patterns for SQL/HQL serialization
@ -153,13 +153,13 @@ public class OperationPatterns {
add(Ops.OpString.SPACE, "space(%s)");
// path types
for (PathType type : new PathType[] { PathMetadata.LISTVALUE,
PathMetadata.LISTVALUE_CONSTANT, PathMetadata.MAPVALUE,
PathMetadata.MAPVALUE_CONSTANT }) {
for (PathType type : new PathType[] { PathType.LISTVALUE,
PathType.LISTVALUE_CONSTANT, PathType.MAPVALUE,
PathType.MAPVALUE_CONSTANT }) {
add(type, "%s.get(%s)");
}
add(PathMetadata.PROPERTY, "%s.%s");
add(PathMetadata.VARIABLE, "%s");
add(PathType.PROPERTY, "%s.%s");
add(PathType.VARIABLE, "%s");
// numeric aggregates
add(OpNumberAgg.AVG_AGG, "avg(%s)");

View File

@ -11,7 +11,6 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
import com.mysema.query.types.ExprFactory;
import com.mysema.query.types.SimpleExprFactory;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.Operator;
/**
* PathMetadata provides metadata for Path expressions.
@ -21,70 +20,38 @@ import com.mysema.query.types.operation.Operator;
*/
public final class PathMetadata<T> {
/**
* The Class PathType.
*/
public static class PathType extends Operator<Path<?>> {
private final String symbol;
public PathType(String symbol) {
super();
this.symbol = symbol;
}
public String toString() {
return symbol;
}
}
private static ExprFactory factory = SimpleExprFactory.getInstance();
public static final PathType ARRAYVALUE = new PathType("array value");
public static final PathType ARRAYVALUE_CONSTANT = new PathType("array value constant");
public static final PathType LISTVALUE = new PathType("list value");
public static final PathType LISTVALUE_CONSTANT = new PathType("list value constant");
public static final PathType MAPVALUE = new PathType("map value");
public static final PathType MAPVALUE_CONSTANT = new PathType("map value constant");
public static final PathType PROPERTY = new PathType("propery");
public static final PathType VARIABLE = new PathType("variable");
public static PathMetadata<Integer> forArrayAccess(PArray<?> parent, Expr<Integer> index) {
return new PathMetadata<Integer>(parent, index, ARRAYVALUE);
return new PathMetadata<Integer>(parent, index, PathType.ARRAYVALUE);
}
public static PathMetadata<Integer> forArrayAccess(PArray<?> parent, int index) {
return new PathMetadata<Integer>(parent, factory.createConstant(index), ARRAYVALUE_CONSTANT);
return new PathMetadata<Integer>(parent, factory.createConstant(index), PathType.ARRAYVALUE_CONSTANT);
}
public static PathMetadata<Integer> forListAccess(PCollection<?> parent, Expr<Integer> index) {
return new PathMetadata<Integer>(parent, index, LISTVALUE);
return new PathMetadata<Integer>(parent, index, PathType.LISTVALUE);
}
public static PathMetadata<Integer> forListAccess(PCollection<?> parent, int index) {
return new PathMetadata<Integer>(parent, factory.createConstant(index), LISTVALUE_CONSTANT);
return new PathMetadata<Integer>(parent, factory.createConstant(index), PathType.LISTVALUE_CONSTANT);
}
public static <KT> PathMetadata<KT> forMapAccess(PMap<?, ?> parent, Expr<KT> key) {
return new PathMetadata<KT>(parent, key, MAPVALUE);
return new PathMetadata<KT>(parent, key, PathType.MAPVALUE);
}
public static <KT> PathMetadata<KT> forMapAccess(PMap<?, ?> parent, KT key) {
return new PathMetadata<KT>(parent, factory.createConstant(key), MAPVALUE_CONSTANT);
return new PathMetadata<KT>(parent, factory.createConstant(key), PathType.MAPVALUE_CONSTANT);
}
public static PathMetadata<String> forProperty(Path<?> parent, String property) {
return new PathMetadata<String>(parent, factory.createConstant(property), PROPERTY);
return new PathMetadata<String>(parent, factory.createConstant(property), PathType.PROPERTY);
}
public static PathMetadata<String> forVariable(String variable) {
return new PathMetadata<String>(null, factory.createConstant(variable),VARIABLE);
return new PathMetadata<String>(null, factory.createConstant(variable), PathType.VARIABLE);
}
private final Expr<T> expression;

View File

@ -0,0 +1,35 @@
package com.mysema.query.types.path;
import com.mysema.query.types.operation.Operator;
/**
* The Class PathType.
*/
public class PathType extends Operator<Path<?>> {
private final String symbol;
public PathType(String symbol) {
super();
this.symbol = symbol;
}
public String toString() {
return symbol;
}
public static final PathType ARRAYVALUE = new PathType("array value");
public static final PathType ARRAYVALUE_CONSTANT = new PathType("array value constant");
public static final PathType LISTVALUE = new PathType("list value");
public static final PathType LISTVALUE_CONSTANT = new PathType("list value constant");
public static final PathType MAPVALUE = new PathType("map value");
public static final PathType MAPVALUE_CONSTANT = new PathType("map value constant");
public static final PathType PROPERTY = new PathType("propery");
public static final PathType VARIABLE = new PathType("variable");
}

View File

@ -6,7 +6,7 @@
<parent>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-root</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.9-SNAPSHOT</version>
</parent>
<groupId>com.mysema.querydsl</groupId>

View File

@ -14,7 +14,7 @@ import com.mysema.query.serialization.OperationPatterns;
import com.mysema.query.types.operation.Operator;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.types.path.PathMetadata;
import com.mysema.query.types.path.PathMetadata.PathType;
import com.mysema.query.types.path.PathType;
/**
* HqlOps extends OperationPatterns to provide operator patterns for HQL
@ -96,14 +96,14 @@ public class HQLPatterns extends OperationPatterns {
add(OpQuant.NOTEXISTS, "not exists %s");
// path types
for (PathType type : new PathType[] { PathMetadata.LISTVALUE,
PathMetadata.LISTVALUE_CONSTANT, PathMetadata.MAPVALUE,
PathMetadata.MAPVALUE_CONSTANT }) {
for (PathType type : new PathType[] { PathType.LISTVALUE,
PathType.LISTVALUE_CONSTANT, PathType.MAPVALUE,
PathType.MAPVALUE_CONSTANT }) {
add(type, "%s[%s]");
}
add(PathMetadata.PROPERTY, "%s.%s");
add(PathType.PROPERTY, "%s.%s");
add(PathMetadata.VARIABLE, "%s");
add(PathType.VARIABLE, "%s");
// HQL types
add(HqlPathType.MINELEMENT, "minelement(%s)");

View File

@ -5,10 +5,7 @@
*/
package com.mysema.query.hql;
import static com.mysema.query.types.path.PathMetadata.PROPERTY;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.mysema.query.JoinExpression;
@ -28,11 +25,7 @@ import com.mysema.query.types.operation.Ops;
import com.mysema.query.types.path.PCollection;
import com.mysema.query.types.path.PEntity;
import com.mysema.query.types.path.Path;
import com.mysema.query.types.quant.QBoolean;
import com.mysema.query.types.quant.QComparable;
import com.mysema.query.types.quant.QNumber;
import com.mysema.query.types.quant.QSimple;
import com.mysema.query.types.quant.Quant;
import com.mysema.query.types.path.PathType;
/**
* HqlSerializer serializes querydsl expressions into HQL syntax.
@ -184,7 +177,7 @@ public class HQLSerializer extends BaseSerializer<HQLSerializer> {
protected void visit(PCollection<?> expr) {
// only wrap a PathCollection, if it the pathType is PROPERTY
boolean wrap = wrapElements
&& expr.getMetadata().getPathType().equals(PROPERTY);
&& expr.getMetadata().getPathType().equals(PathType.PROPERTY);
if (wrap) {
append("elements(");
}

View File

@ -6,7 +6,7 @@
<parent>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-root</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.9-SNAPSHOT</version>
</parent>
<groupId>com.mysema.querydsl</groupId>

View File

@ -10,8 +10,7 @@ import java.util.Collection;
import com.mysema.query.serialization.OperationPatterns;
import com.mysema.query.types.operation.Operator;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.types.path.PathMetadata;
import com.mysema.query.types.path.PathMetadata.PathType;
import com.mysema.query.types.path.PathType;
/**
* Operation patterns for JDOQL serialization
@ -76,14 +75,14 @@ public class JDOQLPatterns extends OperationPatterns {
// path types
add(PathMetadata.VARIABLE, "%s");
for (PathType type : new PathType[] { PathMetadata.LISTVALUE,
PathMetadata.LISTVALUE_CONSTANT, PathMetadata.MAPVALUE,
PathMetadata.MAPVALUE_CONSTANT }) {
add(PathType.VARIABLE, "%s");
for (PathType type : new PathType[] { PathType.LISTVALUE,
PathType.LISTVALUE_CONSTANT, PathType.MAPVALUE,
PathType.MAPVALUE_CONSTANT }) {
add(type, "%s.get(%s)");
}
add(PathMetadata.ARRAYVALUE, "%s[%s]");
add(PathMetadata.ARRAYVALUE_CONSTANT, "%s[%s]");
add(PathType.ARRAYVALUE, "%s[%s]");
add(PathType.ARRAYVALUE_CONSTANT, "%s[%s]");
}
/**

View File

@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-root</artifactId>
<version>0.3.8-SNAPSHOT</version>
<version>0.3.9-SNAPSHOT</version>
<name>Querydsl</name>
<description>parent project for querydsl modules</description>
<url>http://source.mysema.com/display/querydsl</url>