mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
This commit is contained in:
parent
19bf890c5b
commit
fa062f956f
@ -96,4 +96,24 @@ public class DefaultPathFactory implements PathFactory{
|
||||
return new TimePath<T>(type, metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollectionType(Class<?> cl) {
|
||||
return Collection.class.isAssignableFrom(cl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListType(Class<?> cl) {
|
||||
return List.class.isAssignableFrom(cl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSetType(Class<?> cl) {
|
||||
return Set.class.isAssignableFrom(cl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMapType(Class<?> cl) {
|
||||
return Map.class.isAssignableFrom(cl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -53,7 +53,15 @@ public enum MethodType{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
SCALA_GETTER(".+", Object.class, Object.class),;
|
||||
SCALA_GETTER(".+", Object.class, Object.class),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
SCALA_LIST_ACCESS("apply", Object.class, Object.class, int.class),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
SCALA_MAP_ACCESS("get", Object.class, Object.class, Object.class);
|
||||
|
||||
private final Pattern pattern;
|
||||
|
||||
|
||||
@ -19,6 +19,14 @@ import com.mysema.query.types.PathMetadata;
|
||||
*/
|
||||
public interface PathFactory {
|
||||
|
||||
boolean isCollectionType(Class<?> cl);
|
||||
|
||||
boolean isSetType(Class<?> cl);
|
||||
|
||||
boolean isListType(Class<?> cl);
|
||||
|
||||
boolean isMapType(Class<?> cl);
|
||||
|
||||
<T> Path<T[]> createArrayPath(Class<T[]> type, PathMetadata<?> metadata);
|
||||
|
||||
<T> Path<T> createEntityPath(Class<T> type, PathMetadata<?> metadata);
|
||||
|
||||
@ -13,12 +13,9 @@ import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -94,7 +91,7 @@ class PropertyAccessInvocationHandler implements MethodInterceptor {
|
||||
}
|
||||
aliasFactory.setCurrent(propToExpr.get(ptyName));
|
||||
|
||||
} else if (methodType == MethodType.LIST_ACCESS) {
|
||||
} else if (methodType == MethodType.LIST_ACCESS || methodType == MethodType.SCALA_LIST_ACCESS) {
|
||||
// TODO : manage cases where the argument is based on a property invocation
|
||||
Object propKey = Arrays.asList(MethodType.LIST_ACCESS, args[0]);
|
||||
if (propToObj.containsKey(propKey)) {
|
||||
@ -106,7 +103,7 @@ class PropertyAccessInvocationHandler implements MethodInterceptor {
|
||||
}
|
||||
aliasFactory.setCurrent(propToExpr.get(propKey));
|
||||
|
||||
} else if (methodType == MethodType.MAP_ACCESS) {
|
||||
} else if (methodType == MethodType.MAP_ACCESS || methodType == MethodType.SCALA_MAP_ACCESS) {
|
||||
Object propKey = Arrays.asList(MethodType.MAP_ACCESS, args[0]);
|
||||
if (propToObj.containsKey(propKey)) {
|
||||
rv = propToObj.get(propKey);
|
||||
@ -127,7 +124,9 @@ class PropertyAccessInvocationHandler implements MethodInterceptor {
|
||||
rv = hostExpression;
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invocation of " + method.getName() + " not supported");
|
||||
throw new IllegalArgumentException(
|
||||
"Invocation of " + method.getName() +
|
||||
" with types " + Arrays.asList(method.getParameterTypes()) + " not supported");
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@ -195,27 +194,27 @@ class PropertyAccessInvocationHandler implements MethodInterceptor {
|
||||
path = pathFactory.createBooleanPath(metadata);
|
||||
rv = Boolean.TRUE;
|
||||
|
||||
} else if (List.class.isAssignableFrom(type)) {
|
||||
} else if (pathFactory.isMapType(type)) {
|
||||
Class<Object> keyType = (Class)ReflectionUtils.getTypeParameter(genericType, 0);
|
||||
Class<Object> valueType = (Class)ReflectionUtils.getTypeParameter(genericType, 1);
|
||||
path = pathFactory.createMapPath(keyType, valueType, metadata);
|
||||
rv = aliasFactory.createAliasForProperty(type, parent, path);
|
||||
|
||||
} else if (pathFactory.isListType(type)) {
|
||||
Class<Object> elementType = (Class)ReflectionUtils.getTypeParameter(genericType, 0);
|
||||
path = pathFactory.createListPath(elementType, metadata);
|
||||
rv = aliasFactory.createAliasForProperty(type, parent, path);
|
||||
|
||||
} else if (Set.class.isAssignableFrom(type)) {
|
||||
} else if (pathFactory.isSetType(type)) {
|
||||
Class<?> elementType = ReflectionUtils.getTypeParameter(genericType, 0);
|
||||
path = pathFactory.createSetPath(elementType, metadata);
|
||||
rv = aliasFactory.createAliasForProperty(type, parent, path);
|
||||
|
||||
} else if (Collection.class.isAssignableFrom(type)) {
|
||||
} else if (pathFactory.isCollectionType(type)) {
|
||||
Class<?> elementType = ReflectionUtils.getTypeParameter(genericType, 0);
|
||||
path = pathFactory.createCollectionPath(elementType, metadata);
|
||||
rv = aliasFactory.createAliasForProperty(type, parent, path);
|
||||
|
||||
} else if (Map.class.isAssignableFrom(type)) {
|
||||
Class<Object> keyType = (Class)ReflectionUtils.getTypeParameter(genericType, 0);
|
||||
Class<Object> valueType = (Class)ReflectionUtils.getTypeParameter(genericType, 1);
|
||||
path = pathFactory.createMapPath(keyType, valueType, metadata);
|
||||
rv = aliasFactory.createAliasForProperty(type, parent, path);
|
||||
|
||||
} else if (Enum.class.isAssignableFrom(type)) {
|
||||
path = pathFactory.createEnumPath((Class)type, metadata);
|
||||
rv = type.getEnumConstants()[0];
|
||||
|
||||
@ -11,7 +11,6 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.expr.*;
|
||||
|
||||
|
||||
@ -11,13 +11,7 @@ import java.util.HashSet;
|
||||
|
||||
import com.mysema.query.types.Constant;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.PathMetadataFactory;
|
||||
import com.mysema.query.types.expr.*;
|
||||
import com.mysema.query.types.path.DatePath;
|
||||
import com.mysema.query.types.path.DateTimePath;
|
||||
import com.mysema.query.types.path.NumberPath;
|
||||
import com.mysema.query.types.path.StringPath;
|
||||
import com.mysema.query.types.path.TimePath;
|
||||
|
||||
/**
|
||||
* @author tiwe
|
||||
|
||||
Loading…
Reference in New Issue
Block a user