Пример #1
0
        public virtual int getDegree(Direction direction)
        {
            KernelTransaction transaction = SafeAcquireTransaction();

            using (Statement ignore = transaction.AcquireStatement())
            {
                NodeCursor nodes = transaction.AmbientNodeCursor();
                SingleNode(transaction, nodes);

                switch (direction.innerEnumValue)
                {
                case Direction.InnerEnum.OUTGOING:
                    return(Nodes.countOutgoing(nodes, transaction.Cursors()));

                case Direction.InnerEnum.INCOMING:
                    return(Nodes.countIncoming(nodes, transaction.Cursors()));

                case Direction.InnerEnum.BOTH:
                    return(Nodes.countAll(nodes, transaction.Cursors()));

                default:
                    throw new System.InvalidOperationException("Unknown direction " + direction);
                }
            }
        }
Пример #2
0
        public override bool HasProperty(string key)
        {
            if (null == key)
            {
                return(false);
            }

            KernelTransaction transaction = SafeAcquireTransaction();
            int propertyKey = transaction.TokenRead().propertyKey(key);

            if (propertyKey == [email protected]_Fields.NO_TOKEN)
            {
                return(false);
            }

            NodeCursor     nodes      = transaction.AmbientNodeCursor();
            PropertyCursor properties = transaction.AmbientPropertyCursor();

            SingleNode(transaction, nodes);
            nodes.Properties(properties);
            while (properties.Next())
            {
                if (propertyKey == properties.PropertyKey())
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        internal virtual IEnumerator <long> NodeGetRelationships(Transaction transaction, long node, Direction direction, int[] types)
        {
            NodeCursor cursor = transaction.Cursors().allocateNodeCursor();

            transaction.DataRead().singleNode(node, cursor);
            if (!cursor.Next())
            {
                return(emptyIterator());
            }

            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(outgoingIterator(transaction.Cursors(), cursor, types, (id, startNodeId, typeId, endNodeId) => id));

            case Direction.InnerEnum.INCOMING:
                return(incomingIterator(transaction.Cursors(), cursor, types, (id, startNodeId, typeId, endNodeId) => id));

            case Direction.InnerEnum.BOTH:
                return(allIterator(transaction.Cursors(), cursor, types, (id, startNodeId, typeId, endNodeId) => id));

            default:
                throw new System.InvalidOperationException(direction + " is not a valid direction");
            }
        }
Пример #4
0
        public virtual int getDegree(RelationshipType type, Direction direction)
        {
            KernelTransaction transaction = SafeAcquireTransaction();
            int typeId = transaction.TokenRead().relationshipType(type.Name());

            if (typeId == NO_TOKEN)
            {               // This type doesn't even exist. Return 0
                return(0);
            }

            using (Statement ignore = transaction.AcquireStatement())
            {
                NodeCursor nodes = transaction.AmbientNodeCursor();
                SingleNode(transaction, nodes);
                switch (direction.innerEnumValue)
                {
                case Direction.InnerEnum.OUTGOING:
                    return(Nodes.countOutgoing(nodes, transaction.Cursors(), typeId));

                case Direction.InnerEnum.INCOMING:
                    return(Nodes.countIncoming(nodes, transaction.Cursors(), typeId));

                case Direction.InnerEnum.BOTH:
                    return(Nodes.countAll(nodes, transaction.Cursors(), typeId));

                default:
                    throw new System.InvalidOperationException("Unknown direction " + direction);
                }
            }
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeNewNodePropertyInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeNewNodePropertyInTransaction()
        {
            long   nodeId;
            string propKey1 = "prop1";
            string propKey2 = "prop2";

            using (Transaction tx = beginTransaction())
            {
                nodeId = tx.DataWrite().nodeCreate();
                int prop1 = tx.Token().propertyKeyGetOrCreateForName(propKey1);
                int prop2 = tx.Token().propertyKeyGetOrCreateForName(propKey2);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, prop1, stringValue("hello")), NO_VALUE);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, prop2, stringValue("world")), NO_VALUE);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    node.Properties(property);
                    assertTrue(property.Next());
                    //First property
                    assertEquals(prop1, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("hello"));
                    //second property
                    assertTrue(property.Next());
                    assertEquals(prop2, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("world"));

                    assertFalse("should only find two properties", property.Next());
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }
        }
