Ejemplo n.º 1
0
        private static AddedWithValuesAndRemoved IndexUpdatesWithValuesScanAndFilter(ReadableTransactionState txState, IndexDescriptor descriptor, IndexQuery filter, IndexOrder indexOrder)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> updates = getUpdates(txState, descriptor, indexOrder);
            IDictionary <ValueTuple, ? extends LongDiffSets> updates = GetUpdates(txState, descriptor, indexOrder);

            if (updates == null)
            {
                return(_emptyAddedAndRemovedWithValues);
            }

            MutableList <NodeWithPropertyValues> added = Lists.mutable.empty();
            MutableLongSet removed = LongSets.mutable.empty();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.Map.Entry<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> entry : updates.entrySet())
            foreach (KeyValuePair <ValueTuple, ? extends LongDiffSets> entry in updates.SetOfKeyValuePairs())
            {
                ValueTuple key = entry.Key;
                if (filter == null || filter.AcceptsValue(key.OnlyValue))
                {
                    Value[]      values  = key.Values;
                    LongDiffSets diffSet = entry.Value;
                    diffSet.Added.each(nodeId => added.add(new NodeWithPropertyValues(nodeId, values)));
                    removed.addAll(diffSet.Removed);
                }
            }
            return(new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed));
        }
Ejemplo n.º 2
0
        internal static AddedWithValuesAndRemoved IndexUpdatesWithValuesForRangeSeekByPrefix(ReadableTransactionState txState, IndexDescriptor descriptor, TextValue prefix, IndexOrder indexOrder)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.NavigableMap<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
            NavigableMap <ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.GetSortedIndexUpdates(descriptor.Schema());

            if (sortedUpdates == null)
            {
                return(_emptyAddedAndRemovedWithValues);
            }
            ValueTuple floor = ValueTuple.of(prefix);

            MutableList <NodeWithPropertyValues> added = Lists.mutable.empty();
            MutableLongSet removed = LongSets.mutable.empty();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.Map.Entry<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> entry : sortedUpdates.tailMap(floor).entrySet())
            foreach (KeyValuePair <ValueTuple, ? extends LongDiffSets> entry in sortedUpdates.tailMap(floor).entrySet())
            {
                ValueTuple key = entry.Key;
                if ((( TextValue )key.OnlyValue).startsWith(prefix))
                {
                    LongDiffSets diffSets = entry.Value;
                    Value[]      values   = key.Values;
                    diffSets.Added.each(nodeId => added.add(new NodeWithPropertyValues(nodeId, values)));
                    removed.addAll(diffSets.Removed);
                }
                else
                {
                    break;
                }
            }
            return(new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed));
        }
Ejemplo n.º 3
0
        private LongDiffSets GetLabelStateNodeDiffSets(long labelId)
        {
            if (_labelStatesMap == null)
            {
                return(LongDiffSets.EMPTY);
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.txstate.LongDiffSets nodeDiffSets = labelStatesMap.get(labelId);
            LongDiffSets nodeDiffSets = _labelStatesMap.get(labelId);

            return(nodeDiffSets == null ? LongDiffSets.EMPTY : nodeDiffSets);
        }
Ejemplo n.º 4
0
        public override MutableLongSet AugmentLabels(MutableLongSet labels, NodeState nodeState)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.txstate.LongDiffSets labelDiffSets = nodeState.labelDiffSets();
            LongDiffSets labelDiffSets = nodeState.LabelDiffSets();

            if (!labelDiffSets.Empty)
            {
                labelDiffSets.Removed.forEach(labels.remove);
                labelDiffSets.Added.forEach(labels.add);
            }
            return(labels);
        }
