internal virtual void CompareWith(NodeRep other, DiffReport diff) { if (other.Id != Id) { diff.Add("Id differs mine:" + Id + ", other:" + other.Id); } Properties.compareWith(other.Properties, diff); if (Index != null && other.Index != null) { CompareIndex(other, diff); } CompareRelationships(other, diff); }
public override bool Equals(object o) { if (this == o) { return(true); } if (o == null || this.GetType() != o.GetType()) { return(false); } NodeRep nodeRep = ( NodeRep )o; return(Id == nodeRep.Id && Objects.Equals(Properties, nodeRep.Properties) && Objects.Equals(OutRelationships, nodeRep.OutRelationships) && Objects.Equals(Index, nodeRep.Index)); }
/* * Yes, this is not the best way to do it - hash map does a deep equals. However, * if things go wrong, this way give the ability to check where the inequality * happened. If you feel strongly about this, feel free to change. * Admittedly, the implementation could use some cleanup. */ internal virtual void CompareIndex(NodeRep other, DiffReport diff) { if (other.Index == Index) { return; } ICollection <string> allIndexes = new HashSet <string>(); allIndexes.addAll(Index.Keys); allIndexes.addAll(other.Index.Keys); foreach (string indexName in allIndexes) { if (!Index.ContainsKey(indexName)) { diff.Add(this + " isn't indexed in " + indexName + " for mine"); continue; } if (!other.Index.ContainsKey(indexName)) { diff.Add(this + " isn't indexed in " + indexName + " for other"); continue; } IDictionary <string, Serializable> thisIndex = Index[indexName]; IDictionary <string, Serializable> otherIndex = other.Index[indexName]; if (thisIndex.Count != otherIndex.Count) { diff.Add("other index had a different mapping count than me for node " + this + " mine:" + thisIndex + ", other:" + otherIndex); continue; } foreach (KeyValuePair <string, Serializable> indexEntry in thisIndex.SetOfKeyValuePairs()) { if (!indexEntry.Value.Equals(otherIndex[indexEntry.Key])) { diff.Add("other index had a different value indexed for " + indexEntry.Key + "=" + indexEntry.Value + ", namely " + otherIndex[indexEntry.Key] + " for " + this); } } } }
internal virtual void CompareRelationships(NodeRep other, DiffReport diff) { foreach (PropertiesRep rel in OutRelationships.Values) { PropertiesRep otherRel = other.OutRelationships[rel.EntityId]; if (otherRel == null) { diff.Add("I have relationship " + rel.EntityId + " which other don't"); continue; } rel.CompareWith(otherRel, diff); } foreach (long?id in other.OutRelationships.Keys) { if (!OutRelationships.ContainsKey(id)) { diff.Add("Other has relationship " + id + " which I don't"); } } }
private void NodeDiff(DbRepresentation other, DiffReport diff) { foreach (NodeRep node in _nodes.Values) { NodeRep otherNode = other._nodes[node.Id]; if (otherNode == null) { diff.Add("I have node " + node.Id + " which other doesn't"); continue; } node.CompareWith(otherNode, diff); } foreach (long?id in other._nodes.Keys) { if (!_nodes.ContainsKey(id)) { diff.Add("Other has node " + id + " which I don't"); } } }
public static DbRepresentation Of(GraphDatabaseService db, bool includeIndexes) { int retryCount = 5; while (true) { try { using (Transaction ignore = Db.beginTx()) { DbRepresentation result = new DbRepresentation(); foreach (Node node in Db.AllNodes) { NodeRep nodeRep = new NodeRep(db, node, includeIndexes); result._nodes[node.Id] = nodeRep; result._highestNodeId = Math.Max(node.Id, result._highestNodeId); result._highestRelationshipId = Math.Max(nodeRep.HighestRelationshipId, result._highestRelationshipId); } foreach (IndexDefinition indexDefinition in Db.schema().Indexes) { result._schemaIndexes.Add(indexDefinition); } foreach (ConstraintDefinition constraintDefinition in Db.schema().Constraints) { result._constraints.Add(constraintDefinition); } return(result); } } catch (TransactionFailureException e) { if (retryCount-- < 0) { throw e; } } } }