Пример #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void propertyTypeShouldBeTxStateAware() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PropertyTypeShouldBeTxStateAware()
        {
            // Given
            long node;

            using (Transaction tx = beginTransaction())
            {
                node = tx.DataWrite().nodeCreate();
                tx.Success();
            }

            // Then
            using (Transaction tx = beginTransaction())
            {
                using (NodeCursor nodes = tx.Cursors().allocateNodeCursor(), PropertyCursor properties = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(node, nodes);
                    assertTrue(nodes.Next());
                    assertFalse(HasProperties(nodes, properties));
                    int prop = tx.TokenWrite().propertyKeyGetOrCreateForName("prop");
                    tx.DataWrite().nodeSetProperty(node, prop, stringValue("foo"));
                    nodes.Properties(properties);

                    assertTrue(properties.Next());
                    assertThat(properties.PropertyType(), equalTo(ValueGroup.TEXT));
                }
            }
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeNewLabeledNodeInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeNewLabeledNodeInTransaction()
        {
            long         nodeId;
            int          labelId;
            const string labelName = "Town";

            using (Transaction tx = beginTransaction())
            {
                nodeId  = tx.DataWrite().nodeCreate();
                labelId = tx.Token().labelGetOrCreateForName(labelName);
                tx.DataWrite().nodeAddLabel(nodeId, labelId);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    LabelSet labels = node.Labels();
                    assertEquals(1, labels.NumberOfLabels());
                    assertEquals(labelId, labels.Label(0));
                    assertTrue(node.HasLabel(labelId));
                    assertFalse(node.HasLabel(labelId + 1));
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, equalTo(Iterables.iterable(label(labelName))));
            }
        }
Пример #8
0
        private ResourceIterator <Relationship> GetRelationshipSelectionIterator(KernelTransaction transaction, Direction direction, int[] typeIds)
        {
            NodeCursor node = transaction.AmbientNodeCursor();

            transaction.DataRead().singleNode(Id, node);
            if (!node.Next())
            {
                throw new NotFoundException(format("Node %d not found", _nodeId));
            }

            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(outgoingIterator(transaction.Cursors(), node, typeIds, this));

            case Direction.InnerEnum.INCOMING:
                return(incomingIterator(transaction.Cursors(), node, typeIds, this));

            case Direction.InnerEnum.BOTH:
                return(allIterator(transaction.Cursors(), node, typeIds, this));

            default:
                throw new System.InvalidOperationException("Unknown direction " + direction);
            }
        }
Пример #9
0
 /// <summary>
 /// Counts the number of incoming relationships from node where the cursor is positioned.
 /// <para>
 /// NOTE: The number of incoming relationships also includes eventual loops.
 ///
 /// </para>
 /// </summary>
 /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param>
 /// <param name="cursors"> a factory for cursors </param>
 /// <returns> the number of incoming - including loops - relationships from the node </returns>
 public static int CountIncoming(NodeCursor nodeCursor, CursorFactory cursors)
 {
     if (nodeCursor.Dense)
     {
         using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor())
         {
             nodeCursor.Relationships(group);
             int count = 0;
             while (group.next())
             {
                 count += group.IncomingCount() + group.LoopCount();
             }
             return(count);
         }
     }
     else
     {
         using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor())
         {
             int count = 0;
             nodeCursor.AllRelationships(traversal);
             while (traversal.next())
             {
                 if (traversal.TargetNodeReference() == nodeCursor.NodeReference())
                 {
                     count++;
                 }
             }
             return(count);
         }
     }
 }
