From 6ee5f5915323ab656c93fc1472fd7dc057dee56a Mon Sep 17 00:00:00 2001 From: Gerrit Meier Date: Fri, 4 Feb 2022 14:05:26 +0100 Subject: [PATCH] GH-2472 - Reference projection chapter from migration. Closes #2472 --- README.adoc | 4 +-- etc/adr/general-discussion.adoc | 2 +- src/main/asciidoc/appendix/migrating.adoc | 7 ++++-- src/main/asciidoc/appendix/neo4j-client.adoc | 25 +++++++++++++++++++ src/main/asciidoc/faq/faq.adoc | 2 +- .../getting-started/getting-started.adoc | 10 ++++---- .../introduction-and-preface/preface.adoc | 2 +- src/main/asciidoc/object-mapping/mapping.adoc | 2 ++ src/main/asciidoc/testing/testing.adoc | 8 +++--- 9 files changed, 46 insertions(+), 16 deletions(-) diff --git a/README.adoc b/README.adoc index 305bcd803..3dd4d6955 100644 --- a/README.adoc +++ b/README.adoc @@ -10,8 +10,8 @@ image:https://spring.io/badges/spring-data-neo4j/ga.svg[Spring Data Neo4j,link=h :artifactIdStarter: spring-boot-starter-data-neo4j :neo4j-version: 4.1.5 -:spring-boot-version: 2.5.3 -:spring-data-neo4j-version: 6.1.3 +:spring-boot-version: 2.6.3 +:spring-data-neo4j-version: 6.2.1 // end::properties[] [abstract] diff --git a/etc/adr/general-discussion.adoc b/etc/adr/general-discussion.adoc index 102accb5c..7bab300e0 100644 --- a/etc/adr/general-discussion.adoc +++ b/etc/adr/general-discussion.adoc @@ -318,7 +318,7 @@ Thus we stay consistent with all other Spring Boot starters, that are actually p ==== Responsibilities -The starter and it's automatic configuration is responsible for configuring Spring Data Neo4j repositories and infrastructure. +The starter and its automatic configuration is responsible for configuring Spring Data Neo4j repositories and infrastructure. It needs a configured Neo4j Java Driver and therefor is itself dependent on `org.neo4j.driver:neo4j-java-driver-spring-boot-starter`, the official starter for the Neo4j Java Driver. diff --git a/src/main/asciidoc/appendix/migrating.adoc b/src/main/asciidoc/appendix/migrating.adoc index f1c944c79..a924b48e0 100644 --- a/src/main/asciidoc/appendix/migrating.adoc +++ b/src/main/asciidoc/appendix/migrating.adoc @@ -124,18 +124,21 @@ You're then ready to replace annotations: |`org.springframework.data.neo4j.annotation.UseBookmark` |No replacement, not needed +|`org.springframework.data.neo4j.annotation.QueryResult` +|Use <>; arbitrary result mapping not supported anymore + |=== NOTE: Several Neo4j-OGM annotations have not yet a corresponding annotation in SDN, some will never have. We will add to the list above as we support additional features. [[migrating.bookmarks]] -=== Bookmarkmanagement +=== Bookmark management Both `@EnableBookmarkManagement` and `@UseBookmark` as well as the `org.springframework.data.neo4j.bookmark.BookmarkManager` interface and its only implementation `org.springframework.data.neo4j.bookmark.CaffeineBookmarkManager` are gone and are not needed anymore. -SDN uses Bookmarks for all transactions, without configuration. +SDN uses bookmarks for all transactions, without configuration. You can remove the bean declaration of `CaffeineBookmarkManager` as well as the dependency to `com.github.ben-manes.caffeine:caffeine`. [[migrating.autoindex]] diff --git a/src/main/asciidoc/appendix/neo4j-client.adoc b/src/main/asciidoc/appendix/neo4j-client.adoc index d47b16e7b..b4525fcb8 100644 --- a/src/main/asciidoc/appendix/neo4j-client.adoc +++ b/src/main/asciidoc/appendix/neo4j-client.adoc @@ -317,6 +317,31 @@ Mono lily = client `TypeSystem` gives access to the types the underlying Java driver used to fill the record. +[[neo4j-client.result-objects.mapping-functions]] +==== Using domain-aware mapping functions + +If you know that the result of the query will contain nodes that have entity definitions in your application, +you can use the injectable `MappingContext` to retrieve their mapping functions and apply them during the mapping. + +[[neo4j-client-reader.mapping-function]] +[source,java] +.Using an existing mapping function +---- +BiFunction mappingFunction = neo4jMappingContext.getRequiredMappingFunctionFor(Movie.class); +Mono lily = client + .query("" + + " MATCH (p:Person {name: $name}) - [:DIRECTED] -> (m:Movie)" + + "RETURN p, collect(m) as movies") + .bind("Lilly Wachowski").to("name") + .fetchAs(Director.class).mappedBy((TypeSystem t, Record record) -> { + List movies = record.get("movies") + .asList(movie -> mappingFunction.apply(t, movie)); + return new Director(record.get("name").asString(), movies); + }) + .one(); +---- + + [[neo4j-client.interacting.driver.directly]] === Interacting directly with the driver while using managed transactions diff --git a/src/main/asciidoc/faq/faq.adoc b/src/main/asciidoc/faq/faq.adoc index e94e0829b..2572b53b6 100644 --- a/src/main/asciidoc/faq/faq.adoc +++ b/src/main/asciidoc/faq/faq.adoc @@ -12,7 +12,7 @@ release. While patch versions of the Neo4j Java Driver are usually drop-in replacements, SDN6 makes sure that even minor versions are interchangeable as it checks for the presence or absence of methods or interface changes if necessary. -Therefore, you are able to use any 4.x Neo4j Java Driver with any SDN6 6.x version. +Therefore, you are able to use any 4.x Neo4j Java Driver with any SDN 6.x version. === With Spring Boot diff --git a/src/main/asciidoc/getting-started/getting-started.adoc b/src/main/asciidoc/getting-started/getting-started.adoc index 8a47dfae5..9187a76c8 100644 --- a/src/main/asciidoc/getting-started/getting-started.adoc +++ b/src/main/asciidoc/getting-started/getting-started.adoc @@ -2,10 +2,10 @@ = Getting started We provide a Spring Boot starter for SDN. -Please include the starter module via your dependency management and configure the bolt URL to use, for example `org.neo4j.driver.uri=bolt://localhost:7687`. +Please include the starter module via your dependency management and configure the bolt URL to use, for example `spring.neo4j.uri=bolt://localhost:7687`. The starter assumes that the server has disabled authentication. As the SDN starter depends on the starter for the Java Driver, all things regarding configuration said there, apply here as well. -For a reference of the available properties, use your IDEs autocompletion in the `org.neo4j.driver` namespace or look at the link:{java-driver-starter-href}/blob/master/docs/manual/index.adoc[dedicated manual]. +For a reference of the available properties, use your IDEs autocompletion in the `spring.neo4j` namespace. SDN supports @@ -13,7 +13,7 @@ SDN supports * Reactive programming based on https://www.reactive-streams.org[Reactive Streams], including full support for https://spring.io/blog/2019/05/16/reactive-transactions-with-spring[reactive transactions]. Those are all included in the same binary. -The reactive programming model requires a 4.0 Neo4j server on the database side and reactive Spring on the other hand. +The reactive programming model requires a 4+ Neo4j server on the database side and reactive Spring on the other hand. [[prepare-the-database]] == Prepare the database @@ -53,7 +53,7 @@ You can issue a _curl_ request against the Spring Initializer to create a basic .Create a basic Maven project with the Spring Initializr ---- curl https://start.spring.io/starter.tgz \ - -d dependencies=webflux,actuator,data-neo4j \ + -d dependencies=webflux,data-neo4j \ -d bootVersion={spring-boot-version} \ -d baseDir=Neo4jSpringBootExample \ -d name=Neo4j%20SpringBoot%20Example | tar -xzvf - @@ -84,7 +84,7 @@ The idea is the same, just generate a Gradle project: .Create a basic Gradle project with the Spring Initializr ---- curl https://start.spring.io/starter.tgz \ - -d dependencies=webflux,actuator,data-neo4j \ + -d dependencies=webflux,data-neo4j \ -d type=gradle-project \ -d bootVersion={spring-boot-version} \ -d baseDir=Neo4jSpringBootExampleGradle \ diff --git a/src/main/asciidoc/introduction-and-preface/preface.adoc b/src/main/asciidoc/introduction-and-preface/preface.adoc index bdd6ed7ff..044650da0 100644 --- a/src/main/asciidoc/introduction-and-preface/preface.adoc +++ b/src/main/asciidoc/introduction-and-preface/preface.adoc @@ -115,7 +115,7 @@ No. An embedded database is usually represented by an instance of `org.neo4j.graphdb.GraphDatabaseService` and has no Bolt connector out of the box. SDN can however work very much with Neo4j's test harness, the test harness is specially meant to be a drop-in replacement for the real database. -Support for both Neo4j 3.5 and 4.0 test harness is implemented via link:{java-driver-starter-href}[the Spring Boot starter for the driver]. +Support for both Neo4j 3.5 and 4.x test harness is implemented via link:{java-driver-starter-href}[the Spring Boot starter for the driver]. Have a look at the corresponding module `org.neo4j.driver:neo4j-java-driver-test-harness-spring-boot-autoconfigure`. [[sdn-without-spring-boot]] diff --git a/src/main/asciidoc/object-mapping/mapping.adoc b/src/main/asciidoc/object-mapping/mapping.adoc index f213c60c2..cfe9a9eac 100644 --- a/src/main/asciidoc/object-mapping/mapping.adoc +++ b/src/main/asciidoc/object-mapping/mapping.adoc @@ -287,6 +287,8 @@ We see the `MovieEntity` as the aggregate root, owning the relationships. On the other hand, we want to be able to pull all people from the database without selecting all the movies associated with them. Please consider your application's use case before you try to map every relationship in your database in every direction. While you can do this, you may end up rebuilding a graph database inside your object graph and this is not the intention of a mapping framework. +If you have to model your circular or bidirectional domain and don't want to fetch the whole graph, +you can define a fine-grained description of the data that you want to fetch by using <>. [[mapping.id-handling]] == Handling and provisioning of unique IDs diff --git a/src/main/asciidoc/testing/testing.adoc b/src/main/asciidoc/testing/testing.adoc index f6f5020b2..d19d76b3d 100644 --- a/src/main/asciidoc/testing/testing.adoc +++ b/src/main/asciidoc/testing/testing.adoc @@ -105,7 +105,7 @@ Also, 4.0 requires JDK 11. You need the following dependencies to run <>: [source,xml] -.Neo4j 4.0 test harness dependencies +.Neo4j 3.5 test harness dependencies ---- org.neo4j.test @@ -179,12 +179,12 @@ application properties. We overwrite the corresponding Neo4j settings. <.> Shutdown Neo4j after all tests. [[dataneo4jtest-harness40]] -=== `@DataNeo4jTest` with Neo4j test harness 4.0+ +=== `@DataNeo4jTest` with Neo4j test harness 4.x You need the following dependencies to run <>: [source,xml] -.Neo4j 4.0 test harness dependencies +.Neo4j 4.x test harness dependencies ---- org.neo4j.test @@ -205,7 +205,7 @@ an appropriate repository configuration. [[dataneo4jtest-harness40-example]] [source,java] -.Using Neo4j 4.0+ test harness +.Using Neo4j 4.x test harness ---- import static org.assertj.core.api.Assertions.assertThat;