@@ -48,27 +48,29 @@ public void close() throws Exception {
4848 driver .close ();
4949 }
5050
51- public void createFriendship (final String person1Name , final String person2Name ) {
51+ public void createFriendship (final String person1Name , final String person2Name , final String knowsFrom ) {
5252 // To learn more about the Cypher syntax, see https://neo4j.com/docs/cypher-manual/current/
5353 // The Reference Card is also a good resource for keywords https://neo4j.com/docs/cypher-refcard/current/
5454 String createFriendshipQuery = "CREATE (p1:Person { name: $person1_name })\n " +
5555 "CREATE (p2:Person { name: $person2_name })\n " +
56- "CREATE (p1)-[:KNOWS]->(p2)\n " +
57- "RETURN p1, p2" ;
56+ "CREATE (p1)-[k :KNOWS { from: $knows_from } ]->(p2)\n " +
57+ "RETURN p1, p2, k " ;
5858
5959 Map <String , Object > params = new HashMap <>();
6060 params .put ("person1_name" , person1Name );
6161 params .put ("person2_name" , person2Name );
62+ params .put ("knows_from" , knowsFrom );
6263
6364 try (Session session = driver .session ()) {
6465 // Write transactions allow the driver to handle retries and transient errors
6566 Record record = session .writeTransaction (tx -> {
6667 Result result = tx .run (createFriendshipQuery , params );
6768 return result .single ();
6869 });
69- System .out .println (String .format ("Created friendship between: %s, %s" ,
70+ System .out .println (String .format ("Created friendship between: %s, %s from %s " ,
7071 record .get ("p1" ).get ("name" ).asString (),
71- record .get ("p2" ).get ("name" ).asString ()));
72+ record .get ("p2" ).get ("name" ).asString (),
73+ record .get ("k" ).get ("from" ).asString ()));
7274 // You should capture any errors along with the query and data for traceability
7375 } catch (Neo4jException ex ) {
7476 LOGGER .log (Level .SEVERE , createFriendshipQuery + " raised an exception" , ex );
@@ -102,9 +104,12 @@ public static void main(String... args) throws Exception {
102104
103105 String user = "<Username for Neo4j Aura database>" ;
104106 String password = "<Password for Neo4j Aura database>" ;
105-
106- try (DriverIntroductionExample app = new DriverIntroductionExample (boltUrl , user , password , Config .defaultConfig ())) {
107- app .createFriendship ("Alice" , "David" );
107+ Config config = Config .builder ()
108+ // Configuring slf4j logging
109+ .withLogging ( Logging .slf4j () )
110+ .build ();
111+ try (DriverIntroductionExample app = new DriverIntroductionExample (boltUrl , user , password , config )) {
112+ app .createFriendship ("Alice" , "David" , "School" );
108113 app .findPerson ("Alice" );
109114 }
110115 }
0 commit comments