Пример #10
0
 /// <summary>
 /// Counts all the relationships of the given type from node where the cursor is positioned.
 /// </summary>
 /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param>
 /// <param name="cursors"> a factory for cursors </param>
 /// <param name="type"> the type of the relationship we're counting </param>
 /// <returns> the number relationships from the node with the given type </returns>
 public static int CountAll(NodeCursor nodeCursor, CursorFactory cursors, int type)
 {
     if (nodeCursor.Dense)
     {
         using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor())
         {
             nodeCursor.Relationships(group);
             int count = 0;
             while (group.next())
             {
                 if (group.Type() == type)
                 {
                     return(group.TotalCount());
                 }
             }
             return(count);
         }
     }
     else
     {
         using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor())
         {
             int count = 0;
             nodeCursor.AllRelationships(traversal);
             while (traversal.next())
             {
                 if (traversal.Type() == type)
                 {
                     count++;
                 }
             }
             return(count);
         }
     }
 }
Пример #11
0
 /// <summary>
 /// Counts the number of outgoing relationships of the given type from node where the cursor is positioned.
 /// <para>
 /// NOTE: The number of outgoing relationships also includes eventual loops.
 ///
 /// </para>
 /// </summary>
 /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param>
 /// <param name="cursors"> a factory for cursors </param>
 /// <param name="type"> the type of the relationship we're counting </param>
 /// <returns> the number of outgoing - including loops - relationships from the node with the given type </returns>
 public static int CountOutgoing(NodeCursor nodeCursor, CursorFactory cursors, int type)
 {
     if (nodeCursor.Dense)
     {
         using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor())
         {
             nodeCursor.Relationships(group);
             while (group.next())
             {
                 if (group.Type() == type)
                 {
                     return(group.OutgoingCount() + group.LoopCount());
                 }
             }
             return(0);
         }
     }
     else
     {
         using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor())
         {
             int count = 0;
             nodeCursor.AllRelationships(traversal);
             while (traversal.next())
             {
                 if (traversal.SourceNodeReference() == nodeCursor.NodeReference() && traversal.Type() == type)
                 {
                     count++;
                 }
             }
             return(count);
         }
     }
 }
Пример #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Object getProperty(String key) throws org.neo4j.graphdb.NotFoundException
        public override object GetProperty(string key)
        {
            if (null == key)
            {
                throw new System.ArgumentException("(null) property key is not allowed");
            }
            KernelTransaction transaction = SafeAcquireTransaction();
            int propertyKey = transaction.TokenRead().propertyKey(key);

            if (propertyKey == [email protected]_Fields.NO_TOKEN)
            {
                throw new NotFoundException(format("No such property, '%s'.", key));
            }

            NodeCursor     nodes      = transaction.AmbientNodeCursor();
            PropertyCursor properties = transaction.AmbientPropertyCursor();

            SingleNode(transaction, nodes);
            nodes.Properties(properties);
            while (properties.Next())
            {
                if (propertyKey == properties.PropertyKey())
                {
                    Value value = properties.PropertyValue();
                    if (value == Values.NO_VALUE)
                    {
                        throw new NotFoundException(format("No such property, '%s'.", key));
                    }
                    return(value.AsObjectCopy());
                }
            }
            throw new NotFoundException(format("No such property, '%s'.", key));
        }
