Skip to content

Commit 91b57a0

Browse files
GH-2182 - Polishing.
1 parent f470690 commit 91b57a0

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

src/main/java/org/springframework/data/neo4j/core/FluentFindOperation.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ interface FindWithQuery<T> extends TerminatingFindWithoutQuery<T> {
101101
* Set the filter query to be used.
102102
*
103103
* @param query must not be {@literal null}.
104+
* @param parameter Optional parameter map
104105
* @return new instance of {@link TerminatingFind}.
105106
* @throws IllegalArgumentException if query is {@literal null}.
106107
*/
107-
TerminatingFind<T> matching(String query, Map<String, Object> parameter);
108+
TerminatingFind<T> matching(String query, @Nullable Map<String, Object> parameter);
108109

109110
/**
110111
* Set the filter query to be used.
@@ -125,10 +126,12 @@ default TerminatingFind<T> matching(String query) {
125126
* @return new instance of {@link TerminatingFind}.
126127
* @throws IllegalArgumentException if statement is {@literal null}.
127128
*/
128-
default TerminatingFind<T> matching(Statement statement, Map<String, Object> parameter) {
129+
default TerminatingFind<T> matching(Statement statement, @Nullable Map<String, Object> parameter) {
129130
Map<String, Object> mergedParameters = new HashMap<>();
130131
mergedParameters.putAll(statement.getParameters());
131-
mergedParameters.putAll(parameter);
132+
if (parameter != null) {
133+
mergedParameters.putAll(parameter);
134+
}
132135
return matching(statement.getCypher(), mergedParameters);
133136
}
134137

src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ public <T, R> R saveAs(T instance, Class<R> resultType) {
301301
return (R) save(instance);
302302
}
303303

304-
ProjectionInformation pi = projectionFactory.getProjectionInformation(resultType);
305-
T savedInstance = saveImpl(instance, pi.getInputProperties());
306-
if (pi.isClosed()) {
304+
ProjectionInformation projectionInformation = projectionFactory.getProjectionInformation(resultType);
305+
T savedInstance = saveImpl(instance, projectionInformation.getInputProperties());
306+
if (projectionInformation.isClosed()) {
307307
return projectionFactory.createProjection(resultType, savedInstance);
308308
}
309309

@@ -323,12 +323,12 @@ private <T> T saveImpl(T instance, @Nullable List<PropertyDescriptor> includedPr
323323

324324
DynamicLabels dynamicLabels = determineDynamicLabels(entityToBeSaved, entityMetaData);
325325

326-
Function<T, Map<String, Object>> requiredBinderFunctionFor = neo4jMappingContext
326+
Function<T, Map<String, Object>> binderFunction = neo4jMappingContext
327327
.getRequiredBinderFunctionFor((Class<T>) entityToBeSaved.getClass());
328328

329329
Predicate<String> includeProperty = TemplateSupport.computeIncludePropertyPredicate(includedProperties);
330330
if (includedProperties != null) {
331-
requiredBinderFunctionFor = requiredBinderFunctionFor.andThen(tree -> {
331+
binderFunction = binderFunction.andThen(tree -> {
332332
Map<String, Object> properties = (Map<String, Object>) tree.get(Constants.NAME_OF_PROPERTIES_PARAM);
333333
properties.entrySet().removeIf(e -> !includeProperty.test(e.getKey()));
334334
return tree;
@@ -337,7 +337,7 @@ private <T> T saveImpl(T instance, @Nullable List<PropertyDescriptor> includedPr
337337
Optional<Long> optionalInternalId = neo4jClient
338338
.query(() -> renderer.render(cypherGenerator.prepareSaveOf(entityMetaData, dynamicLabels)))
339339
.bind(entityToBeSaved)
340-
.with(requiredBinderFunctionFor)
340+
.with(binderFunction)
341341
.fetchAs(Long.class).one();
342342

343343
if (entityMetaData.hasVersionProperty() && !optionalInternalId.isPresent()) {
@@ -451,10 +451,10 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
451451
return (List<R>) saveAll(instances);
452452
}
453453

454-
ProjectionInformation pi = projectionFactory.getProjectionInformation(resultType);
455-
List<T> savedInstances = saveAllImpl(instances, pi.getInputProperties());
454+
ProjectionInformation projectionInformation = projectionFactory.getProjectionInformation(resultType);
455+
List<T> savedInstances = saveAllImpl(instances, projectionInformation.getInputProperties());
456456

457-
if (pi.isClosed()) {
457+
if (projectionInformation.isClosed()) {
458458
return savedInstances.stream().map(instance -> projectionFactory.createProjection(resultType, instance))
459459
.collect(Collectors.toList());
460460
}

src/main/java/org/springframework/data/neo4j/core/ReactiveFluentFindOperation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.apiguardian.api.API;
2626
import org.neo4j.cypherdsl.core.Statement;
27+
import org.springframework.lang.Nullable;
2728

2829
/**
2930
* {@link ReactiveFluentFindOperation} allows creation and execution of Neo4j find operations in a fluent API style.
@@ -90,10 +91,11 @@ interface FindWithQuery<T> extends TerminatingFindWithoutQuery<T> {
9091
* Set the filter query to be used.
9192
*
9293
* @param query must not be {@literal null}.
94+
* @param parameter Optional parameter map
9395
* @return new instance of {@link TerminatingFind}.
9496
* @throws IllegalArgumentException if query is {@literal null}.
9597
*/
96-
TerminatingFind<T> matching(String query, Map<String, Object> parameter);
98+
TerminatingFind<T> matching(String query, @Nullable Map<String, Object> parameter);
9799

98100
/**
99101
* Set the filter query to be used.
@@ -114,10 +116,12 @@ default TerminatingFind<T> matching(String query) {
114116
* @return new instance of {@link TerminatingFind}.
115117
* @throws IllegalArgumentException if statement is {@literal null}.
116118
*/
117-
default TerminatingFind<T> matching(Statement statement, Map<String, Object> parameter) {
119+
default TerminatingFind<T> matching(Statement statement, @Nullable Map<String, Object> parameter) {
118120
Map<String, Object> mergedParameters = new HashMap<>();
119121
mergedParameters.putAll(statement.getParameters());
120-
mergedParameters.putAll(parameter);
122+
if (parameter != null) {
123+
mergedParameters.putAll(parameter);
124+
}
121125
return matching(statement.getCypher(), mergedParameters);
122126
}
123127

src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ public <T, R> Mono<R> saveAs(T instance, Class<R> resultType) {
288288
return (Mono<R>) save(instance);
289289
}
290290

291-
ProjectionInformation pi = projectionFactory.getProjectionInformation(resultType);
292-
Mono<T> savingPublisher = saveImpl(instance, pi.getInputProperties());
293-
if (pi.isClosed()) {
291+
ProjectionInformation projectionInformation = projectionFactory.getProjectionInformation(resultType);
292+
Mono<T> savingPublisher = saveImpl(instance, projectionInformation.getInputProperties());
293+
if (projectionInformation.isClosed()) {
294294
return savingPublisher.map(savedInstance -> projectionFactory.createProjection(resultType, savedInstance));
295295
}
296296

@@ -314,7 +314,7 @@ private <T> Mono<T> saveImpl(T instance, @Nullable List<PropertyDescriptor> incl
314314

315315
DynamicLabels dynamicLabels = t.getT2();
316316

317-
Function<T, Map<String, Object>> requiredBinderFunctionFor = neo4jMappingContext
317+
Function<T, Map<String, Object>> binderFunction = neo4jMappingContext
318318
.getRequiredBinderFunctionFor((Class<T>) entityToBeSaved.getClass());
319319

320320
Predicate<String> includeProperty;
@@ -323,15 +323,15 @@ private <T> Mono<T> saveImpl(T instance, @Nullable List<PropertyDescriptor> incl
323323
} else {
324324
Set<String> includedPropertyNames = includedProperties.stream().map(PropertyDescriptor::getName).collect(Collectors.toSet());
325325
includeProperty = includedPropertyNames::contains;
326-
requiredBinderFunctionFor = requiredBinderFunctionFor.andThen(tree -> {
326+
binderFunction = binderFunction.andThen(tree -> {
327327
Map<String, Object> properties = (Map<String, Object>) tree.get(Constants.NAME_OF_PROPERTIES_PARAM);
328328
properties.entrySet().removeIf(e -> !includeProperty.test(e.getKey()));
329329
return tree;
330330
});
331331
}
332332

333333
Mono<Long> idMono = this.neo4jClient.query(() -> renderer.render(cypherGenerator.prepareSaveOf(entityMetaData, dynamicLabels)))
334-
.bind(entityToBeSaved).with(requiredBinderFunctionFor)
334+
.bind(entityToBeSaved).with(binderFunction)
335335
.fetchAs(Long.class).one()
336336
.switchIfEmpty(Mono.defer(() -> {
337337
if (entityMetaData.hasVersionProperty()) {
@@ -388,9 +388,9 @@ public <T, R> Flux<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
388388
return (Flux<R>) saveAll(instances);
389389
}
390390

391-
ProjectionInformation pi = projectionFactory.getProjectionInformation(resultType);
392-
Flux<T> savedInstances = saveAllImpl(instances, pi.getInputProperties());
393-
if (pi.isClosed()) {
391+
ProjectionInformation projectionInformation = projectionFactory.getProjectionInformation(resultType);
392+
Flux<T> savedInstances = saveAllImpl(instances, projectionInformation.getInputProperties());
393+
if (projectionInformation.isClosed()) {
394394
return savedInstances.map(instance -> projectionFactory.createProjection(resultType, instance));
395395
}
396396

0 commit comments

Comments
 (0)