mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-06 21:05:50 +08:00
added ParametrizedExpression for Collection, Set, List and Map typed expressions
This commit is contained in:
parent
c6839b3d48
commit
b81b7d40b7
@ -28,13 +28,10 @@ import net.sf.cglib.proxy.MethodProxy;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.ParametrizedExpression;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.PathMetadata;
|
||||
import com.mysema.query.types.PathMetadataFactory;
|
||||
import com.mysema.query.types.expr.CollectionExpression;
|
||||
import com.mysema.query.types.expr.MapExpression;
|
||||
import com.mysema.query.types.path.ListPath;
|
||||
import com.mysema.query.types.path.MapPath;
|
||||
import com.mysema.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@ -103,8 +100,8 @@ class PropertyAccessInvocationHandler implements MethodInterceptor {
|
||||
if (propToObj.containsKey(propKey)) {
|
||||
rv = propToObj.get(propKey);
|
||||
} else {
|
||||
PathMetadata<Integer> pm = PathMetadataFactory.forListAccess((ListPath<?, ?>) hostExpression, (Integer) args[0]);
|
||||
Class<?> elementType = ((CollectionExpression<?,?>) hostExpression).getElementType();
|
||||
PathMetadata<Integer> pm = PathMetadataFactory.forListAccess((Path<?>)hostExpression, (Integer) args[0]);
|
||||
Class<?> elementType = ((ParametrizedExpression<?>) hostExpression).getParameter(0);
|
||||
rv = newInstance(elementType, elementType, proxy, propKey, pm);
|
||||
}
|
||||
aliasFactory.setCurrent(propToExpr.get(propKey));
|
||||
@ -114,8 +111,8 @@ class PropertyAccessInvocationHandler implements MethodInterceptor {
|
||||
if (propToObj.containsKey(propKey)) {
|
||||
rv = propToObj.get(propKey);
|
||||
} else {
|
||||
PathMetadata<?> pm = PathMetadataFactory.forMapAccess((MapPath<?, ?, ?>) hostExpression, args[0]);
|
||||
Class<?> valueType = ((MapExpression<?, ?>) hostExpression).getValueType();
|
||||
PathMetadata<?> pm = PathMetadataFactory.forMapAccess((Path<?>)hostExpression, args[0]);
|
||||
Class<?> valueType = ((ParametrizedExpression<?>) hostExpression).getParameter(1);
|
||||
rv = newInstance(valueType, valueType, proxy, propKey, pm);
|
||||
}
|
||||
aliasFactory.setCurrent(propToExpr.get(propKey));
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.mysema.query.types;
|
||||
|
||||
/**
|
||||
* @author tiwe
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface ParametrizedExpression<T> extends Expression<T> {
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
Class<?> getParameter(int index);
|
||||
|
||||
}
|
||||
@ -8,6 +8,7 @@ package com.mysema.query.types.expr;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.ParametrizedExpression;
|
||||
|
||||
/**
|
||||
* CollectionExpression represents java.util.Collection typed expressions
|
||||
@ -17,7 +18,7 @@ import com.mysema.query.types.Expression;
|
||||
* @param <E>
|
||||
* @see java.util.Collection
|
||||
*/
|
||||
public interface CollectionExpression<C extends Collection<E>, E>{
|
||||
public interface CollectionExpression<C extends Collection<E>, E> extends ParametrizedExpression<C>{
|
||||
|
||||
/**
|
||||
* Get an expression for <code>this.contains(child)</code>
|
||||
|
||||
@ -5,7 +5,10 @@
|
||||
*/
|
||||
package com.mysema.query.types.expr;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.ParametrizedExpression;
|
||||
|
||||
/**
|
||||
* MapExpression represents java.util.Map typed expressions
|
||||
@ -16,7 +19,7 @@ import com.mysema.query.types.Expression;
|
||||
* @param <V> value type
|
||||
* @see java.util.Map
|
||||
*/
|
||||
public interface MapExpression<K, V> {
|
||||
public interface MapExpression<K, V> extends ParametrizedExpression<Map<K,V>>{
|
||||
|
||||
/**
|
||||
* @param key
|
||||
|
||||
@ -10,8 +10,8 @@ import java.util.Collection;
|
||||
|
||||
import com.mysema.commons.lang.Assert;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.PathMetadata;
|
||||
import com.mysema.query.types.PathImpl;
|
||||
import com.mysema.query.types.PathMetadata;
|
||||
import com.mysema.query.types.Visitor;
|
||||
import com.mysema.query.types.expr.CollectionExpressionBase;
|
||||
|
||||
@ -84,4 +84,15 @@ public class CollectionPath<E> extends CollectionExpressionBase<Collection<E>,E>
|
||||
return pathMixin.getAnnotatedElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getParameter(int index) {
|
||||
if (index == 0){
|
||||
return elementType;
|
||||
}else{
|
||||
throw new IndexOutOfBoundsException(String.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -158,4 +158,13 @@ public class ListPath<E, Q extends SimpleExpression<E>> extends CollectionExpres
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getParameter(int index) {
|
||||
if (index == 0){
|
||||
return elementType;
|
||||
}else{
|
||||
throw new IndexOutOfBoundsException(String.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -150,5 +150,16 @@ public class MapPath<K, V, E extends SimpleExpression<V>> extends MapExpressionB
|
||||
return constructor.newInstance(pm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getParameter(int index) {
|
||||
if (index == 0){
|
||||
return keyType;
|
||||
}else if (index == 1){
|
||||
return valueType;
|
||||
}else{
|
||||
throw new IndexOutOfBoundsException(String.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -83,5 +83,14 @@ public class SetPath<E> extends CollectionExpressionBase<Set<E>,E> implements Pa
|
||||
public AnnotatedElement getAnnotatedElement(){
|
||||
return pathMixin.getAnnotatedElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getParameter(int index) {
|
||||
if (index == 0){
|
||||
return elementType;
|
||||
}else{
|
||||
throw new IndexOutOfBoundsException(String.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -78,5 +78,14 @@ public final class ListSubQuery<A> extends CollectionExpressionBase<List<A>,A> i
|
||||
public Expression<?> as(Expression<?> alias) {
|
||||
return SimpleOperation.create(alias.getType(),(Operator)Ops.ALIAS, this, alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getParameter(int index) {
|
||||
if (index == 0){
|
||||
return elementType;
|
||||
}else{
|
||||
throw new IndexOutOfBoundsException(String.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user