@@ -41,7 +41,7 @@ public class Examples
4141 public static Driver constructDriver () throws Exception
4242 {
4343 // tag::construct-driver[]
44- Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ("neo4j" , "neo4j" ) );
44+ Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ( "neo4j" , "neo4j" ) );
4545 // end::construct-driver[]
4646
4747 return driver ;
@@ -52,7 +52,7 @@ public static Driver configuration() throws Exception
5252 // tag::configuration[]
5353 Driver driver = GraphDatabase .driver (
5454 "bolt://localhost:7687" ,
55- AuthTokens .basic ("neo4j" , "neo4j" ),
55+ AuthTokens .basic ( "neo4j" , "neo4j" ),
5656 Config .build ().withMaxSessions ( 10 ).toConfig () );
5757 // end::configuration[]
5858
@@ -72,7 +72,7 @@ public static void statement( Session session ) throws Exception
7272 public static void statementWithoutParameters ( Session session ) throws Exception
7373 {
7474 // tag::statement-without-parameters[]
75- StatementResult result = session .run ( "CREATE (p:Person { name: 'Arthur' })" );
75+ StatementResult result = session .run ( "CREATE (p:Person {name: 'Arthur'})" );
7676 // end::statement-without-parameters[]
7777 int theOnesCreated = result .consume ().counters ().nodesCreated ();
7878 System .out .println ( "There were " + theOnesCreated + " the ones created." );
@@ -82,14 +82,15 @@ public static void resultTraversal( Session session ) throws Exception
8282 {
8383 // tag::result-traversal[]
8484 String searchTerm = "Sword" ;
85- StatementResult result = session .run ( "MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} RETURN weapon.name" ,
86- Values .parameters ( "term" , searchTerm ) );
85+ StatementResult result =
86+ session .run ( "MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} RETURN weapon.name" ,
87+ Values .parameters ( "term" , searchTerm ) );
8788
88- System .out .println ("List of weapons called " + searchTerm + ":" );
89+ System .out .println ( "List of weapons called " + searchTerm + ":" );
8990 while ( result .hasNext () )
9091 {
9192 Record record = result .next ();
92- System .out .println (record .get ("weapon.name" ).asString ());
93+ System .out .println ( record .get ( "weapon.name" ).asString () );
9394 }
9495 // end::result-traversal[]
9596 }
@@ -98,34 +99,36 @@ public static void accessRecord( Session session ) throws Exception
9899 {
99100 // tag::access-record[]
100101 String searchTerm = "Arthur" ;
101- StatementResult result = session .run ( "MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} RETURN weapon.name, weapon.material, weapon.size" ,
102+ StatementResult result = session .run ( "MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} " +
103+ "RETURN weapon.name, weapon.material, weapon.size" ,
102104 Values .parameters ( "term" , searchTerm ) );
103105
104- System .out .println ("List of weapons owned by " + searchTerm + ":" );
106+ System .out .println ( "List of weapons owned by " + searchTerm + ":" );
105107 while ( result .hasNext () )
106108 {
107109 Record record = result .next ();
108110 List <String > sword = new ArrayList <>();
109111 for ( String key : record .keys () )
110112 {
111- sword .add ( key + ": " + record .get (key ) );
113+ sword .add ( key + ": " + record .get ( key ) );
112114 }
113- System .out .println (sword );
115+ System .out .println ( sword );
114116 }
115117 // end::access-record[]
116118 }
117119
118120 public static void retainResultsForNestedQuerying ( Session session ) throws Exception
119121 {
120122 // tag::nested-statements[]
121- StatementResult result = session .run ( "MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN id(knight) AS knight_id" ,
123+ StatementResult result = session .run (
124+ "MATCH (knight:Person:Knight) WHERE knight.castle = {castle} RETURN id(knight) AS knight_id" ,
122125 Values .parameters ( "castle" , "Camelot" ) );
123126
124127 for ( Record record : result .list () )
125128 {
126129 session .run ( "MATCH (knight) WHERE id(knight) = {id} " +
127- "MATCH (king:Person) WHERE king.name = {king} " +
128- "CREATE (knight)-[:DEFENDS]->(king)" ,
130+ "MATCH (king:Person) WHERE king.name = {king} " +
131+ "CREATE (knight)-[:DEFENDS]->(king)" ,
129132 Values .parameters ( "id" , record .get ( "knight_id" ), "king" , "Arthur" ) );
130133 }
131134 // end::nested-statements[]
@@ -160,7 +163,7 @@ public static void handleCypherError( Session session ) throws Exception
160163 }
161164 catch ( ClientException e )
162165 {
163- throw new RuntimeException ("Something really bad has happened!" );
166+ throw new RuntimeException ( "Something really bad has happened!" );
164167 }
165168 // end::handle-cypher-error[]
166169 }
@@ -170,7 +173,8 @@ public static void transactionCommit( Session session ) throws Exception
170173 // tag::transaction-commit[]
171174 try ( Transaction tx = session .beginTransaction () )
172175 {
173- tx .run ( "CREATE (:Person {name: 'Guinevere'})" );
176+ tx .run ( "CREATE (:Person {name: {name}})" ,
177+ Values .parameters ( "name" , "Guinevere" ) );
174178 tx .success ();
175179 }
176180 // end::transaction-commit[]
@@ -181,7 +185,8 @@ public static void transactionRollback( Session session ) throws Exception
181185 // tag::transaction-rollback[]
182186 try ( Transaction tx = session .beginTransaction () )
183187 {
184- tx .run ( "CREATE (:Person {name: 'Merlin'})" );
188+ tx .run ( "CREATE (:Person {name: {name}})" ,
189+ Values .parameters ( "name" , "Merlin" ) );
185190 tx .failure ();
186191 }
187192 // end::transaction-rollback[]
@@ -190,7 +195,7 @@ public static void transactionRollback( Session session ) throws Exception
190195 public static void resultSummary ( Session session ) throws Exception
191196 {
192197 // tag::result-summary-query-profile[]
193- StatementResult result = session .run ( "PROFILE MATCH (p:Person { name: {name} }) RETURN id(p)" ,
198+ StatementResult result = session .run ( "PROFILE MATCH (p:Person {name: {name}}) RETURN id(p)" ,
194199 Values .parameters ( "name" , "Arthur" ) );
195200
196201 ResultSummary summary = result .consume ();
@@ -215,7 +220,7 @@ public static void notifications( Session session ) throws Exception
215220 public static Driver requireEncryption () throws Exception
216221 {
217222 // tag::tls-require-encryption[]
218- Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ("neo4j" , "neo4j" ),
223+ Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ( "neo4j" , "neo4j" ),
219224 Config .build ().withEncryptionLevel ( Config .EncryptionLevel .REQUIRED ).toConfig () );
220225 // end::tls-require-encryption[]
221226
@@ -225,7 +230,7 @@ public static Driver requireEncryption() throws Exception
225230 public static Driver trustOnFirstUse () throws Exception
226231 {
227232 // tag::tls-trust-on-first-use[]
228- Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ("neo4j" , "neo4j" ), Config .build ()
233+ Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ( "neo4j" , "neo4j" ), Config .build ()
229234 .withEncryptionLevel ( Config .EncryptionLevel .REQUIRED )
230235 .withTrustStrategy ( Config .TrustStrategy .trustOnFirstUse ( new File ( "/path/to/neo4j_known_hosts" ) ) )
231236 .toConfig () );
@@ -237,9 +242,9 @@ public static Driver trustOnFirstUse() throws Exception
237242 public static Driver trustSignedCertificates () throws Exception
238243 {
239244 // tag::tls-signed[]
240- Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ("neo4j" , "neo4j" ), Config .build ()
245+ Driver driver = GraphDatabase .driver ( "bolt://localhost:7687" , AuthTokens .basic ( "neo4j" , "neo4j" ), Config .build ()
241246 .withEncryptionLevel ( Config .EncryptionLevel .REQUIRED )
242- .withTrustStrategy ( Config .TrustStrategy .trustCustomCertificateSignedBy ( new File ( "/path/to/ca-certificate.pem" ) ) )
247+ .withTrustStrategy ( Config .TrustStrategy .trustCustomCertificateSignedBy ( new File ( "/path/to/ca-certificate.pem" ) ) )
243248 .toConfig () );
244249 // end::tls-signed[]
245250
0 commit comments