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.data.lazy;
 
 
 import java.util.Set;
 
 import static com.graphaware.common.util.DirectionUtils.matches;
 import static org.neo4j.graphdb.Direction.BOTH;

 
 
     private final TransactionData transactionData;
     private final TransactionDataContainer transactionDataContainer;

    
Construct relationship transaction data from Neo4j org.neo4j.graphdb.event.TransactionData.

Parameters:
transactionData provided by Neo4j.
transactionDataContainer containing com.graphaware.tx.event.improved.data.PropertyContainerTransactionData.
 
     public LazyRelationshipTransactionData(TransactionData transactionDataTransactionDataContainer transactionDataContainer) {
         this. = transactionData;
         this. = transactionDataContainer;
     }

    
 
     @Override
     protected Relationship oldSnapshot(Relationship original) {
         return new RelationshipSnapshot(original);
     }

    
 
     @Override
     protected Relationship newSnapshot(Relationship original) {
         return original;
     }

    
 
     @Override
     protected Iterable<Relationshipcreated() {
         return .createdRelationships();
     }

    
 
     @Override
     protected Iterable<Relationshipdeleted() {
         return .deletedRelationships();
     }

    
 
     @Override
     }

    
 
     @Override
    }

    
    @Override
    public Collection<RelationshipgetCreated(Node nodeRelationshipType... types) {
        return getCreated(nodetypes);
    }

    
    @Override
    public Collection<RelationshipgetCreated(Node nodeDirection directionRelationshipType... types) {
        return filterRelationships(getAllCreated(), nodedirectiontypes);
    }

    
    @Override
    public Collection<RelationshipgetDeleted(Node nodeRelationshipType... types) {
        return getDeleted(nodetypes);
    }

    
    @Override
    public Collection<RelationshipgetDeleted(Node nodeDirection directionRelationshipType... types) {
        return filterRelationships(getAllDeleted(), nodedirectiontypes);
    }

    
Filter relationships based on type and direction.

Parameters:
node whose point of view we're looking.
direction of the relationships to be incuded.
types of the relationships to be included.
Returns:
filtered relationships.
    private Collection<RelationshipfilterRelationships(Iterable<RelationshiprelationshipsNode nodeDirection directionRelationshipType[] types) {
        Set<StringtypeNames = new HashSet<>();
        for (RelationshipType type : types) {
            typeNames.add(type.name());
        }
        Set<Relationshipresult = new HashSet<>();
        for (Relationship r : relationships) {
            if ((typeNames.isEmpty() || typeNames.contains(r.getType().name())) &&
                    ((r.getStartNode().getId() == node.getId() && matches(rr.getStartNode(), direction))
                            || (r.getEndNode().getId() == node.getId() && matches(rr.getEndNode(), direction)))) {
                result.add(r);
            }
        }
        return result;
    }
    @Override
    protected Change<RelationshipcreateChangeObject(Relationship candidate) {
        return new Change<>(oldSnapshot(bugWorkaround(candidate)), newSnapshot(bugWorkaround(candidate)));
    }
    private Relationship bugWorkaround(Relationship relationship) {
        return relationship.getGraphDatabase().getRelationshipById(relationship.getId());
    }
New to GrepCode? Check out our FAQ X