refactoring Querydsl to new Type model

This commit is contained in:
Timo Westkämper 2010-09-15 06:47:41 +00:00
parent 8d9d6208b4
commit 51a86662ff
12 changed files with 34 additions and 36 deletions

View File

@ -43,7 +43,7 @@ public final class ExpressionUtils {
}
public static <D> Expression<D> as(Expression<D> source, String alias) {
return as(source, new PathMixin<D>(source.getType(), PathMetadataFactory.forVariable(alias)));
return as(source, new PathMixin<D>(source.getType(), alias));
}
public static <D> Predicate eqConst(Expression<D> left, D constant) {

View File

@ -8,12 +8,6 @@ package com.mysema.query.types;
import javax.annotation.Nonnegative;
import com.mysema.commons.lang.Assert;
import com.mysema.query.types.expr.NumberConstant;
import com.mysema.query.types.expr.SimpleConstant;
import com.mysema.query.types.expr.StringConstant;
import com.mysema.query.types.path.ArrayPath;
import com.mysema.query.types.path.ListPath;
import com.mysema.query.types.path.MapPath;
/**
* @author tiwe
@ -21,36 +15,36 @@ import com.mysema.query.types.path.MapPath;
*/
public final class PathMetadataFactory {
public static PathMetadata<Integer> forArrayAccess(ArrayPath<?> parent, Expression<Integer> index) {
public static PathMetadata<Integer> forArrayAccess(Path<?> parent, Expression<Integer> index) {
return new PathMetadata<Integer>(parent, index, PathType.ARRAYVALUE);
}
public static PathMetadata<Integer> forArrayAccess(ArrayPath<?> parent, @Nonnegative int index) {
return new PathMetadata<Integer>(parent, NumberConstant.create(index), PathType.ARRAYVALUE_CONSTANT);
public static PathMetadata<Integer> forArrayAccess(Path<?> parent, @Nonnegative int index) {
return new PathMetadata<Integer>(parent, new ConstantMixin<Integer>(index), PathType.ARRAYVALUE_CONSTANT);
}
public static PathMetadata<Integer> forListAccess(ListPath<?, ?> parent, Expression<Integer> index) {
public static PathMetadata<Integer> forListAccess(Path<?> parent, Expression<Integer> index) {
return new PathMetadata<Integer>(parent, index, PathType.LISTVALUE);
}
public static PathMetadata<Integer> forListAccess(ListPath<?, ?> parent, @Nonnegative int index) {
return new PathMetadata<Integer>(parent, NumberConstant.create(index), PathType.LISTVALUE_CONSTANT);
public static PathMetadata<Integer> forListAccess(Path<?> parent, @Nonnegative int index) {
return new PathMetadata<Integer>(parent, new ConstantMixin<Integer>(index), PathType.LISTVALUE_CONSTANT);
}
public static <KT> PathMetadata<KT> forMapAccess(MapPath<?, ?, ?> parent, Expression<KT> key) {
public static <KT> PathMetadata<KT> forMapAccess(Path<?> parent, Expression<KT> key) {
return new PathMetadata<KT>(parent, key, PathType.MAPVALUE);
}
public static <KT> PathMetadata<KT> forMapAccess(MapPath<?, ?, ?> parent, KT key) {
return new PathMetadata<KT>(parent, SimpleConstant.create(key), PathType.MAPVALUE_CONSTANT);
public static <KT> PathMetadata<KT> forMapAccess(Path<?> parent, KT key) {
return new PathMetadata<KT>(parent, new ConstantMixin<KT>(key), PathType.MAPVALUE_CONSTANT);
}
public static PathMetadata<String> forProperty(Path<?> parent, String property) {
return new PathMetadata<String>(parent, StringConstant.create(Assert.hasLength(property,"property"), true), PathType.PROPERTY);
return new PathMetadata<String>(parent, new ConstantMixin<String>(Assert.hasLength(property,"property")), PathType.PROPERTY);
}
public static PathMetadata<String> forVariable(String variable) {
return new PathMetadata<String>(null, StringConstant.create(Assert.hasLength(variable,"variable"), true), PathType.VARIABLE);
return new PathMetadata<String>(null, new ConstantMixin<String>(Assert.hasLength(variable,"variable")), PathType.VARIABLE);
}
private PathMetadataFactory(){}

View File

@ -30,6 +30,10 @@ public class PathMixin<T> extends MixinBase<T> implements Path<T> {
@Nullable
private AnnotatedElement annotatedElement;
public PathMixin(Class<? extends T> type, String variable){
this(type, PathMetadataFactory.forVariable(variable));
}
public PathMixin(Class<? extends T> type, PathMetadata<?> metadata){
super(type);
this.metadata = metadata;

View File

@ -10,8 +10,8 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.PathMixin;
import com.mysema.query.types.Predicate;
import com.mysema.query.types.path.SimplePath;
/**
* BooleanExpression represents boolean expressions
@ -58,7 +58,7 @@ public abstract class BooleanExpression extends ComparableExpression<Boolean> im
@SuppressWarnings("unchecked")
@Override
public BooleanExpression as(String alias) {
return BooleanOperation.create((Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return BooleanOperation.create((Operator)Ops.ALIAS, this, new PathMixin(getType(), alias));
}
/**

View File

@ -9,7 +9,7 @@ import com.mysema.query.types.Expression;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.SimplePath;
import com.mysema.query.types.PathMixin;
/**
* ComparableExpression extends EComparableBase to provide comparison methods.
@ -34,7 +34,7 @@ public abstract class ComparableExpression<D extends Comparable> extends Compara
@Override
public ComparableExpression<D> as(String alias) {
return ComparableOperation.create(getType(),(Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return ComparableOperation.create(getType(),(Operator)Ops.ALIAS, this, new PathMixin<D>(getType(), alias));
}
/**

View File

@ -12,7 +12,7 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.SimplePath;
import com.mysema.query.types.PathMixin;
/**
* DateExpression represents Date expressions
@ -68,7 +68,7 @@ public abstract class DateExpression<D extends Comparable> extends TemporalExpre
@Override
public DateExpression as(String alias) {
return DateOperation.create(getType(), (Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return DateOperation.create(getType(), (Operator)Ops.ALIAS, this, new PathMixin<D>(getType(), alias));
}
/**

View File

@ -12,7 +12,7 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.SimplePath;
import com.mysema.query.types.PathMixin;
/**
* DateTimeExpression represents Date / Time expressions
@ -85,7 +85,7 @@ public abstract class DateTimeExpression<D extends Comparable> extends DateExpre
@Override
public DateTimeExpression as(String alias) {
return DateTimeOperation.create(getType(), (Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return DateTimeOperation.create(getType(), (Operator)Ops.ALIAS, this, new PathMixin<D>(getType(), alias));
}
/**

View File

@ -8,7 +8,7 @@ package com.mysema.query.types.expr;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.SimplePath;
import com.mysema.query.types.PathMixin;
/**
* @author tiwe
@ -32,7 +32,7 @@ public abstract class EnumExpression<T extends Enum<T>> extends ComparableExpres
@SuppressWarnings("unchecked")
@Override
public EnumExpression<T> as(String alias) {
return EnumOperation.create(getType(),(Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return EnumOperation.create(getType(),(Operator)Ops.ALIAS, this, new PathMixin<T>(getType(), alias));
}
/**

View File

@ -16,8 +16,8 @@ import com.mysema.query.types.Expression;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.PathMixin;
import com.mysema.query.types.Ops.MathOps;
import com.mysema.query.types.path.SimplePath;
import com.mysema.util.MathUtils;
/**
@ -86,7 +86,7 @@ public abstract class NumberExpression<D extends Number & Comparable<?>> extends
@SuppressWarnings("unchecked")
@Override
public NumberExpression<D> as(String alias) {
return NumberOperation.create(getType(),(Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return NumberOperation.create(getType(),(Operator)Ops.ALIAS, this, new PathMixin<D>(getType(), alias));
}
/**

View File

@ -15,9 +15,9 @@ import com.mysema.query.types.Expression;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.PathMixin;
import com.mysema.query.types.Templates;
import com.mysema.query.types.ToStringVisitor;
import com.mysema.query.types.path.SimplePath;
/**
* ESimple is the base class for Expr implementations. It provides default implementations
@ -97,7 +97,7 @@ public abstract class SimpleExpression<D> implements Expression<D> {
*/
@SuppressWarnings("unchecked")
public SimpleExpression<D> as(String alias) {
return SimpleOperation.create(getType(),(Operator)Ops.ALIAS, this, new SimplePath<D>(getType(), alias));
return SimpleOperation.create(getType(),(Operator)Ops.ALIAS, this, new PathMixin<D>(getType(), alias));
}
/**

View File

@ -11,7 +11,7 @@ import com.mysema.query.types.Expression;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.SimplePath;
import com.mysema.query.types.PathMixin;
/**
* StringExpression represents String expressions
@ -45,7 +45,7 @@ public abstract class StringExpression extends ComparableExpression<String> {
@SuppressWarnings("unchecked")
@Override
public StringExpression as(String alias) {
return StringOperation.create((Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return StringOperation.create((Operator)Ops.ALIAS, this, new PathMixin<String>(getType(), alias));
}
/**

View File

@ -12,7 +12,7 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Operator;
import com.mysema.query.types.Ops;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.SimplePath;
import com.mysema.query.types.PathMixin;
/**
* TimeExpression represents Time expressions
@ -42,7 +42,7 @@ public abstract class TimeExpression<D extends Comparable> extends TemporalExpre
@Override
public TimeExpression<D> as(String alias) {
return TimeOperation.create(getType(), (Operator)Ops.ALIAS, this, new SimplePath(getType(), alias));
return TimeOperation.create(getType(), (Operator)Ops.ALIAS, this, new PathMixin<D>(getType(), alias));
}
/**