Ejemplo n.º 5
0
        // SEEK

        internal static AddedAndRemoved IndexUpdatesForSeek(ReadableTransactionState txState, IndexDescriptor descriptor, ValueTuple values)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.eclipse.collections.impl.UnmodifiableMap<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> updates = txState.getIndexUpdates(descriptor.schema());
            UnmodifiableMap <ValueTuple, ? extends LongDiffSets> updates = txState.GetIndexUpdates(descriptor.Schema());

            if (updates != null)
            {
                LongDiffSets indexUpdatesForSeek = updates.get(values);
                return(indexUpdatesForSeek == null ? _emptyAddedAndRemoved : new AddedAndRemoved(LongLists.mutable.ofAll(indexUpdatesForSeek.Added), indexUpdatesForSeek.Removed));
            }
            return(_emptyAddedAndRemoved);
        }
Ejemplo n.º 6
0
        public override void NodeDoDelete(long nodeId)
        {
            Nodes().remove(nodeId);

            if (_nodeStatesMap != null)
            {
                NodeStateImpl nodeState = _nodeStatesMap.remove(nodeId);
                if (nodeState != null)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.txstate.LongDiffSets diff = nodeState.labelDiffSets();
                    LongDiffSets diff = nodeState.LabelDiffSets();
                    diff.Added.each(label => GetOrCreateLabelStateNodeDiffSets(label).remove(nodeId));
                    nodeState.ClearIndexDiffs(nodeId);
                    nodeState.Clear();
                }
            }
            DataChanged();
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void accept(final org.neo4j.storageengine.api.txstate.TxStateVisitor visitor) throws org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException, org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public override void Accept(TxStateVisitor visitor)
        {
            if (_nodes != null)
            {
                _nodes.Added.each(visitor.visitCreatedNode);
            }

            if (_relationships != null)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.iterator.LongIterator added = relationships.getAdded().longIterator();
                LongIterator added = _relationships.Added.longIterator();
                while (added.hasNext())
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long relId = added.next();
                    long relId = added.next();
                    if (!RelationshipVisit(relId, visitor.visitCreatedRelationship))
                    {
                        throw new System.InvalidOperationException("No RelationshipState for added relationship!");
                    }
                }
                _relationships.Removed.forEach(visitor.visitDeletedRelationship);
            }

            if (_nodes != null)
            {
                _nodes.Removed.each(visitor.visitDeletedNode);
            }

            foreach (NodeState node in ModifiedNodes())
            {
                if (node.HasPropertyChanges())
                {
                    visitor.VisitNodePropertyChanges(node.Id, node.AddedProperties(), node.ChangedProperties(), node.RemovedProperties());
                }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.txstate.LongDiffSets labelDiffSets = node.labelDiffSets();
                LongDiffSets labelDiffSets = node.LabelDiffSets();
                if (!labelDiffSets.Empty)
                {
                    visitor.VisitNodeLabelChanges(node.Id, labelDiffSets.Added, labelDiffSets.Removed);
                }
            }

            foreach (RelationshipState rel in ModifiedRelationships())
            {
                visitor.VisitRelPropertyChanges(rel.Id, rel.AddedProperties(), rel.ChangedProperties(), rel.RemovedProperties());
            }

            if (_graphState != null)
            {
                visitor.VisitGraphPropertyChanges(_graphState.addedProperties(), _graphState.changedProperties(), _graphState.removedProperties());
            }

            if (_indexChanges != null)
            {
                _indexChanges.Added.forEach(visitor.visitAddedIndex);
                _indexChanges.Removed.forEach(visitor.visitRemovedIndex);
            }

            if (_constraintsChanges != null)
            {
                foreach (ConstraintDescriptor added in _constraintsChanges.Added)
                {
                    visitor.VisitAddedConstraint(added);
                }
                _constraintsChanges.Removed.forEach(visitor.visitRemovedConstraint);
            }

            if (_createdLabelTokens != null)
            {
                _createdLabelTokens.forEachKeyValue(visitor.visitCreatedLabelToken);
            }

            if (_createdPropertyKeyTokens != null)
            {
                _createdPropertyKeyTokens.forEachKeyValue(visitor.visitCreatedPropertyKeyToken);
            }

            if (_createdRelationshipTypeTokens != null)
            {
                _createdRelationshipTypeTokens.forEachKeyValue(visitor.visitCreatedRelationshipTypeToken);
            }
        }
        private void TakeSnapshot()
        {
            try
            {
                using (StorageNodeCursor node = _store.allocateNodeCursor(), StoragePropertyCursor properties = _store.allocatePropertyCursor(), StorageRelationshipScanCursor relationship = _store.allocateRelationshipScanCursor())
                {
                    TokenRead tokenRead = _transaction.tokenRead();
                    _state.addedAndRemovedNodes().Removed.each(nodeId =>
                    {
                        node.Single(nodeId);
                        if (node.Next())
                        {
                            properties.Init(node.PropertiesReference());
                            while (properties.Next())
                            {
                                try
                                {
                                    _removedNodeProperties.Add(new NodePropertyEntryView(this, nodeId, tokenRead.PropertyKeyName(properties.PropertyKey()), null, properties.PropertyValue()));
                                }
                                catch (PropertyKeyIdNotFoundKernelException e)
                                {
                                    throw new System.InvalidOperationException("Nonexisting properties was modified for node " + nodeId, e);
                                }
                            }

                            foreach (long labelId in node.Labels())
                            {
                                try
                                {
                                    _removedLabels.Add(new LabelEntryView(this, nodeId, tokenRead.NodeLabelName(toIntExact(labelId))));
                                }
                                catch (LabelNotFoundKernelException e)
                                {
                                    throw new System.InvalidOperationException("Nonexisting label was modified for node " + nodeId, e);
                                }
                            }
                        }
                    });
                    _state.addedAndRemovedRelationships().Removed.each(relId =>
                    {
                        Relationship relationshipProxy = relationship(relId);
                        relationship.Single(relId);
                        if (relationship.Next())
                        {
                            properties.Init(relationship.PropertiesReference());
                            while (properties.Next())
                            {
                                try
                                {
                                    _removedRelationshipProperties.Add(new RelationshipPropertyEntryView(relationshipProxy, tokenRead.PropertyKeyName(properties.PropertyKey()), null, properties.PropertyValue()));
                                }
                                catch (PropertyKeyIdNotFoundKernelException e)
                                {
                                    throw new System.InvalidOperationException("Nonexisting node properties was modified for relationship " + relId, e);
                                }
                            }
                        }
                    });
                    foreach (NodeState nodeState in _state.modifiedNodes())
                    {
                        IEnumerator <StorageProperty> added = nodeState.AddedAndChangedProperties();
                        long nodeId = nodeState.Id;
                        while (added.MoveNext())
                        {
                            StorageProperty property = added.Current;
                            _assignedNodeProperties.Add(new NodePropertyEntryView(this, nodeId, tokenRead.PropertyKeyName(property.PropertyKeyId()), property.Value(), CommittedValue(nodeState, property.PropertyKeyId(), node, properties)));
                        }
                        nodeState.RemovedProperties().each(id =>
                        {
                            try
                            {
                                NodePropertyEntryView entryView = new NodePropertyEntryView(this, nodeId, tokenRead.PropertyKeyName(id), null, CommittedValue(nodeState, id, node, properties));
                                _removedNodeProperties.Add(entryView);
                            }
                            catch (PropertyKeyIdNotFoundKernelException e)
                            {
                                throw new System.InvalidOperationException("Nonexisting node properties was modified for node " + nodeId, e);
                            }
                        });

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.txstate.LongDiffSets labels = nodeState.labelDiffSets();
                        LongDiffSets labels = nodeState.LabelDiffSets();
                        AddLabelEntriesTo(nodeId, labels.Added, _assignedLabels);
                        AddLabelEntriesTo(nodeId, labels.Removed, _removedLabels);
                    }
                    foreach (RelationshipState relState in _state.modifiedRelationships())
                    {
                        Relationship relationshipProxy      = relationship(relState.Id);
                        IEnumerator <StorageProperty> added = relState.AddedAndChangedProperties();
                        while (added.MoveNext())
                        {
                            StorageProperty property = added.Current;
                            _assignedRelationshipProperties.Add(new RelationshipPropertyEntryView(relationshipProxy, tokenRead.PropertyKeyName(property.PropertyKeyId()), property.Value(), CommittedValue(relState, property.PropertyKeyId(), relationship, properties)));
                        }
                        relState.RemovedProperties().each(id =>
                        {
                            try
                            {
                                RelationshipPropertyEntryView entryView = new RelationshipPropertyEntryView(relationshipProxy, tokenRead.PropertyKeyName(id), null, CommittedValue(relState, id, relationship, properties));
                                _removedRelationshipProperties.Add(entryView);
                            }
                            catch (PropertyKeyIdNotFoundKernelException e)
                            {
                                throw new System.InvalidOperationException("Nonexisting properties was modified for relationship " + relState.Id, e);
                            }
                        });
                    }
                }
            }
            catch (PropertyKeyIdNotFoundKernelException e)
            {
                throw new System.InvalidOperationException("An entity that does not exist was modified.", e);
            }
        }
