Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean process(org.neo4j.storageengine.api.StorageNodeCursor cursor) throws FAILURE
        public override bool Process(StorageNodeCursor cursor)
        {
            long[] labels = cursor.Labels();
            if (labels.Length == 0 && LabelIds.Length != 0)
            {
                // This node has no labels at all
                return(false);
            }

            if (_labelUpdateVisitor != null)
            {
                // Notify the label update visitor
                _labelUpdateVisitor.visit(labelChanges(cursor.EntityReference(), EMPTY_LONG_ARRAY, labels));
            }

            if (_propertyUpdatesVisitor != null && containsAnyEntityToken(LabelIds, labels))
            {
                // Notify the property update visitor
                EntityUpdates.Builder updates = EntityUpdates.forEntity(cursor.EntityReference(), true).withTokens(labels);

                if (hasRelevantProperty(cursor, updates))
                {
                    return(_propertyUpdatesVisitor.visit(updates.Build()));
                }
            }
            return(false);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void processAllNodeProperties() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ProcessAllNodeProperties()
        {
            CopyUpdateVisitor      propertyUpdateVisitor  = new CopyUpdateVisitor();
            StoreViewNodeStoreScan storeViewNodeStoreScan = new StoreViewNodeStoreScan(new RecordStorageReader(_neoStores), _locks, null, propertyUpdateVisitor, new int[] { _labelId }, id => true);

            using (StorageNodeCursor nodeCursor = _reader.allocateNodeCursor())
            {
                nodeCursor.Single(1);
                nodeCursor.Next();

                storeViewNodeStoreScan.process(nodeCursor);
            }

            EntityUpdates propertyUpdates = propertyUpdateVisitor.PropertyUpdates;

            assertNotNull("Visitor should contain container with updates.", propertyUpdates);

            LabelSchemaDescriptor         index1  = SchemaDescriptorFactory.forLabel(0, 0);
            LabelSchemaDescriptor         index2  = SchemaDescriptorFactory.forLabel(0, 1);
            LabelSchemaDescriptor         index3  = SchemaDescriptorFactory.forLabel(0, 0, 1);
            LabelSchemaDescriptor         index4  = SchemaDescriptorFactory.forLabel(1, 1);
            IList <LabelSchemaDescriptor> indexes = Arrays.asList(index1, index2, index3, index4);

//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertThat(Iterables.map(IndexEntryUpdate::indexKey, propertyUpdates.ForIndexKeys(indexes)), containsInAnyOrder(index1, index2, index3));
        }
Esempio n. 3
0
        private void TestDegreesForDenseNodeWithPartiallyDeletedRelChains(bool modifyInChain, bool modifyOutChain, bool modifyLoopChain)
        {
            int inRelCount   = RandomRelCount();
            int outRelCount  = RandomRelCount();
            int loopRelCount = RandomRelCount();

            long nodeId = CreateNode(inRelCount, outRelCount, loopRelCount);
            StorageNodeCursor cursor = NewCursor(nodeId);

            if (modifyInChain)
            {
                MarkRandomRelsInGroupNotInUse(nodeId, IN);
            }
            if (modifyOutChain)
            {
                MarkRandomRelsInGroupNotInUse(nodeId, OUT);
            }
            if (modifyLoopChain)
            {
                MarkRandomRelsInGroupNotInUse(nodeId, LOOP);
            }

            ISet <TestDegreeItem> expectedDegrees = new HashSet <TestDegreeItem>(asList(new TestDegreeItem(RelTypeId(OUT), outRelCount, 0), new TestDegreeItem(RelTypeId(IN), 0, inRelCount), new TestDegreeItem(RelTypeId(LOOP), loopRelCount, loopRelCount)));

            ISet <TestDegreeItem> actualDegrees = Degrees(cursor);

            assertEquals(expectedDegrees, actualDegrees);
        }
Esempio n. 4
0
        private void TestDegreeByDirectionAndTypeForDenseNodeWithPartiallyDeletedRelChains(bool modifyInChain, bool modifyOutChain, bool modifyLoopChain)
        {
            int inRelCount   = RandomRelCount();
            int outRelCount  = RandomRelCount();
            int loopRelCount = RandomRelCount();

            long nodeId = CreateNode(inRelCount, outRelCount, loopRelCount);
            StorageNodeCursor cursor = NewCursor(nodeId);

            if (modifyInChain)
            {
                MarkRandomRelsInGroupNotInUse(nodeId, IN);
            }
            if (modifyOutChain)
            {
                MarkRandomRelsInGroupNotInUse(nodeId, OUT);
            }
            if (modifyLoopChain)
            {
                MarkRandomRelsInGroupNotInUse(nodeId, LOOP);
            }

            assertEquals(0, DegreeForDirectionAndType(cursor, OUTGOING, RelTypeId(IN)));
            assertEquals(outRelCount, DegreeForDirectionAndType(cursor, OUTGOING, RelTypeId(OUT)));
            assertEquals(loopRelCount, DegreeForDirectionAndType(cursor, OUTGOING, RelTypeId(LOOP)));

            assertEquals(0, DegreeForDirectionAndType(cursor, INCOMING, RelTypeId(OUT)));
            assertEquals(inRelCount, DegreeForDirectionAndType(cursor, INCOMING, RelTypeId(IN)));
            assertEquals(loopRelCount, DegreeForDirectionAndType(cursor, INCOMING, RelTypeId(LOOP)));

            assertEquals(inRelCount, DegreeForDirectionAndType(cursor, RelationshipDirection.LOOP, RelTypeId(IN)));
            assertEquals(outRelCount, DegreeForDirectionAndType(cursor, RelationshipDirection.LOOP, RelTypeId(OUT)));
            assertEquals(loopRelCount, DegreeForDirectionAndType(cursor, RelationshipDirection.LOOP, RelTypeId(LOOP)));
        }
Esempio n. 5
0
        private int DegreeForDirectionAndType(StorageNodeCursor cursor, RelationshipDirection direction, int relType)
        {
            int degree = 0;

            using (StorageRelationshipGroupCursor groups = StorageReader.allocateRelationshipGroupCursor())
            {
                groups.Init(cursor.EntityReference(), cursor.RelationshipGroupReference());
                while (groups.Next())
                {
                    if (relType == ANY_RELATIONSHIP_TYPE || relType == groups.Type())
                    {
                        switch (direction)
                        {
                        case RelationshipDirection.OUTGOING:
                            degree += groups.OutgoingCount() + groups.LoopCount();
                            break;

                        case RelationshipDirection.INCOMING:
                            degree += groups.IncomingCount() + groups.LoopCount();
                            break;

                        case RelationshipDirection.LOOP:
                            degree += groups.OutgoingCount() + groups.IncomingCount() + groups.LoopCount();
                            break;

                        default:
                            throw new System.ArgumentException(direction.name());
                        }
                    }
                }
            }
            return(degree);
        }
Esempio n. 6
0
        private void TestDegreeByDirectionForDenseNodeWithPartiallyDeletedRelGroupChain(params TestRelType[] typesToDelete)
        {
            int inRelCount   = RandomRelCount();
            int outRelCount  = RandomRelCount();
            int loopRelCount = RandomRelCount();

            long nodeId = CreateNode(inRelCount, outRelCount, loopRelCount);
            StorageNodeCursor cursor = NewCursor(nodeId);

            foreach (TestRelType type in typesToDelete)
            {
                MarkRelGroupNotInUse(nodeId, type);
                switch (type)
                {
                case Org.Neo4j.Kernel.impl.storageengine.impl.recordstorage.TestRelType.In:
                    inRelCount = 0;
                    break;

                case Org.Neo4j.Kernel.impl.storageengine.impl.recordstorage.TestRelType.Out:
                    outRelCount = 0;
                    break;

                case Org.Neo4j.Kernel.impl.storageengine.impl.recordstorage.TestRelType.Loop:
                    loopRelCount = 0;
                    break;

                default:
                    throw new System.ArgumentException("Unknown type: " + type);
                }
            }

            assertEquals(outRelCount + loopRelCount, DegreeForDirection(cursor, OUTGOING));
            assertEquals(inRelCount + loopRelCount, DegreeForDirection(cursor, INCOMING));
            assertEquals(inRelCount + outRelCount + loopRelCount, DegreeForDirection(cursor, RelationshipDirection.LOOP));
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private org.neo4j.storageengine.api.StorageNodeCursor newCursor(long nodeId)
        private StorageNodeCursor NewCursor(long nodeId)
        {
            StorageNodeCursor nodeCursor = StorageReader.allocateNodeCursor();

            nodeCursor.Single(nodeId);
            assertTrue(nodeCursor.Next());
            return(nodeCursor);
        }
Esempio n. 8
0
        private ISet <TestDegreeItem> Degrees(StorageNodeCursor nodeCursor)
        {
            ISet <TestDegreeItem> degrees = new HashSet <TestDegreeItem>();

            using (StorageRelationshipGroupCursor groups = StorageReader.allocateRelationshipGroupCursor())
            {
                groups.Init(nodeCursor.EntityReference(), nodeCursor.RelationshipGroupReference());
                while (groups.Next())
                {
                    degrees.Add(new TestDegreeItem(groups.Type(), groups.OutgoingCount() + groups.LoopCount(), groups.IncomingCount() + groups.LoopCount()));
                }
            }
            return(degrees);
        }
Esempio n. 9
0
        private void TestDegreesForDenseNodeWithPartiallyDeletedRelGroupChain(params TestRelType[] typesToDelete)
        {
            int inRelCount   = RandomRelCount();
            int outRelCount  = RandomRelCount();
            int loopRelCount = RandomRelCount();

            long nodeId = CreateNode(inRelCount, outRelCount, loopRelCount);
            StorageNodeCursor cursor = NewCursor(nodeId);

            foreach (TestRelType type in typesToDelete)
            {
                MarkRelGroupNotInUse(nodeId, type);
                switch (type)
                {
                case Org.Neo4j.Kernel.impl.storageengine.impl.recordstorage.TestRelType.In:
                    inRelCount = 0;
                    break;

                case Org.Neo4j.Kernel.impl.storageengine.impl.recordstorage.TestRelType.Out:
                    outRelCount = 0;
                    break;

                case Org.Neo4j.Kernel.impl.storageengine.impl.recordstorage.TestRelType.Loop:
                    loopRelCount = 0;
                    break;

                default:
                    throw new System.ArgumentException("Unknown type: " + type);
                }
            }

            ISet <TestDegreeItem> expectedDegrees = new HashSet <TestDegreeItem>();

            if (outRelCount != 0)
            {
                expectedDegrees.Add(new TestDegreeItem(RelTypeId(OUT), outRelCount, 0));
            }
            if (inRelCount != 0)
            {
                expectedDegrees.Add(new TestDegreeItem(RelTypeId(IN), 0, inRelCount));
            }
            if (loopRelCount != 0)
            {
                expectedDegrees.Add(new TestDegreeItem(RelTypeId(LOOP), loopRelCount, loopRelCount));
            }

            ISet <TestDegreeItem> actualDegrees = Degrees(cursor);

            assertEquals(expectedDegrees, actualDegrees);
        }
Esempio n. 10
0
        private ISet <TestRelType> RelTypes(StorageNodeCursor cursor)
        {
            ISet <TestRelType> types = new HashSet <TestRelType>();

            using (StorageRelationshipGroupCursor groups = StorageReader.allocateRelationshipGroupCursor())
            {
                groups.Init(cursor.EntityReference(), cursor.RelationshipGroupReference());
                while (groups.Next())
                {
                    types.Add(RelTypeForId(groups.Type()));
                }
            }
            return(types);
        }
Esempio n. 11
0
        private void TestRelationshipTypesForDenseNode(System.Action <long> nodeChanger, ISet <TestRelType> expectedTypes)
        {
            int inRelCount   = RandomRelCount();
            int outRelCount  = RandomRelCount();
            int loopRelCount = RandomRelCount();

            long nodeId = CreateNode(inRelCount, outRelCount, loopRelCount);

            nodeChanger(nodeId);

            StorageNodeCursor cursor = NewCursor(nodeId);

            assertEquals(expectedTypes, RelTypes(cursor));
        }
        private Value CommittedValue(NodeState nodeState, int property, StorageNodeCursor node, StoragePropertyCursor properties)
        {
            if (_state.nodeIsAddedInThisTx(nodeState.Id))
            {
                return(Values.NO_VALUE);
            }

            node.Single(nodeState.Id);
            if (!node.Next())
            {
                return(Values.NO_VALUE);
            }

            return(CommittedValue(properties, node.PropertiesReference(), property));
        }
Esempio n. 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGetAllNodeProperties()
        public virtual void ShouldGetAllNodeProperties()
        {
            // GIVEN
            string longString = "AlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalong";

            object[] properties = new object[] { longString, CreateNew(typeof(string)), CreateNew(typeof(long)), CreateNew(typeof(int)), CreateNew(typeof(sbyte)), CreateNew(typeof(short)), CreateNew(typeof(bool)), CreateNew(typeof(char)), CreateNew(typeof(float)), CreateNew(typeof(double)), Array(0, typeof(string)), Array(0, typeof(long)), Array(0, typeof(int)), Array(0, typeof(sbyte)), Array(0, typeof(short)), Array(0, typeof(bool)), Array(0, typeof(char)), Array(0, typeof(float)), Array(0, typeof(double)), Array(1, typeof(string)), Array(1, typeof(long)), Array(1, typeof(int)), Array(1, typeof(sbyte)), Array(1, typeof(short)), Array(1, typeof(bool)), Array(1, typeof(char)), Array(1, typeof(float)), Array(1, typeof(double)), Array(256, typeof(string)), Array(256, typeof(long)), Array(256, typeof(int)), Array(256, typeof(sbyte)), Array(256, typeof(short)), Array(256, typeof(bool)), Array(256, typeof(char)), Array(256, typeof(float)), Array(256, typeof(double)) };

            foreach (object value in properties)
            {
                // given
                long nodeId = CreateLabeledNode(Db, singletonMap("prop", value), Label1).Id;

                // when
                using (StorageNodeCursor node = StorageReader.allocateNodeCursor())
                {
                    node.Single(nodeId);
                    assertTrue(node.Next());

                    using (StoragePropertyCursor props = StorageReader.allocatePropertyCursor())
                    {
                        props.Init(node.PropertiesReference());
                        if (props.Next())
                        {
                            Value propVal = props.PropertyValue();

                            //then
                            assertTrue(propVal + ".equals(" + value + ")", propVal.Equals(Values.of(value)));
                        }
                        else
                        {
                            fail();
                        }
                    }
                }
            }
        }
Esempio n. 14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean process(org.neo4j.storageengine.api.StorageNodeCursor cursor) throws FAILURE
            public override bool Process(StorageNodeCursor cursor)
            {
                ProcessListener.receive(cursor);
                return(base.Process(cursor));
            }
        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);
            }
        }
Esempio n. 16
0
 private int DegreeForDirection(StorageNodeCursor cursor, RelationshipDirection direction)
 {
     return(DegreeForDirectionAndType(cursor, direction, ANY_RELATIONSHIP_TYPE));
 }