14.8.3 Creating a Snapshot via ChangeSet

You can create a graph snapshot with ChangeSet via the PGX Java API. When you want to create the graph from a persistent data source, you can use PgxSession.readGraphWithProperties() with the snapshots_source configuration option set to CHANGE_SET.

You can create a snapshot via ChangeSet by performing the following steps:

  1. Create a snapshot of a transient graph from database:
    opg4j> var builder = session.createGraphBuilder()
    opg4j> builder.addEdge(1, 2)
    opg4j> builder.addEdge(2, 3)
    opg4j> builder.addEdge(2, 4)
    opg4j> builder.addEdge(3, 4)
    opg4j> builder.addEdge(4, 2)
    opg4j> var graph = builder.build()
    import oracle.pgx.api.*;
    
    GraphBuilder<Integer> builder = session.createGraphBuilder();
    
    builder.addEdge(1, 2);
    builder.addEdge(2, 3);
    builder.addEdge(2, 4);
    builder.addEdge(3, 4);
    builder.addEdge(4, 2);
    
    PgxGraph graph = builder.build();
    builder = session.create_graph_builder();
    
    builder.add_edge(1, 2)
    builder.add_edge(2, 3)
    builder.add_edge(2, 4)
    builder.add_edge(3, 4)
    builder.add_edge(4, 2)
    
    graph = builder.build()
  2. Create a ChangeSet from graph and populate it. The following example shows adding a new edge between vertices 1 and 4:
    opg4j> var changeSet = graph.<Integer>createChangeSet()
    opg4j> changeSet.addEdge(6, 1, 4)
    import oracle.pgx.api.*;
    GraphChangeSet<Integer> changeSet = graph.createChangeSet();
    changeSet.addEdge(6, 1, 4);
    changeSet = graph.create_change_set()changeSet.add_edge(1,4,6)
  3. Create a second snapshot using GraphChangeSet.buildNewSnapshot() as shown in the following code:
    opg4j> var secondSnapshot = changeSet.buildNewSnapshot()
    opg4j> session.getAvailableSnapshots(secondSnapshot).size()
    ==> 2
    PgxGraph secondSnapshot = changeSet.buildNewSnapshot();
    System.out.println( session.getAvailableSnapshots(secondSnapshot).size() );
    second_snapshot = change_set.build_new_snapshot()
    print(len(session,get_available_snapshots()))
    Thus two snapshots, referenced via the variables graph and secondSnapshot are created.