X

Oracle Big Data Spatial and Graph - technical tips, best practices, and news from the product team

Applying changes to an in-memory graph snapshot

Alan Wu
Architect

A little while ago, I got a question on how to apply changes to an existing in-memory graph snapshot and generate an updated graph. The following Groovy code snippet shows how. Note that I am using Oracle Big Data Spatial and Graph (BDSG) v2.4.

// First, read the graph data out of an Oracle NoSQL Database

cfg = GraphConfigBuilder.forPropertyGraphNosql()             \
  .setName("connections").setStoreName("kvstore")            \
  .setHosts(server)                                          \
  .addVertexProperty("name", PropertyType.STRING, "null") \
  .addEdgeProperty("weight", PropertyType.DOUBLE, "1000000") \
  .setMaxNumConnections(2).build();


// Get an instance of OraclePropertyGraph which is a key Java
// class to manage property graph data
opg = OraclePropertyGraph.getInstance(cfg);

// assume there is a vertex (ID = 1) with name="John" in this graph

// read this graph into in-memory snapshot
pgxGraph = session.readGraphWithProperties(opg.getConfig(), true);


// We can inspect vertex 1
//

pgxVertex1=pgxGraph.getVertex(1)

opg-nosql> pgxVertex1.getProperty("name")
==>John

 

// Start to make changes 

changeSet = pgxGraph.createChangeSet()

vm = changeSet.updateVertex(pgxVertex1.getId())
vm.setProperty("name", "Hey a new name")

pgxGraphNew = changeSet.build("new")
pgxVertexNew1 = pgxGraphNew.getVertex(1)
pgxVertexNew1.getProperty("name")

opg-nosql> pgxVertexNew1.getProperty("name")
==>Hey a new name


// The original vertex in the old graph still has name="John"
opg-nosql> pgxGraph.getVertex(1).getProperty("name")
==>John

Cheers,

Zhe

 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.