From 42c809cb852235d8920b201e2c5d6a8e765fdac1 Mon Sep 17 00:00:00 2001 From: martin bendsoe Date: Mon, 2 Dec 2019 12:26:24 +0100 Subject: [PATCH] Updated the SimpleExample The introduction of a Managed Transaction is now included in the example, and example code was tested against 4.0.0-rc. --- driver/src/main/javadoc/overview.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/driver/src/main/javadoc/overview.html b/driver/src/main/javadoc/overview.html index d067847d91..63b7176589 100644 --- a/driver/src/main/javadoc/overview.html +++ b/driver/src/main/javadoc/overview.html @@ -9,7 +9,7 @@

Example

-
import org.neo4j.driver.v1.*;
+
import org.neo4j.driver.*;
 
 import static org.neo4j.driver.Values.parameters;
 
@@ -28,13 +28,11 @@ 

Example

// Sessions are lightweight and disposable connection wrappers. try (Session session = driver.session()) { - // Wrapping Cypher in an unmanaged transaction provides atomicity + // Wrapping a Cypher Query in a Managed Transaction provides atomicity // and makes handling errors much easier. - try (Transaction tx = session.beginTransaction()) - { - tx.run("MERGE (a:Person {name: $x})", parameters("x", name)); - tx.success(); // Mark this write as successful. - } + // Use `session.writeTransaction` for writes and `session.readTransaction` for reading data. + // These methods are also able to handle connection problems and transient errors using an automatic retry mechanism. + session.writeTransaction(tx -> tx.run("MERGE (a:Person {name: $x})", parameters("x", name))); } } @@ -42,7 +40,9 @@

Example

{ try (Session session = driver.session()) { - // Auto-commit transactions are a quick and easy way to wrap a read. + // A Managed Transaction transactions are a quick and easy way to wrap a Cypher Query. + // The `session.run` method will run the specified Query. + // This simpler method does not use any automatic retry mechanism. Result result = session.run( "MATCH (a:Person) WHERE a.name STARTS WITH $x RETURN a.name AS name", parameters("x", initial));