Skip to content

Commit 549cbd6

Browse files
Added docs
1 parent d31e50b commit 549cbd6

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/main/antora/modules/ROOT/pages/appendix/custom-queries.adoc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,11 @@ If an entity has a relationship with the same type to different types of others
367367
If you need such a mapping and also have the need to work with those custom parameters, you have to unroll it accordingly.
368368
One way to do this are correlated subqueries (Neo4j 4.1+ required).
369369

370+
[[custom-queries.expressions]]
371+
== Value Expressions in custom queries
372+
370373
[[custom-queries.spel]]
371-
== Spring Expression Language in custom queries
374+
=== Spring Expression Language in custom queries
372375

373376
{springdocsurl}/core/expressions.html[Spring Expression Language (SpEL)] can be used in custom queries inside `:#{}`.
374377
The colon here refers to a parameter and such an expression should be used where parameters make sense.
@@ -502,3 +505,18 @@ MATCH (n:`Bike`:`Gravel`:`Easy Trail`) WHERE n.id = $nameOrId OR n.name = $nameO
502505

503506
Notice how we used standard parameter for the `nameOrId`: In most cases there is no need to complicate things here by
504507
adding a SpEL expression.
508+
509+
510+
[[custom-queries.propertyplaceholder]]
511+
=== Property Placeholder resolution in custom queries
512+
513+
Spring's property placeholders can be used in custom queries inside `${}`.
514+
515+
[source,java,indent=0]
516+
[[custom-queries-with-property-placeholder-example]]
517+
.ARepository.java
518+
----
519+
include::example$documentation/repositories/domain_events/ARepository.java[tags=property-placeholder]
520+
----
521+
522+
In the example above, if the property `foo` would be set to `bar` then the `${foo}` block would be resolved to `bar`.

src/test/java/org/springframework/data/neo4j/documentation/repositories/domain_events/ARepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public interface ARepository extends Neo4jRepository<AnAggregateRoot, String> {
3636
Optional<AnAggregateRoot> findByCustomQuery(String name);
3737
// end::standard-parameter[]
3838

39+
// tag::property-placeholder[]
40+
@Query("MATCH (a:AnAggregateRoot) WHERE a.name = :${foo} RETURN a")
41+
Optional<AnAggregateRoot> findByCustomQueryWithPropertyPlaceholder();
42+
// end::property-placeholder[]
43+
3944
// tag::spel[]
4045
@Query("MATCH (a:AnAggregateRoot) WHERE a.name = :#{#pt1 + #pt2} RETURN a")
4146
Optional<AnAggregateRoot> findByCustomQueryWithSpEL(String pt1, String pt2);

src/test/java/org/springframework/data/neo4j/documentation/repositories/domain_events/DomainEventsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import org.junit.jupiter.api.Disabled;
2323
import org.junit.jupiter.api.Test;
2424
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.test.context.TestPropertySource;
2526

2627
/**
2728
* Basic tests for domain events (and documentation).
2829
*/
2930
@Disabled
31+
@TestPropertySource("foo=The Root")
3032
// tag::domain-events[]
3133
public class DomainEventsTest {
3234

@@ -57,6 +59,9 @@ void customQueryShouldWork() {
5759

5860
optionalAggregate = aRepository.findByCustomQueryWithSpEL("The ", "Root");
5961
assertThat(optionalAggregate).isPresent();
62+
63+
optionalAggregate = aRepository.findByCustomQueryWithPropertyPlaceholder();
64+
assertThat(optionalAggregate).isPresent();
6065
}
6166

6267
// tag::domain-events[]

0 commit comments

Comments
 (0)