Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2013 GraphAware
   *
   * This file is part of GraphAware.
   *
   * GraphAware is free software: you can redistribute it and/or modify it under the terms of
   * the GNU General Public License as published by the Free Software Foundation, either
   * version 3 of the License, or (at your option) any later version.
   *
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details. You should have received a copy of
  * the GNU General Public License along with this program.  If not, see
  * <http://www.gnu.org/licenses/>.
  */
 
 package com.graphaware.tx.event.improved.api;
 
 
 import java.util.Map;
 import java.util.Set;

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 org.neo4j.graphdb.event.TransactionData, i.e. before or after a transaction commit, this API improves the org.neo4j.graphdb.event.TransactionData API in a number of ways.

It categorizes org.neo4j.graphdb.PropertyContainers, i.e. org.neo4j.graphdb.Nodes and org.neo4j.graphdb.Relationships 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 org.neo4j.graphdb.PropertyContainer has been created, deleted, or changed in this transaction and obtain all the created, deleted, and changed org.neo4j.graphdb.PropertyContainers.

Properties that have been created, deleted, and changed in the transaction are grouped by the changed org.neo4j.graphdb.PropertyContainer they belong to. Users can find out, which properties have been created, deleted, and changed for a given changed org.neo4j.graphdb.PropertyContainer and check, whether a given property for a given changed org.neo4j.graphdb.PropertyContainer has been created, deleted, or changed.

Properties of created org.neo4j.graphdb.PropertyContainers are available through the actual created org.neo4j.graphdb.PropertyContainer. Properties of deleted org.neo4j.graphdb.PropertyContainers (as they were before the transaction started) are available through the snapshot of the deleted org.neo4j.graphdb.PropertyContainer, obtained by calling getDeleted(org.neo4j.graphdb.Node) or getDeleted(org.neo4j.graphdb.Relationship). Properties of created and deleted containers will not be returned by changedProperties(org.neo4j.graphdb.Node) and changedProperties(org.neo4j.graphdb.Relationship) as these only return changed properties of changed org.neo4j.graphdb.PropertyContainers.

Changed org.neo4j.graphdb.PropertyContainers and properties are wrapped in a Change object which holds the previous state of the object before the transaction started, and the current state of the object (when the transaction commits).

All created org.neo4j.graphdb.PropertyContainers + properties and current versions of changed org.neo4j.graphdb.PropertyContainers + 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 org.neo4j.graphdb.event.TransactionData.