Пример #13
0
        public override NodeCursor AllocateNodeCursor()
        {
            NodeCursor n = _cursors.allocateNodeCursor();

            _allCursors.Add(n);
            return(n);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void traverseViaGroups(RelationshipTestSupport.StartNode start, boolean detached) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void TraverseViaGroups(RelationshipTestSupport.StartNode start, bool detached)
        {
            // given
            IDictionary <string, int> expectedCounts = start.ExpectedCounts();

            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                // when
                read.singleNode(start.Id, node);
                assertTrue("access node", node.Next());
                if (detached)
                {
                    read.relationshipGroups(start.Id, node.RelationshipGroupReference(), group);
                }
                else
                {
                    node.Relationships(group);
                }

                while (group.next())
                {
                    // outgoing
                    if (detached)
                    {
                        read.relationships(start.Id, group.OutgoingReference(), relationship);
                    }
                    else
                    {
                        group.Outgoing(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), OUTGOING);

                    // incoming
                    if (detached)
                    {
                        read.relationships(start.Id, group.IncomingReference(), relationship);
                    }
                    else
                    {
                        group.Incoming(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), INCOMING);

                    // loops
                    if (detached)
                    {
                        read.relationships(start.Id, group.LoopsReference(), relationship);
                    }
                    else
                    {
                        group.Loops(relationship);
                    }
                    // then
                    assertCount(tx, relationship, expectedCounts, group.Type(), BOTH);
                }
            }
        }
 internal virtual FulltextIndexTransactionStateVisitor Init(AllStoreHolder read, NodeCursor nodeCursor, RelationshipScanCursor relationshipCursor, PropertyCursor propertyCursor)
 {
     this._read               = read;
     this._nodeCursor         = nodeCursor;
     this._relationshipCursor = relationshipCursor;
     this._propertyCursor     = propertyCursor;
     return(this);
 }
Пример #16
0
 internal NodeValueClientFilter(IndexProgressor_NodeValueClient target, NodeCursor node, PropertyCursor property, Read read, params IndexQuery[] filters)
 {
     this._target   = target;
     this._node     = node;
     this._property = property;
     this._filters  = filters;
     this._read     = read;
 }
Пример #17
0
 private void SingleNode(KernelTransaction transaction, NodeCursor nodes)
 {
     transaction.DataRead().singleNode(_nodeId, nodes);
     if (!nodes.Next())
     {
         throw new NotFoundException(new EntityNotFoundException(EntityType.NODE, _nodeId));
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFollowSpecificRelationship()
        public virtual void ShouldFollowSpecificRelationship()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                // when - traversing from start to end
                read.singleNode(_start, node);
                assertTrue("access start node", node.Next());
                node.Relationships(group);
                assertTrue("access relationship group", group.next());
                group.Outgoing(relationship);
                assertTrue("access outgoing relationships", relationship.next());

                // then
                assertEquals("source node", _start, relationship.SourceNodeReference());
                assertEquals("target node", _end, relationship.TargetNodeReference());

                assertEquals("node of origin", _start, relationship.OriginNodeReference());
                assertEquals("neighbouring node", _end, relationship.NeighbourNodeReference());

                assertEquals("relationship should have same label as group", group.Type(), relationship.Type());

                assertFalse("only a single relationship", relationship.next());

                group.Incoming(relationship);
                assertFalse("no incoming relationships", relationship.next());
                group.Loops(relationship);
                assertFalse("no loop relationships", relationship.next());

                assertFalse("only a single group", group.next());

                // when - traversing from end to start
                read.singleNode(_end, node);
                assertTrue("access start node", node.Next());
                node.Relationships(group);
                assertTrue("access relationship group", group.next());
                group.Incoming(relationship);
                assertTrue("access incoming relationships", relationship.next());

                // then
                assertEquals("source node", _start, relationship.SourceNodeReference());
                assertEquals("target node", _end, relationship.TargetNodeReference());

                assertEquals("node of origin", _end, relationship.OriginNodeReference());
                assertEquals("neighbouring node", _start, relationship.NeighbourNodeReference());

                assertEquals("relationship should have same label as group", group.Type(), relationship.Type());

                assertFalse("only a single relationship", relationship.next());

                group.Outgoing(relationship);
                assertFalse("no outgoing relationships", relationship.next());
                group.Loops(relationship);
                assertFalse("no loop relationships", relationship.next());

                assertFalse("only a single group", group.next());
            }
        }
