use of com.querydsl.core.types.dsl.CollectionPathBase in project spring-data-commons by spring-projects.
the class PropertyPathInformation method reifyPath.
private static Path<?> reifyPath(EntityPathResolver resolver, PropertyPath path, Optional<Path<?>> base) {
Optional<Path<?>> map = //
base.filter(it -> it instanceof CollectionPathBase).map(CollectionPathBase.class::cast).map(//
CollectionPathBase::any).map(//
Path.class::cast).map(it -> reifyPath(resolver, path, Optional.of(it)));
return map.orElseGet(() -> {
Path<?> entityPath = base.orElseGet(() -> resolver.createPath(path.getOwningType().getType()));
Field field = org.springframework.data.util.ReflectionUtils.findRequiredField(entityPath.getClass(), path.getSegment());
Object value = ReflectionUtils.getField(field, entityPath);
PropertyPath next = path.next();
if (next != null) {
return reifyPath(resolver, next, Optional.of((Path<?>) value));
}
return (Path<?>) value;
});
}
use of com.querydsl.core.types.dsl.CollectionPathBase in project spring-data-commons by spring-projects.
the class QuerydslDefaultBinding method bind.
/*
* (non-Javadoc)
* @see org.springframework.data.web.querydsl.QueryDslPredicateBuilder#buildPredicate(org.springframework.data.mapping.PropertyPath, java.lang.Object)
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Optional<Predicate> bind(Path<?> path, Collection<? extends Object> value) {
Assert.notNull(path, "Path must not be null!");
Assert.notNull(value, "Value must not be null!");
if (value.isEmpty()) {
return Optional.empty();
}
if (path instanceof CollectionPathBase) {
BooleanBuilder builder = new BooleanBuilder();
for (Object element : value) {
builder.and(((CollectionPathBase) path).contains(element));
}
return Optional.of(builder.getValue());
}
if (path instanceof SimpleExpression) {
if (value.size() > 1) {
return Optional.of(((SimpleExpression) path).in(value));
}
return Optional.of(((SimpleExpression) path).eq(value.iterator().next()));
}
throw new IllegalArgumentException(String.format("Cannot create predicate for path '%s' with type '%s'.", path, path.getMetadata().getPathType()));
}
Aggregations