Within the context of a running transaction, this API gives users the ability to find out exactly what mutations occurred on the graph during that transaction. Used in the same context as {@link org.neo4j.graphdb.event.TransactionData}, i.e. before or after a transaction commit, this API improves the {@link org.neo4j.graphdb.event.TransactionData} APIin a number of ways.
It categorizes {@link org.neo4j.graphdb.PropertyContainer}s, i.e. {@link org.neo4j.graphdb.Node}s and {@link org.neo4j.graphdb.Relationship}s into:
- created in this transaction
- deleted in this transaction
- changed in this transaction, i.e those with at least one property created, deleted, or changed
- untouched by this transaction
Users can find out, whether a {@link org.neo4j.graphdb.PropertyContainer} has been created, deleted, or changed inthis transaction and obtain all the created, deleted, and changed {@link org.neo4j.graphdb.PropertyContainer}s.
Properties that have been created, deleted, and changed in the transaction are grouped by the
changed {@link org.neo4j.graphdb.PropertyContainer} they belong to. Users can find out, which properties have been created,deleted, and changed for a given
changed {@link org.neo4j.graphdb.PropertyContainer} and check, whethera given property for a given
changed {@link org.neo4j.graphdb.PropertyContainer} has been created, deleted,or changed.
Properties of created {@link org.neo4j.graphdb.PropertyContainer}s are available through the actual created {@link org.neo4j.graphdb.PropertyContainer}. Properties of deleted {@link org.neo4j.graphdb.PropertyContainer}s (as they were before the transaction started) are available through the snapshot of the deleted {@link org.neo4j.graphdb.PropertyContainer}, obtained by calling {@link #getDeleted(org.neo4j.graphdb.Node)} or {@link #getDeleted(org.neo4j.graphdb.Relationship)}. Properties of created and deleted containers will not be returned by {@link #changedProperties(org.neo4j.graphdb.Node)} and {@link #changedProperties(org.neo4j.graphdb.Relationship)}as these only return changed properties of changed {@link org.neo4j.graphdb.PropertyContainer}s.
Changed {@link org.neo4j.graphdb.PropertyContainer}s and properties are wrapped in a {@link Change} object which holdsthe previous state of the object before the transaction started, and the current state of the object (when the transaction commits).
All created {@link org.neo4j.graphdb.PropertyContainer}s + properties and current versions of changed {@link org.neo4j.graphdb.PropertyContainer}s + properties can be accessed by native Neo4j API and the traversal API as one would expect. For example, one can traverse the graph starting from a newly created node, using a mixture of newly created and already existing relationships. In other words, one can traverse the graph as if the transaction has already been committed. This is similar to using {@link org.neo4j.graphdb.event.TransactionData}.
A major difference between this API and {@link org.neo4j.graphdb.event.TransactionData}, however, is what one can do with the returned information about deleted {@link org.neo4j.graphdb.PropertyContainer}s + properties and the previous versions thereof. With this API, one can traverse a
snapshot of the graph as it was before the transaction started. As opposed to the {@link org.neo4j.graphdb.event.TransactionData} API, this will not result in exceptions being thrown.
For example, one can start traversing the graph from a deleted {@link org.neo4j.graphdb.Node}, or the previous version of a changed {@link org.neo4j.graphdb.Node}. Such traversal will only traverse {@link org.neo4j.graphdb.Relationship}s that existed before the transaction started and will return properties and their values as they were before the transaction started. This is achieved using {@link com.graphaware.tx.event.improved.propertycontainer.snapshot.NodeSnapshot}and {@link com.graphaware.tx.event.improved.propertycontainer.snapshot.RelationshipSnapshot} decorators.
One can even perform additional mutating operations on the previous version (snapshot) of the graph, provided that the mutated objects have been changed in the transaction (as opposed to deleted). Mutating deleted {@link org.neo4j.graphdb.PropertyContainer}s and properties does not make any sense and will cause exceptions.
To summarize, this API gives access to two versions of the same graph. Through created {@link org.neo4j.graphdb.PropertyContainer}s and/or their current versions, one can traverse the current version of the graph as it will be after the transaction commits. Through deleted and/or previous versions of {@link org.neo4j.graphdb.PropertyContainer}s, one can traverse the previous snapshot of the graph, as it was before the transaction started.