Пример #19
0
        private void ScanEverythingBelongingToNodes(NodeMappings nodeMappings)
        {
            using (NodeCursor nodeCursor = _cursors.allocateNodeCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor())
            {
                _dataRead.allNodesScan(nodeCursor);
                while (nodeCursor.Next())
                {
                    // each node
                    SortedLabels labels = SortedLabels.From(nodeCursor.Labels());
                    nodeCursor.Properties(propertyCursor);
                    MutableIntSet propertyIds = IntSets.mutable.empty();

                    while (propertyCursor.Next())
                    {
                        Value currentValue           = propertyCursor.PropertyValue();
                        int   propertyKeyId          = propertyCursor.PropertyKey();
                        Pair <SortedLabels, int> key = Pair.of(labels, propertyKeyId);
                        UpdateValueTypeInMapping(currentValue, key, nodeMappings.LabelSetANDNodePropertyKeyIdToValueType);

                        propertyIds.add(propertyKeyId);
                    }
                    propertyCursor.Close();

                    MutableIntSet oldPropertyKeySet = nodeMappings.LabelSetToPropertyKeys.getOrDefault(labels, _emptyPropertyIdSet);

                    // find out which old properties we did not visited and mark them as nullable
                    if (oldPropertyKeySet == _emptyPropertyIdSet)
                    {
                        if (propertyIds.size() == 0)
                        {
                            // Even if we find property key on other nodes with those labels, set all of them nullable
                            nodeMappings.NullableLabelSets.Add(labels);
                        }

                        propertyIds.addAll(oldPropertyKeySet);
                    }
                    else
                    {
                        MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
                        currentPropertyIdsHelperSet.addAll(propertyIds);
                        propertyIds.removeAll(oldPropertyKeySet);                                     // only the brand new ones in propIds now
                        oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);                     // only the old ones that are not on the new node

                        propertyIds.addAll(oldPropertyKeySet);
                        propertyIds.forEach(id =>
                        {
                            Pair <SortedLabels, int> key = Pair.of(labels, id);
                            nodeMappings.LabelSetANDNodePropertyKeyIdToValueType[key].setNullable();
                        });

                        propertyIds.addAll(currentPropertyIdsHelperSet);
                    }

                    nodeMappings.LabelSetToPropertyKeys[labels] = propertyIds;
                }
                nodeCursor.Close();
            }
        }
            internal override void SetItem(ref NodeCursor cursor, T item)
            {
#if DEBUG
                if (ContainsLocal(cursor.LocalIndex) == false)
                {
                    throw new IndexOutOfRangeException();
                }
#endif
                Span[cursor.LocalIndex] = item;
            }
Пример #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowManyLabelsAndPropertyCursor()
        public virtual void ShouldAllowManyLabelsAndPropertyCursor()
        {
            int propertyCount = 10;
            int labelCount    = 15;

            GraphDatabaseAPI db = DbRule.GraphDatabaseAPI;
            Node             node;

            using (Transaction tx = Db.beginTx())
            {
                node = Db.createNode();
                for (int i = 0; i < propertyCount; i++)
                {
                    node.SetProperty("foo" + i, "bar");
                }
                for (int i = 0; i < labelCount; i++)
                {
                    node.AddLabel(label("label" + i));
                }
                tx.Success();
            }

            ISet <int> seenProperties = new HashSet <int>();
            ISet <int> seenLabels     = new HashSet <int>();

            using (Transaction tx = Db.beginTx())
            {
                DependencyResolver             resolver = Db.DependencyResolver;
                ThreadToStatementContextBridge bridge   = resolver.ResolveDependency(typeof(ThreadToStatementContextBridge));
                KernelTransaction ktx = bridge.GetKernelTransactionBoundToThisThread(true);
                using (NodeCursor nodes = ktx.Cursors().allocateNodeCursor(), PropertyCursor propertyCursor = ktx.Cursors().allocatePropertyCursor())
                {
                    ktx.DataRead().singleNode(node.Id, nodes);
                    while (nodes.Next())
                    {
                        nodes.Properties(propertyCursor);
                        while (propertyCursor.Next())
                        {
                            seenProperties.Add(propertyCursor.PropertyKey());
                        }

                        LabelSet labels = nodes.Labels();
                        for (int i = 0; i < labels.NumberOfLabels(); i++)
                        {
                            seenLabels.Add(labels.Label(i));
                        }
                    }
                }
                tx.Success();
            }

            assertEquals(propertyCount, seenProperties.Count);
            assertEquals(labelCount, seenLabels.Count);
        }
            internal override T GetItem(ref NodeCursor cursor)
            {
#if DEBUG
                if (ContainsLocal(cursor.LocalIndex) == false)
                {
                    throw new IndexOutOfRangeException();
                }
#endif

                return(Span[cursor.LocalIndex]);
            }