A major difference between this API and org.neo4j.graphdb.event.TransactionData, however, is what one can do with the returned information about deleted org.neo4j.graphdb.PropertyContainers + 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 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 org.neo4j.graphdb.Node, or the previous version of a changed org.neo4j.graphdb.Node. Such traversal will only traverse org.neo4j.graphdb.Relationships that existed before the transaction started and will return properties and their values as they were before the transaction started. This is achieved using com.graphaware.tx.event.improved.propertycontainer.snapshot.NodeSnapshot and 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 org.neo4j.graphdb.PropertyContainers 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 org.neo4j.graphdb.PropertyContainers 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 org.neo4j.graphdb.PropertyContainers, one can traverse the previous snapshot of the graph, as it was before the transaction started.

 
 public interface ImprovedTransactionData {

    
Check whether the given node has been created in the transaction.

Parameters:
node to check.
Returns:
true iff the node has been created.
 
     boolean hasBeenCreated(Node node);

    
Get all nodes created in the transaction.

Returns:
read-only collection of all created nodes.
 
     Collection<NodegetAllCreatedNodes();

    
Check whether the given node has been deleted in the transaction.

Parameters:
node to check.
Returns:
true iff the node has been deleted.
    boolean hasBeenDeleted(Node node);

    
Get a node that has been deleted in this transaction as it was before the transaction started.

Parameters:
node to get.
Returns:
snapshot of the node before the transaction started.
Throws:
java.lang.IllegalArgumentException in case the given node has not been deleted in the transaction.
    Node getDeleted(Node node);

    
Get all nodes deleted in the transaction as they were before the transaction started.

Returns:
read-only collection of all deleted nodes as they were before the transaction started (snapshots).
Check whether a node has been changed in the transaction, i.e. if any of its properties have been changed.

Parameters:
node to check.
Returns:
true iff the node has been changed.
    boolean hasBeenChanged(Node node);

    
Get a node that has been changed in this transaction as it was before the transaction started and as it is now.

Parameters:
node to get.
Returns:
snapshot of the node before the transaction started and the current state of the node.
Throws:
java.lang.IllegalArgumentException in case the given node has not been changed in the transaction.
    Change<NodegetChanged(Node node);

    
Get all nodes changed in the transaction.

Returns:
a read-only collection of all changed nodes as they were before the transaction started and as they are now.
Check whether a property has been created in the transaction.

Parameters:
node to check. Must be a changed org.neo4j.graphdb.Node, not a created one.
key of the property to check.
Returns:
true iff the property has been created on the org.neo4j.graphdb.Node.
    boolean hasPropertyBeenCreated(Node nodeString key);

    
Get properties created in the transaction.

Parameters:
node for which to get created properties. Must be a changed org.neo4j.graphdb.Node, not a created one.
Returns:
read-only properties created for the given org.neo4j.graphdb.Node.
    Map<StringObjectcreatedProperties(Node node);

    
Check whether a property has been deleted in the transaction.

Parameters:
node to check. Must be a changed org.neo4j.graphdb.Node, not a deleted one.
key of the property to check.
Returns:
true iff the property has been deleted for the given org.neo4j.graphdb.Node.
    boolean hasPropertyBeenDeleted(Node nodeString key);

    
Get properties deleted in the transaction.

Parameters:
node for which to get deleted properties. Must be a changed org.neo4j.graphdb.Node, not a deleted one.
Returns:
read-only properties deleted for the given org.neo4j.graphdb.Node, where the value is the property value before the transaction started.
    Map<StringObjectdeletedProperties(Node node);

    
Check whether a property has been changed in the transaction.

Parameters:
node to check.
key of the property to check.
Returns:
true iff the property has been changed.
    boolean hasPropertyBeenChanged(Node nodeString key);

    
Get properties changed in the transaction.

Parameters:
node for which to get changed properties.
Returns:
read-only properties changed for the given node, where the value is the property value before and after the transaction started, respectively.
    Map<StringChange<Object>> changedProperties(Node node);

    
Check whether a label has been assigned in the transaction.

Parameters:
node to check.
label to check.
Returns:
true iff the node has been assigned.
    boolean hasLabelBeenAssigned(Node nodeLabel label);

    
Get labels assigned in the transaction.

Parameters:
node for which to get assigned labels.
Returns:
read-only labels created for the given node.
    Set<LabelassignedLabels(Node node);

    
Check whether a label has been removed in the transaction.

Parameters:
node to check.
label to check.
Returns:
true iff the label has been removed.
    boolean hasLabelBeenRemoved(Node nodeLabel label);

    
Get labels removed in the transaction.

Parameters:
node for which to get removed labels.
Returns:
read-only labels removed for the given node.
    Set<LabelremovedLabels(Node node);

    
Check whether the given relationship has been created in the transaction.

Parameters:
relationship to check.
Returns:
true iff the relationship has been created.
    boolean hasBeenCreated(Relationship relationship);

    
Get all relationships created in the transaction.

Returns:
read-only collection of all created relationships.
Check whether the given relationship has been deleted in the transaction.

Parameters:
relationship to check.
Returns:
true iff the relationship has been deleted.
    boolean hasBeenDeleted(Relationship relationship);

    
Get a relationship that has been deleted in this transaction as it was before the transaction started.

Parameters:
relationship to get.
Returns:
snapshot of the relationship before the transaction started.
Throws:
java.lang.IllegalArgumentException in case the given relationship has not been deleted in the transaction.
    Relationship getDeleted(Relationship relationship);

    
Get all relationships deleted in the transaction as they were before the transaction started.

Returns:
read-only collection of all deleted relationships as they were before the transaction started (snapshots).
Get all relationships for the given node and of the given types, which have been deleted in the transaction.

Parameters:
node for which to get deleted relationships.
types of the deleted relationships. If no types are provided, all types are returned.
Returns:
snapshot of all deleted relationships for the given node of the given types, as they were before the transaction started.
Get all relationships for the given node and of the given directions and types, which have been deleted in the transaction.

Parameters:
node for which to get deleted relationships.
direction of the deleted relationships
types of the deleted relationships.
Returns:
snapshot of all deleted relationships for the given node of the given direction and types, as they were before the transaction started.
    Collection<RelationshipgetDeletedRelationships(Node nodeDirection directionRelationshipType... types);

    
Check whether a relationship has been changed in the transaction, i.e. if any of its properties have been changed.

Parameters:
relationship to check.
Returns:
true iff the relationship has been changed.
    boolean hasBeenChanged(Relationship relationship);

    
Get a relationship that has been changed in this transaction as it was before the transaction started and as it is now.

Parameters:
relationship to get.
Returns:
snapshot of the relationship before the transaction started and the current state of the relationship.
Throws:
java.lang.IllegalArgumentException in case the given relationship has not been changed in the transaction.
    Change<RelationshipgetChanged(Relationship relationship);

    
Get all relationships changed in the transaction.

Returns:
a read-only collection of all changed relationships as they were before the transaction started and as they are now.
Check whether a property has been created in the transaction.

Parameters:
relationship to check. Must be a changed org.neo4j.graphdb.Relationship, not a created one.
key of the property to check.
Returns:
true iff the property has been created for the org.neo4j.graphdb.Relationship.
    boolean hasPropertyBeenCreated(Relationship relationshipString key);

    
Get properties created in the transaction.

Parameters:
relationship for which to get created properties. Must be a changed org.neo4j.graphdb.Node, not a created one.
Returns:
read-only properties created for the given changed org.neo4j.graphdb.Relationship.
    Map<StringObjectcreatedProperties(Relationship relationship);

    
Check whether a property has been deleted in the transaction.

Parameters:
relationship to check. Must be a changed org.neo4j.graphdb.Relationship, not a deleted one.
key of the property to check.
Returns:
true iff the property has been deleted for the given org.neo4j.graphdb.Relationship.
    boolean hasPropertyBeenDeleted(Relationship relationshipString key);

    
Get properties deleted in the transaction.

Parameters:
relationship for which to get deleted properties. Must be a changed org.neo4j.graphdb.Relationship, not a deleted one.
Returns:
read-only properties deleted for the given relationship, where the value is the property value before the transaction started.
    Map<StringObjectdeletedProperties(Relationship relationship);

    
Check whether a property has been changed in the transaction.

Parameters:
relationship to check.
key of the property to check.
Returns:
true iff the property has been changed.
    boolean hasPropertyBeenChanged(Relationship relationshipString key);

    
Get properties changed in the transaction.

Parameters:
relationship for which to get changed properties.
Returns:
read-only properties changed for the given relationship, where the value is the property value before and after the transaction started, respectively.
    Map<StringChange<Object>> changedProperties(Relationship relationship);

    
Have any mutations actually occurred?

Returns:
true iff an least one of the following method calls returns a non-empty collection: getAllCreatedNodes(), getAllCreatedRelationships(), getAllDeletedNodes(), getAllDeletedRelationships(), getAllChangedNodes(), getAllChangedRelationships().
    boolean mutationsOccurred();

    
Convert all mutations in the transaction to human-readable Strings.

Returns:
human-readable Strings.
New to GrepCode? Check out our FAQ X