committed by
Mark Paluch
parent
803fd7101e
commit
6190b3bff6
@@ -29,6 +29,7 @@ import org.springframework.data.repository.query.ParameterAccessor;
|
||||
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||
import org.springframework.data.repository.query.parser.Part;
|
||||
import org.springframework.data.repository.query.parser.PartTree;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
@@ -37,6 +38,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
* @author Junghoon Ban
|
||||
* @since 1.7
|
||||
*/
|
||||
public class RedisQueryCreator extends AbstractQueryCreator<KeyValueQuery<RedisOperationChain>, RedisOperationChain> {
|
||||
@@ -78,16 +80,16 @@ public class RedisQueryCreator extends AbstractQueryCreator<KeyValueQuery<RedisO
|
||||
}
|
||||
|
||||
@Override
|
||||
protected KeyValueQuery<RedisOperationChain> complete(final RedisOperationChain criteria, Sort sort) {
|
||||
protected KeyValueQuery<RedisOperationChain> complete(@Nullable final RedisOperationChain criteria, Sort sort) {
|
||||
|
||||
KeyValueQuery<RedisOperationChain> query = new KeyValueQuery<>(criteria);
|
||||
|
||||
if (query.getCriteria() != null && !CollectionUtils.isEmpty(query.getCriteria().getSismember())
|
||||
&& !CollectionUtils.isEmpty(query.getCriteria().getOrSismember()))
|
||||
if (query.getCriteria().getSismember().size() == 1 && query.getCriteria().getOrSismember().size() == 1) {
|
||||
if (criteria != null && !CollectionUtils.isEmpty(criteria.getSismember())
|
||||
&& !CollectionUtils.isEmpty(criteria.getOrSismember()))
|
||||
if (criteria.getSismember().size() == 1 && criteria.getOrSismember().size() == 1) {
|
||||
|
||||
query.getCriteria().getOrSismember().add(query.getCriteria().getSismember().iterator().next());
|
||||
query.getCriteria().getSismember().clear();
|
||||
criteria.getOrSismember().add(criteria.getSismember().iterator().next());
|
||||
criteria.getSismember().clear();
|
||||
}
|
||||
|
||||
if (sort.isSorted()) {
|
||||
@@ -99,43 +101,39 @@ public class RedisQueryCreator extends AbstractQueryCreator<KeyValueQuery<RedisO
|
||||
|
||||
private NearPath getNearPath(Part part, Iterator<Object> iterator) {
|
||||
|
||||
String path = part.getProperty().toDotPath();
|
||||
Object value = iterator.next();
|
||||
|
||||
Point point;
|
||||
Distance distance;
|
||||
if (value instanceof Circle circle) {
|
||||
return new NearPath(path, circle.getCenter(), circle.getRadius());
|
||||
}
|
||||
|
||||
if (value instanceof Circle) {
|
||||
point = ((Circle) value).getCenter();
|
||||
distance = ((Circle) value).getRadius();
|
||||
} else if (value instanceof Point) {
|
||||
|
||||
point = (Point) value;
|
||||
if (value instanceof Point point) {
|
||||
|
||||
if (!iterator.hasNext()) {
|
||||
String message = "Expected to find distance value for geo query; Are you missing a parameter";
|
||||
throw new InvalidDataAccessApiUsageException(message);
|
||||
}
|
||||
|
||||
Distance distance;
|
||||
Object distObject = iterator.next();
|
||||
if (distObject instanceof Distance) {
|
||||
distance = (Distance) distObject;
|
||||
} else if (distObject instanceof Number) {
|
||||
distance = new Distance(((Number) distObject).doubleValue(), Metrics.KILOMETERS);
|
||||
|
||||
if (distObject instanceof Distance distanceValue) {
|
||||
distance = distanceValue;
|
||||
} else if (distObject instanceof Number numberValue) {
|
||||
distance = new Distance(numberValue.doubleValue(), Metrics.KILOMETERS);
|
||||
} else {
|
||||
|
||||
String message = String.format("Expected to find Distance or Numeric value for geo query but was %s",
|
||||
distObject.getClass());
|
||||
|
||||
throw new InvalidDataAccessApiUsageException(message);
|
||||
}
|
||||
} else {
|
||||
|
||||
String message = String.format("Expected to find a Circle or Point/Distance for geo query but was %s.",
|
||||
value.getClass());
|
||||
|
||||
throw new InvalidDataAccessApiUsageException(message);
|
||||
return new NearPath(path, point, distance);
|
||||
}
|
||||
|
||||
return new NearPath(part.getProperty().toDotPath(), point, distance);
|
||||
String message = String.format("Expected to find a Circle or Point/Distance for geo query but was %s.",
|
||||
value.getClass());
|
||||
throw new InvalidDataAccessApiUsageException(message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user