Пример #23
0
        private RealizedNode EnsureRealizedNode(ref NodeCursor cursor, long index, bool insert)
        {
            if (cursor.Node is RealizedNode realizedNode)
            {
                return(realizedNode);
            }

            realizedNode = RealizeNode(ref cursor, index, insert);

            return(realizedNode);
        }
Пример #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeLabelChangesInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeLabelChangesInTransaction()
        {
            long         nodeId;
            int          toRetain, toDelete, toAdd, toRegret;
            const string toRetainName = "ToRetain";
            const string toDeleteName = "ToDelete";
            const string toAddName    = "ToAdd";
            const string toRegretName = "ToRegret";

            using (Transaction tx = beginTransaction())
            {
                nodeId   = tx.DataWrite().nodeCreate();
                toRetain = tx.Token().labelGetOrCreateForName(toRetainName);
                toDelete = tx.Token().labelGetOrCreateForName(toDeleteName);
                tx.DataWrite().nodeAddLabel(nodeId, toRetain);
                tx.DataWrite().nodeAddLabel(nodeId, toDelete);
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toDeleteName)));
            }

            using (Transaction tx = beginTransaction())
            {
                toAdd = tx.Token().labelGetOrCreateForName(toAddName);
                tx.DataWrite().nodeAddLabel(nodeId, toAdd);
                tx.DataWrite().nodeRemoveLabel(nodeId, toDelete);

                toRegret = tx.Token().labelGetOrCreateForName(toRegretName);
                tx.DataWrite().nodeAddLabel(nodeId, toRegret);
                tx.DataWrite().nodeRemoveLabel(nodeId, toRegret);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    AssertLabels(node.Labels(), toRetain, toAdd);
                    assertTrue(node.HasLabel(toAdd));
                    assertTrue(node.HasLabel(toRetain));
                    assertFalse(node.HasLabel(toDelete));
                    assertFalse(node.HasLabel(toRegret));
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toAddName)));
            }
        }
Пример #25
0
        // This is functionality which is only required for the hacky db.schema not to leak real data
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAccessNegativeReferences()
        public virtual void ShouldNotAccessNegativeReferences()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor())
            {
                // when
                read.singleNode(-2L, node);

                // then
                assertFalse("should not access negative reference node", node.Next());
            }
        }
