"*--- points to the Neo4j DB host ---*
DATA(neo4a) = NEW zcl_neo4a( '192.168.38.52' ).
TYPES: BEGIN OF ty_actor,
name TYPE string,
END OF ty_actor,
BEGIN OF ty_movie,
title TYPE string,
END OF ty_movie.
DATA(actor) = VALUE ty_actor( name = 'Tom Hanks' ).
DATA(movie) = VALUE ty_movie( title = 'Sleepless IN Seattle' ).
TRY.
DATA(node_actor) = neo4a->create_node(
i_properties = actor
i_label = 'Actor'
).
DATA(node_movie) = neo4a->create_node(
i_properties = movie
i_label = 'Movie'
).
CATCH zcx_neo4a INTO DATA(n4a_ex).
WRITE😕 n4a_ex->get_text( ).
RETURN.
ENDTRY.
DATA(neo4a) = NEW zcl_neo4a( '192.168.38.52' ).
TRY.
DATA(node_actor) = neo4a->get_node( 1 ).
DATA(node_movie) = neo4a->get_node( 2 ).
DATA(relationship) = node_actor->create_relationship(
i_type = 'acted_in'
i_to_node = node_movie
).
CATCH zcx_neo4a INTO DATA(n4a_ex).
WRITE😕 n4a_ex->get_text( ).
RETURN.
ENDTRY.
DATA(neo4a) = NEW zcl_neo4a( '192.168.38.52' ).
TRY.
DATA(node) = neo4a->get_node( 1 ).
node->set_property(
EXPORTING
i_name = 'year_of_birth'
i_value = '1944'
).
DATA(name) = node->get_property( 'name' ).
DATA(yob) = node->get_property( 'year_of_birth' ).
cl_demo_output=>display( |{ name } : { yob }| ).
CATCH zcx_neo4a INTO DATA(n4a_ex).
WRITE😕 n4a_ex->get_text( ).
RETURN.
ENDTRY.
DATA(neo4a) = NEW zcl_neo4a( '192.168.38.52' ).
DATA: BEGIN OF actor,
name TYPE string,
year_of_birth TYPE string,
END OF actor.
TRY.
neo4a->get_node( 1 )->get_properties(
IMPORTING
e_properties = actor
e_properties_json = DATA(properties_json)
e_properties_table = DATA(properties_table)
).
cl_demo_output=>begin_section( 'DATA' ).
cl_demo_output=>write( actor ).
cl_demo_output=>begin_section( 'JSON' ).
cl_demo_output=>write( properties_json ).
cl_demo_output=>begin_section( 'Name/Value pairs' ).
cl_demo_output=>write( properties_table ).
cl_demo_output=>display( ).
CATCH zcx_neo4a INTO DATA(n4a_ex).
WRITE😕 n4a_ex->get_text( ).
RETURN.
ENDTRY.
DATA(neo4a) = NEW zcl_neo4a( '192.168.38.52' ).
TYPES: BEGIN OF ty_movie,
title TYPE string,
END OF ty_movie.
DATA(movie) = VALUE ty_movie( title = 'Forrest Gump' ).
TRY.
"*--- create another movie ---*
DATA(node_movie) = neo4a->create_node(
i_properties = movie
i_label = 'Movie'
).
"*--- and connect to Tom ---*
neo4a->get_node( 1 )->create_relationship(
EXPORTING
i_type = 'acted_in'
i_to_node = node_movie
).
"*--- get all movies ---*
neo4a->get_nodes_with_label(
EXPORTING
i_label = 'Movie'
IMPORTING
e_nodes = DATA(movies)
).
LOOP AT movies ASSIGNING FIELD-SYMBOL(<movie>).
cl_demo_output=>write_text( <movie>->get_property( 'title' ) ).
ENDLOOP.
cl_demo_output=>display( ).
CATCH zcx_neo4a INTO DATA(n4a_ex).
WRITE😕 n4a_ex->get_text( ).
RETURN.
ENDTRY.
DATA(neo4a) = NEW zcl_neo4a( '192.168.38.52' ).
"*--- get all movies where Tom acted in ---*
DATA(query) = `MATCH (actor:Actor {name:'Tom Hanks'})-[r:acted_in]->(movie:Movie) RETURN movie.title`.
TRY.
neo4a->query(
EXPORTING
i_cypher = query
IMPORTING
e_result = DATA(result)
).
cl_demo_output=>display_json( result ).
CATCH zcx_neo4a INTO DATA(n4a_ex).
WRITE😕 n4a_ex->get_text( ).
RETURN.
ENDTRY.
"transaction" : {
"expires" : "Fri, 24 Jan 2015 22:53:51 +0000"
},
DATA(neo4a) = NEW zcl_neo4a( '192.168.38.52' ).
DATA(statements) = VALUE string_table(
(
`CREATE (matrix1:Movie { title : 'The Matrix', year : '1999-03-31' })` &&
`CREATE (matrix2:Movie { title : 'The Matrix Reloaded', year : '2003-05-07' })` &&
`CREATE (matrix3:Movie { title : 'The Matrix Revolutions', year : '2003-10-27' })` &&
`CREATE (keanu:Actor { name:'Keanu Reeves' })` &&
`CREATE (laurence:Actor { name:'Laurence Fishburne' })` &&
`CREATE (carrieanne:Actor { name:'Carrie-Anne Moss' })` &&
`CREATE (keanu)-[:ACTS_IN { role : 'Neo' }]->(matrix1)` &&
`CREATE (keanu)-[:ACTS_IN { role : 'Neo' }]->(matrix2)` &&
`CREATE (keanu)-[:ACTS_IN { role : 'Neo' }]->(matrix3)` &&
`CREATE (laurence)-[:ACTS_IN { role : 'Morpheus' }]->(matrix1)` &&
`CREATE (laurence)-[:ACTS_IN { role : 'Morpheus' }]->(matrix2)` &&
`CREATE (laurence)-[:ACTS_IN { role : 'Morpheus' }]->(matrix3)` &&
`CREATE (carrieanne)-[:ACTS_IN { role : 'Trinity' }]->(matrix1)` &&
`CREATE (carrieanne)-[:ACTS_IN { role : 'Trinity' }]->(matrix2)` &&
`CREATE (carrieanne)-[:ACTS_IN { role : 'Trinity' }]->(matrix3)`
)
(
`CREATE (whatever:Movie { title : 'Just another Movie', year : '2015-01-24' })`
)
).
DATA(next_statements) = VALUE string_table(
(
`CREATE (whatever2:Movie { title : 'Yet another Movie', year : '2015-01-24' })`
)
).
TRY.
"*--- create the transaction ---*
DATA(transaction) = neo4a->create_transaction( ).
"*--- send the DB statements ---*
transaction->send( i_statements = statements ).
transaction->send( i_statements = next_statements ).
"*--- placeholders without properties should be visible now ---*
cl_demo_output=>display( 'have a look in the Neo4j browser' ).
"*--- and rollback the work ---*
transaction->rollback( ).
"*--- look Mom, they are gone ---*
cl_demo_output=>display( 'and look again' ).
CATCH zcx_neo4a INTO DATA(n4a_ex).
WRITE😕 n4a_ex->get_text( ).
RETURN.
ENDTRY.
"*--- commit the work ---*
transaction->commit( ).
"*--- tahtah, the Matrix ---*
cl_demo_output=>display( 'the red pill please' ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 |