Ejemplo n.º 9
0
        internal static AddedWithValuesAndRemoved IndexUpdatesWithValuesForRangeSeek <T1>(ReadableTransactionState txState, IndexDescriptor descriptor, IndexQuery.RangePredicate <T1> predicate, IndexOrder indexOrder)
        {
            Value lower = predicate.FromValue();
            Value upper = predicate.ToValue();

            if (lower == null || upper == null)
            {
                throw new System.InvalidOperationException("Use Values.NO_VALUE to encode the lack of a bound");
            }

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.NavigableMap<org.neo4j.values.storable.ValueTuple, ? extends org.neo4j.storageengine.api.txstate.LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
            NavigableMap <ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.GetSortedIndexUpdates(descriptor.Schema());

            if (sortedUpdates == null)
            {
                return(_emptyAddedAndRemovedWithValues);
            }

            ValueTuple selectedLower;
            bool       selectedIncludeLower;

            ValueTuple selectedUpper;
            bool       selectedIncludeUpper;

            if (lower == NO_VALUE)
            {
                selectedLower        = ValueTuple.of(Values.minValue(predicate.ValueGroup(), upper));
                selectedIncludeLower = true;
            }
            else
            {
                selectedLower        = ValueTuple.of(lower);
                selectedIncludeLower = predicate.FromInclusive();
            }

            if (upper == NO_VALUE)
            {
                selectedUpper        = ValueTuple.of(Values.maxValue(predicate.ValueGroup(), lower));
                selectedIncludeUpper = false;
            }
            else
            {
                selectedUpper        = ValueTuple.of(upper);
                selectedIncludeUpper = predicate.ToInclusive();
            }

            MutableList <NodeWithPropertyValues> added = Lists.mutable.empty();
            MutableLongSet removed = LongSets.mutable.empty();

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.Map<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper);
            IDictionary <ValueTuple, ? extends LongDiffSets> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.Map.Entry<org.neo4j.values.storable.ValueTuple,? extends org.neo4j.storageengine.api.txstate.LongDiffSets> entry : inRange.entrySet())
            foreach (KeyValuePair <ValueTuple, ? extends LongDiffSets> entry in inRange.SetOfKeyValuePairs())
            {
                ValueTuple   values               = entry.Key;
                Value[]      valuesArray          = values.Values;
                LongDiffSets diffForSpecificValue = entry.Value;

                // The TreeMap cannot perfectly order multi-dimensional types (spatial) and need additional filtering out false positives
                // TODO: If the composite index starts to be able to handle spatial types the line below needs enhancement
                if (predicate.RegularOrder || predicate.AcceptsValue(values.OnlyValue))
                {
                    diffForSpecificValue.Added.each(nodeId => added.add(new NodeWithPropertyValues(nodeId, valuesArray)));
                    removed.addAll(diffForSpecificValue.Removed);
                }
            }
            return(new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed));
        }