DATAKV-169 - Add support for IN keyword in derived queries.
We now support `In` keyword in derived finder methods (eg. `findByFirstnameIn(Collection<String> firstnames)`) when using SpEL based queries. Original pull request: #23.
This commit is contained in:
committed by
Mark Paluch
parent
979f3a33a8
commit
f67a66bf25
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,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.Part.IgnoreCaseType;
|
||||
import org.springframework.data.repository.query.parser.Part.Type;
|
||||
import org.springframework.data.repository.query.parser.PartTree;
|
||||
import org.springframework.data.repository.query.parser.PartTree.OrPart;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
@@ -107,8 +108,12 @@ public class SpelQueryCreator extends AbstractQueryCreator<KeyValueQuery<SpelExp
|
||||
for (Iterator<Part> partIter = orPart.iterator(); partIter.hasNext();) {
|
||||
|
||||
Part part = partIter.next();
|
||||
partBuilder.append("#it?.");
|
||||
partBuilder.append(part.getProperty().toDotPath().replace(".", "?."));
|
||||
|
||||
if(!requiresInverseLookup(part)) {
|
||||
|
||||
partBuilder.append("#it?.");
|
||||
partBuilder.append(part.getProperty().toDotPath().replace(".", "?."));
|
||||
}
|
||||
|
||||
// TODO: check if we can have caseinsensitive search
|
||||
if (!part.shouldIgnoreCase().equals(IgnoreCaseType.NEVER)) {
|
||||
@@ -173,6 +178,13 @@ public class SpelQueryCreator extends AbstractQueryCreator<KeyValueQuery<SpelExp
|
||||
partBuilder.append(" matches ").append("[").append(parameterIndex++).append("]");
|
||||
break;
|
||||
case IN:
|
||||
|
||||
partBuilder.append("[").append(parameterIndex++).append("].contains(");
|
||||
partBuilder.append("#it?.");
|
||||
partBuilder.append(part.getProperty().toDotPath().replace(".", "?."));
|
||||
partBuilder.append(")");
|
||||
break;
|
||||
|
||||
case CONTAINING:
|
||||
case NOT_CONTAINING:
|
||||
case NEGATING_SIMPLE_PROPERTY:
|
||||
@@ -202,4 +214,8 @@ public class SpelQueryCreator extends AbstractQueryCreator<KeyValueQuery<SpelExp
|
||||
|
||||
return PARSER.parseRaw(sb.toString());
|
||||
}
|
||||
|
||||
private static boolean requiresInverseLookup(Part part) {
|
||||
return part.getType() == Type.IN;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user