@@ -41,7 +41,7 @@ public class Examples
41
41
public static Driver constructDriver () throws Exception
42
42
{
43
43
// 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" ) );
45
45
// end::construct-driver[]
46
46
47
47
return driver ;
@@ -52,7 +52,7 @@ public static Driver configuration() throws Exception
52
52
// tag::configuration[]
53
53
Driver driver = GraphDatabase .driver (
54
54
"bolt://localhost:7687" ,
55
- AuthTokens .basic ("neo4j" , "neo4j" ),
55
+ AuthTokens .basic ( "neo4j" , "neo4j" ),
56
56
Config .build ().withMaxSessions ( 10 ).toConfig () );
57
57
// end::configuration[]
58
58
@@ -72,7 +72,7 @@ public static void statement( Session session ) throws Exception
72
72
public static void statementWithoutParameters ( Session session ) throws Exception
73
73
{
74
74
// tag::statement-without-parameters[]
75
- StatementResult result = session .run ( "CREATE (p:Person { name: 'Arthur' })" );
75
+ StatementResult result = session .run ( "CREATE (p:Person {name: 'Arthur'})" );
76
76
// end::statement-without-parameters[]
77
77
int theOnesCreated = result .consume ().counters ().nodesCreated ();
78
78
System .out .println ( "There were " + theOnesCreated + " the ones created." );
@@ -82,14 +82,15 @@ public static void resultTraversal( Session session ) throws Exception
82
82
{
83
83
// tag::result-traversal[]
84
84
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 ) );
87
88
88
- System .out .println ("List of weapons called " + searchTerm + ":" );
89
+ System .out .println ( "List of weapons called " + searchTerm + ":" );
89
90
while ( result .hasNext () )
90
91
{
91
92
Record record = result .next ();
92
- System .out .println (record .get ("weapon.name" ).asString ());
93
+ System .out .println ( record .get ( "weapon.name" ).asString () );
93
94
}
94
95
// end::result-traversal[]
95
96
}
@@ -98,34 +99,36 @@ public static void accessRecord( Session session ) throws Exception
98
99
{
99
100
// tag::access-record[]
100
101
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" ,
102
104
Values .parameters ( "term" , searchTerm ) );
103
105
104
- System .out .println ("List of weapons owned by " + searchTerm + ":" );
106
+ System .out .println ( "List of weapons owned by " + searchTerm + ":" );
105
107
while ( result .hasNext () )
106
108
{
107
109
Record record = result .next ();
108
110
List <String > sword = new ArrayList <>();
109
111
for ( String key : record .keys () )
110
112
{
111
- sword .add ( key + ": " + record .get (key ) );
113
+ sword .add ( key + ": " + record .get ( key ) );
112
114
}
113
- System .out .println (sword );
115
+ System .out .println ( sword );
114
116
}
115
117
// end::access-record[]
116
118
}
117
119
118
120
public static void retainResultsForNestedQuerying ( Session session ) throws Exception
119
121
{
120
122
// 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" ,
122
125
Values .parameters ( "castle" , "Camelot" ) );
123
126
124
127
for ( Record record : result .list () )
125
128
{
126
129
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)" ,
129
132
Values .parameters ( "id" , record .get ( "knight_id" ), "king" , "Arthur" ) );
130
133
}
131
134
// end::nested-statements[]
@@ -160,7 +163,7 @@ public static void handleCypherError( Session session ) throws Exception
160
163
}
161
164
catch ( ClientException e )
162
165
{
163
- throw new RuntimeException ("Something really bad has happened!" );
166
+ throw new RuntimeException ( "Something really bad has happened!" );
164
167
}
165
168
// end::handle-cypher-error[]
166
169
}
@@ -170,7 +173,8 @@ public static void transactionCommit( Session session ) throws Exception
170
173
// tag::transaction-commit[]
171
174
try ( Transaction tx = session .beginTransaction () )
172
175
{
173
- tx .run ( "CREATE (:Person {name: 'Guinevere'})" );
176
+ tx .run ( "CREATE (:Person {name: {name}})" ,
177
+ Values .parameters ( "name" , "Guinevere" ) );
174
178
tx .success ();
175
179
}
176
180
// end::transaction-commit[]
@@ -181,7 +185,8 @@ public static void transactionRollback( Session session ) throws Exception
181
185
// tag::transaction-rollback[]
182
186
try ( Transaction tx = session .beginTransaction () )
183
187
{
184
- tx .run ( "CREATE (:Person {name: 'Merlin'})" );
188
+ tx .run ( "CREATE (:Person {name: {name}})" ,
189
+ Values .parameters ( "name" , "Merlin" ) );
185
190
tx .failure ();
186
191
}
187
192
// end::transaction-rollback[]
@@ -190,7 +195,7 @@ public static void transactionRollback( Session session ) throws Exception
190
195
public static void resultSummary ( Session session ) throws Exception
191
196
{
192
197
// 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)" ,
194
199
Values .parameters ( "name" , "Arthur" ) );
195
200
196
201
ResultSummary summary = result .consume ();
@@ -215,7 +220,7 @@ public static void notifications( Session session ) throws Exception
215
220
public static Driver requireEncryption () throws Exception
216
221
{
217
222
// 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" ),
219
224
Config .build ().withEncryptionLevel ( Config .EncryptionLevel .REQUIRED ).toConfig () );
220
225
// end::tls-require-encryption[]
221
226
@@ -225,7 +230,7 @@ public static Driver requireEncryption() throws Exception
225
230
public static Driver trustOnFirstUse () throws Exception
226
231
{
227
232
// 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 ()
229
234
.withEncryptionLevel ( Config .EncryptionLevel .REQUIRED )
230
235
.withTrustStrategy ( Config .TrustStrategy .trustOnFirstUse ( new File ( "/path/to/neo4j_known_hosts" ) ) )
231
236
.toConfig () );
@@ -237,9 +242,9 @@ public static Driver trustOnFirstUse() throws Exception
237
242
public static Driver trustSignedCertificates () throws Exception
238
243
{
239
244
// 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 ()
241
246
.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" ) ) )
243
248
.toConfig () );
244
249
// end::tls-signed[]
245
250
0 commit comments