Пример #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFindDeletedNode()
        public virtual void ShouldNotFindDeletedNode()
        {
            // given
            using (NodeCursor nodes = cursors.allocateNodeCursor())
            {
                // when
                read.singleNode(_gone, nodes);

                // then
                assertFalse("should not access deleted node", nodes.Next());
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTraverseRelationshipsOfGivenType()
        public virtual void ShouldTraverseRelationshipsOfGivenType()
        {
            // given
            using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor())
            {
                int empty = 0;
                // when
                read.allNodesScan(node);
                while (node.Next())
                {
                    node.Relationships(group);
                    bool none = true;
                    while (group.next())
                    {
                        none = false;
                        Sizes degree = new Sizes();
                        group.Outgoing(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + " relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Outgoing++;
                        }
                        group.Incoming(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + "relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Incoming++;
                        }
                        group.Loops(relationship);
                        while (relationship.next())
                        {
                            assertEquals("node #" + node.NodeReference() + "relationship should have same label as group", group.Type(), relationship.Type());
                            degree.Loop++;
                        }

                        // then
                        assertNotEquals("all", 0, degree.Incoming + degree.Outgoing + degree.Loop);
                        assertEquals("node #" + node.NodeReference() + " outgoing", group.OutgoingCount(), degree.Outgoing);
                        assertEquals("node #" + node.NodeReference() + " incoming", group.IncomingCount(), degree.Incoming);
                        assertEquals("node #" + node.NodeReference() + " loop", group.LoopCount(), degree.Loop);
                        assertEquals("node #" + node.NodeReference() + " all = incoming + outgoing - loop", group.TotalCount(), degree.Incoming + degree.Outgoing + degree.Loop);
                    }
                    if (none)
                    {
                        empty++;
                    }
                }

                // then
                assertEquals("number of empty nodes", 1, empty);
            }
        }
Пример #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction()
        {
            // Given
            long   nodeId;
            string propKey1 = "prop1";
            string propKey2 = "prop2";
            int    propToken1;
            int    propToken2;

            using (Transaction tx = beginTransaction())
            {
                nodeId     = tx.DataWrite().nodeCreate();
                propToken1 = tx.Token().propertyKeyGetOrCreateForName(propKey1);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken1, stringValue("hello")), NO_VALUE);
                tx.Success();
            }

            // When/Then
            using (Transaction tx = beginTransaction())
            {
                propToken2 = tx.Token().propertyKeyGetOrCreateForName(propKey2);
                assertEquals(tx.DataWrite().nodeSetProperty(nodeId, propToken2, stringValue("world")), NO_VALUE);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor(), PropertyCursor property = tx.Cursors().allocatePropertyCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    node.Properties(property);

                    //property 2, start with tx state
                    assertTrue(property.Next());
                    assertEquals(propToken2, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("world"));

                    //property 1, from disk
                    assertTrue(property.Next());
                    assertEquals(propToken1, property.PropertyKey());
                    assertEquals(property.PropertyValue(), stringValue("hello"));

                    assertFalse("should only find two properties", property.Next());
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).getProperty(propKey1), equalTo("hello"));
                assertThat(graphDb.getNodeById(nodeId).getProperty(propKey2), equalTo("world"));
            }
        }
Пример #29
0
        public override IDictionary <string, object> GetProperties(params string[] keys)
        {
            Objects.requireNonNull(keys, "Properties keys should be not null array.");

            if (keys.Length == 0)
            {
                return(Collections.emptyMap());
            }

            KernelTransaction transaction = SafeAcquireTransaction();

            int itemsToReturn = keys.Length;
            IDictionary <string, object> properties = new Dictionary <string, object>(itemsToReturn);
            TokenRead token = transaction.TokenRead();

            //Find ids, note we are betting on that the number of keys
            //is small enough not to use a set here.
            int[] propertyIds = new int[itemsToReturn];
            for (int i = 0; i < itemsToReturn; i++)
            {
                string key = keys[i];
                if (string.ReferenceEquals(key, null))
                {
                    throw new System.NullReferenceException(string.Format("Key {0:D} was null", i));
                }
                propertyIds[i] = token.PropertyKey(key);
            }

            NodeCursor     nodes          = transaction.AmbientNodeCursor();
            PropertyCursor propertyCursor = transaction.AmbientPropertyCursor();

            SingleNode(transaction, nodes);
            nodes.Properties(propertyCursor);
            int propertiesToFind = itemsToReturn;

            while (propertiesToFind > 0 && propertyCursor.Next())
            {
                //Do a linear check if this is a property we are interested in.
                int currentKey = propertyCursor.PropertyKey();
                for (int i = 0; i < itemsToReturn; i++)
                {
                    if (propertyIds[i] == currentKey)
                    {
                        properties[keys[i]] = propertyCursor.PropertyValue().asObjectCopy();
                        propertiesToFind--;
                        break;
                    }
                }
            }
            return(properties);
        }
Пример #30
0
        protected internal virtual int CountNodes(Transaction transaction)
        {
            int result = 0;

            using (NodeCursor cursor = transaction.Cursors().allocateNodeCursor())
            {
                transaction.DataRead().allNodesScan(cursor);
                while (cursor.Next())
                {
                    result++;
                }
            }
            return(result);
        }