public TransactionData getTransactionData() { TransactionDataImpl result = new TransactionDataImpl(); PrimitiveElement element = cowMap.get( getTransaction() ); populateCreatedNodes( element, result ); if ( element == null ) { return result; } if ( element.nodes != null ) { populateNodeRelEvent( element, result ); } if ( element.relationships != null ) { populateRelationshipPropertyEvents( element, result ); } return result; }
/** * @see org.neo4j.graphdb.event.TransactionEventHandler#beforeCommit(org.neo4j.graphdb.event.TransactionData) */ public Void beforeCommit(TransactionData data) throws Exception { return null; }
@Override public Object beforeCommit(TransactionData transactionData) throws Exception { return null; }
@Override public void afterCommit(TransactionData transactionData, Object o) { ex.submit(new SuspectRunnable(transactionData, db)); }
public SuspectRunnable (TransactionData transactionData, GraphDatabaseService graphDatabaseService) { td = transactionData; db = graphDatabaseService; }
public TransactionData getTransactionData() { return lockReleaser.getTransactionData(); }
@Override public T beforeCommit(TransactionData data) throws Exception { long currentTime = System.currentTimeMillis(); updateParentTimestampsFor(data.assignedRelationshipProperties(), currentTime); updateParentTimestampsFor(data.assignedNodeProperties(), currentTime); // With removed properties, don't update when node is being deleted updateRemoveTimestampsFor(data.removedRelationshipProperties(), data.deletedRelationships(), currentTime); updateRemoveTimestampsFor(data.removedNodeProperties(), data.deletedNodes(), currentTime); updateTimestampsFor(data.createdNodes(), currentTime); if (this.addCreated){ addCreatedTimestampFor(data.createdNodes(), currentTime); } // For created relationships, update both start and end node, and relationship itself Iterable<Relationship> createdRelationships = data.createdRelationships(); Set<PropertyContainer> updatedPropertyContainers = null; for (Relationship relationship : createdRelationships) { if (updatedPropertyContainers == null) updatedPropertyContainers = new HashSet<PropertyContainer>(); updatedPropertyContainers.add(relationship.getEndNode()); updatedPropertyContainers.add(relationship.getStartNode()); } updateTimestampsFor(updatedPropertyContainers, currentTime); updateTimestampsFor(createdRelationships, currentTime); if (this.addCreated){ addCreatedTimestampFor(createdRelationships, currentTime); } // Process custom relationships if (customPropertyHandlers != null && !customPropertyHandlers.isEmpty()){ for (TimestampCustomPropertyHandler cpr : customPropertyHandlers){ for (PropertyEntry<Node> assignedProperty : data.assignedNodeProperties()){ if (cpr.getCustomPropertyName() == assignedProperty.key()){ // Assigned custom property found, process modifications updateCustomRelationshipModifiedTimestampsFor( assignedProperty.entity(), cpr.getModifiedRelationshipTypes(), cpr.getDirection(), currentTime); } } for (PropertyEntry<Node> removedProperty : data.removedNodeProperties()){ if (cpr.getCustomPropertyName() == removedProperty.key()){ // Removed custom property found, process modifications to relationships updateCustomRelationshipModifiedTimestampsFor( removedProperty.entity(), cpr.getModifiedRelationshipTypes(), cpr.getDirection(), currentTime); } } } } return null; }
@Override public void afterCommit(TransactionData data, java.lang.Object state) { }
@Override public void afterRollback(TransactionData data, java.lang.Object state) { }
/** * @see org.neo4j.graphdb.event.TransactionEventHandler#afterCommit(org.neo4j.graphdb.event.TransactionData, * java.lang.Object) */ public void afterCommit(TransactionData data, Void state) { List<JsonDocument> jsonDocuments = buildJSONDocument(data); if (jsonDocuments != null) { sendJSONDocumentsToCouchbase(jsonDocuments); } }
/** * * @param data * the data that has changed during the course of one transaction */ public List<JsonDocument> buildJSONDocument(TransactionData data) { LOGGER.debug("Starting transofrm data from Cypher to JSON..."); Neo4jToCouchbaseTransformer transformer = new Neo4jToCouchbaseTransformer(); List<JsonDocument> jsonDocuments = transformer.transform(data, this.db); return jsonDocuments; }
/** * @see org.neo4j.graphdb.event.TransactionEventHandler#afterRollback(org.neo4j.graphdb.event.TransactionData, * java.lang.Object) */ public void afterRollback(TransactionData data, Void state) { }
@Override public void afterRollback(TransactionData transactionData, Object o) { }