Skip to content

Commit 027e422

Browse files
GH-2032 - Remove duplicated documentation.
1 parent 041bd05 commit 027e422

File tree

2 files changed

+3
-68
lines changed

2 files changed

+3
-68
lines changed

src/main/asciidoc/appendix/custom-queries.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Those come in handy if you cannot express the finder logic via derived query fun
66

77
Because Spring Data Neo4j works heavily record-oriented under the hood, it is important to keep this in mind and not build up a result set with multiple records for the same "root node".
88

9+
TIP: Please have a look in the FAQ as well to learn about alternative forms of using custom queries from repositories, especially
10+
how to use custom queries with custom mappings: <<faq.custom-queries-and-custom-mappings>>.
11+
912
[[custom-queries.for-relationships]]
1013
== Queries with relationships
1114

src/main/asciidoc/faq/faq.adoc

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -379,74 +379,6 @@ One way to do this is shown in <<domain-results>>.
379379

380380
To use this base repository for all declared repositories enable Neo4j repositories with: `@EnableNeo4jRepositories(repositoryBaseClass = MyRepositoryImpl.class)`.
381381

382-
[[faq.spel.custom-query]]
383-
== How do I use Spring Expression Language in custom queries?
384-
385-
{spring-framework-ref}/core.html#expressions[Spring Expression Language (SpEL)] can be used in custom queries inside `:#{}`.
386-
This is the standard Spring Data way of defining a block of text inside a query that undergoes SpEL evaluation.
387-
388-
The following example basically defines the same query as above, but uses a `WHERE` clause to avoid even more curly braces:
389-
390-
[source,java,indent=0]
391-
[[custom-queries-with-spel]]
392-
.ARepository.java
393-
----
394-
include::../../../../src/test/java/org/springframework/data/neo4j/documentation/repositories/domain_events/ARepository.java[tags=spel]
395-
----
396-
397-
The SpEL blocked starts with `:#{` and than refers to the given `String` parameters by name (`#pt1`).
398-
Don't confuse this with the above Cypher syntax!
399-
The SpEL expression concatenates both parameters into one single value that is eventually passed on to the <<neo4j-client>>.
400-
The SpEL block ends with `}`.
401-
402-
SpEL also solves two additional problems. We provide two extensions that allow to pass in a `Sort` object into custom queries.
403-
Remember <<custom-queries-with-page-and-slice-examples>> from <<faq.custom-queries,custom queries>>?
404-
With the `orderBy` extension you can pass in a `Pageable` with a dynamic sort to a custom query:
405-
406-
[[custom-queries-with-spel-extensions]]
407-
[source,java]
408-
.orderBy-Extension
409-
----
410-
import org.springframework.data.domain.Pageable;
411-
import org.springframework.data.domain.Sort;
412-
import org.springframework.data.neo4j.repository.Neo4jRepository;
413-
import org.springframework.data.neo4j.repository.query.Query;
414-
415-
public interface MyPersonRepository extends Neo4jRepository<Person, Long> {
416-
417-
@Query(""
418-
+ "MATCH (n:Person) WHERE n.name = $name RETURN n "
419-
+ ":#{orderBy(#pageable)} SKIP $skip LIMIT $limit" // <.>
420-
)
421-
Slice<Person> findSliceByName(String name, Pageable pageable);
422-
423-
@Query(""
424-
+ "MATCH (n:Person) WHERE n.name = $name RETURN n :#{orderBy(#sort)}" // <.>
425-
)
426-
List<Person> findAllByName(String name, Sort sort);
427-
}
428-
----
429-
<.> A `Pageable` has always the name `pageable` inside the SpEL context.
430-
<.> A `Sort` has always the name `sort` inside the SpEL context.
431-
432-
The `literal` extension can be used to make things like labels or relationship-types "dynamic" in custom queries.
433-
Neither labels nor relationship types can be parameterized in Cypher, so they must be given literal.
434-
435-
[source,java]
436-
.literal-Extension
437-
----
438-
interface BaseClassRepository extends Neo4jRepository<BaseClass, Long> {
439-
440-
@Query("MATCH (n:`:#{literal(#label)}`) RETURN n") // <.>
441-
List<Inheritance.BaseClass> findByLabel(String label);
442-
}
443-
----
444-
<.> The `literal` extension will be replaced with the literal value of the evaluate parameter.
445-
Here it has been used to match dynamically on a Label.
446-
If you pass in `SomeLabel` as a parameter to the method, `MATCH (n:``SomeLabel``) RETURN n`
447-
will be generated. Ticks have been added to correctly escape values. SDN won't do this
448-
for you as this is probably not what you want in all cases.
449-
450382
[[faq.entities.auditing]]
451383
== How do I audit entities?
452384

0 commit comments

Comments
 (0)