14.6.2.4 Error Handling when Using a ChangeSet

Error handling while populating a ChangeSet or while applying a ChangeSet to the existing graph can be configured by setting the InvalidChangePolicy. The options are:

  • OnInvalidChange.ERROR: throws an exception (This is the default configuration)
  • OnInvalidChange.IGNORE: ignores the issue and continues
  • OnInvalidChange.IGNORE_AND_LOG: ignores the issue, logs in DEBUG log level and continues
  • OnInvalidChange.IGNORE_AND_LOG_ONCE: only logs the first occurrence of each issue type

Issues that can be ignored with InvalidChangePolicy include trying to remove a vertex or an edge that does not exist in the graph, property type mismatch, updates to non existing properties, providing a vertex ID with wrong type or invalid vertex or edge providers.

The following example, tries to remove vertex 9032 which does not exist in the graph. By configuring IGNORE_AND_LOG, this action will be ignored while the property value update for vertex 99 will be applied successfully.

opg4j> var changeSet3 = updatedGraph2.<Integer>createChangeSet()
opg4j> changeSet3.setInvalidChangePolicy(OnInvalidChange.IGNORE_AND_LOG)

opg4j> changeSet3.removeVertex(9032)
opg4j> changeSet3.updateVertex(99).setProperty("prop1", 17)
opg4j> var updatedGraph3 = changeSet3.build() // will log that a vertex removal was ignored

opg4j> var prop1Val = updatedGraph3.getVertex(99).getProperty("prop1") // evaluates to 17
import oracle.pgx.api.*;

GraphChangeSet<Integer> changeSet3 = graph.createChangeSet();
changeSet3.setInvalidChangePolicy(OnInvalidChange.IGNORE_AND_LOG);
changeSet3.removeVertex(9032);
changeSet3.updateVertex(99).setProperty("prop1", 17);
PgxGraph updatedGraph3 = changeSet3.build(); // will log that a vertex removal was ignored

int prop1Val = updatedGraph3.getVertex(99).getProperty("prop1"); // evaluates to 17

Note:

When connecting to a remote graph server (PGX), error handling log messages will not be relayed to the client. In such a case, you need access to the server logs to determine which issues have been ignored. For this, you must update the default Logback configuration file in /etc/oracle/graph/logback.xml and the graph server (PGX) logger configuration file in /etc/oracle/graph/logback-server.xml to log the DEBUG logs. You can then view the ignored issues in /var/opt/log/pgx-server.log file.

Add Existing Edges and Vertices

The error handling for adding a vertex or an edge where its ID is already used in the graph or in an incompatible ChangeSet action can be configured with AddExistingVertexPolicy and AddExistingEdgePolicy.

Note:

The default setting for AddExistingVertexPolicy and AddExistingEdgePolicy is IGNORE. This is different from InvalidChangePolicy where the default is ERROR.