Skip to content

Commit 5cb900b

Browse files
Polishing.
Original Pull Request: #577
1 parent 008e1e2 commit 5cb900b

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/main/antora/modules/ROOT/pages/keyvalue/repository/map-repositories.adoc

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
= Map Repositories
33

44
Map repositories reside on top of the `KeyValueTemplate`.
5-
Using the default `SpelQueryCreator` allows deriving query and sort expressions from the given method name, as the following example shows:
5+
Using the default `PredicateQueryCreator` allows deriving query and sort expressions from the given method name, as the following example shows:
66

77
[source, java]
88
----
@@ -16,3 +16,10 @@ interface PersonRepository implements CrudRepository<Person, String> {
1616
List<Person> findByLastname(String lastname);
1717
}
1818
----
19+
20+
== Configuring the QueryEngine
21+
22+
It is possible to change the `QueryEngine` and use a custom one instead of the default.
23+
The `EnableMapRepositories` annotation allows to configure the by supplying a `QueryEngineFactory` as well as the `QueryCreator` via according attributes.
24+
Please mind that the `QueryEngine` needs to be able to process queries created by the configured `QueryCreator`.
25+

src/main/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected SpelExpression toPredicateExpression(PartTree tree) {
181181
case EXISTS:
182182
default:
183183
throw new InvalidDataAccessApiUsageException(
184-
String.format("Found invalid part '%s' in query", part.getType()));
184+
"Found invalid part '%s' in query".formatted(part.getType()));
185185
}
186186

187187
if (partIter.hasNext()) {

src/main/java/org/springframework/data/map/repository/config/MapRepositoryConfigurationExtension.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,19 @@ private static SortAccessor<?> getSortAccessor(RepositoryConfigurationSource sou
109109
Class<? extends QueryEngineFactory> queryEngineFactoryType = (Class<? extends QueryEngineFactory>) getAnnotationAttributes(
110110
source).get("queryEngineFactory");
111111

112-
if (queryEngineFactoryType != null && !queryEngineFactoryType.isInterface()) {
113-
114-
if (sortAccessor != null) {
115-
Constructor<? extends QueryEngineFactory> constructor = ClassUtils
116-
.getConstructorIfAvailable(queryEngineFactoryType, SortAccessor.class);
117-
if (constructor != null) {
118-
return BeanUtils.instantiateClass(constructor, sortAccessor).create();
119-
}
120-
}
112+
if(queryEngineFactoryType == null || queryEngineFactoryType.isInterface()) {
113+
return null;
114+
}
121115

122-
return BeanUtils.instantiateClass(queryEngineFactoryType).create();
116+
if (sortAccessor != null) {
117+
Constructor<? extends QueryEngineFactory> constructor = ClassUtils
118+
.getConstructorIfAvailable(queryEngineFactoryType, SortAccessor.class);
119+
if (constructor != null) {
120+
return BeanUtils.instantiateClass(constructor, sortAccessor).create();
121+
}
123122
}
124123

125-
return null;
124+
return BeanUtils.instantiateClass(queryEngineFactoryType).create();
126125
}
127126

128127
private static Map<String, Object> getAnnotationAttributes(RepositoryConfigurationSource source) {

0 commit comments

Comments
 (0)