コード例 #1
0
ファイル: NodeProxy.cs プロジェクト: Neo4Net/Neo4Net
        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);
            }
        }
コード例 #2
0
ファイル: NodeProxy.cs プロジェクト: Neo4Net/Neo4Net
        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);
                }
            }
        }
コード例 #3
0
ファイル: NodeProxy.cs プロジェクト: Neo4Net/Neo4Net
        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);
                }
            }
        }
コード例 #4
0
ファイル: ExplicitIndexProxy.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.graphdb.index.IndexHits<org.neo4j.graphdb.Node> query(org.neo4j.kernel.api.KernelTransaction ktx, String name, Object queryOrQueryObject, org.neo4j.graphdb.GraphDatabaseService graphDatabaseService) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
            public IndexHits <Node> query(KernelTransaction ktx, string name, object queryOrQueryObject, GraphDatabaseService graphDatabaseService)
            {
                NodeExplicitIndexCursor cursor = ktx.Cursors().allocateNodeExplicitIndexCursor();

                ktx.IndexRead().nodeExplicitIndexQuery(cursor, name, queryOrQueryObject);
                return(new CursorWrappingNodeIndexHits(cursor, graphDatabaseService, ktx, name));
            }
コード例 #5
0
ファイル: ExplicitIndexProxy.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.graphdb.index.IndexHits<org.neo4j.graphdb.Node> get(org.neo4j.kernel.api.KernelTransaction ktx, String name, String key, Object value, org.neo4j.graphdb.GraphDatabaseService graphDatabaseService) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
            public IndexHits <Node> get(KernelTransaction ktx, string name, string key, object value, GraphDatabaseService graphDatabaseService)
            {
                NodeExplicitIndexCursor cursor = ktx.Cursors().allocateNodeExplicitIndexCursor();

                ktx.IndexRead().nodeExplicitIndexLookup(cursor, name, key, value);
                return(new CursorWrappingNodeIndexHits(cursor, graphDatabaseService, ktx, name));
            }
コード例 #6
0
ファイル: ExplicitIndexProxy.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.graphdb.index.IndexHits<org.neo4j.graphdb.Relationship> query(org.neo4j.kernel.api.KernelTransaction ktx, String name, Object queryOrQueryObject, org.neo4j.graphdb.GraphDatabaseService graphDatabaseService) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
            public IndexHits <Relationship> query(KernelTransaction ktx, string name, object queryOrQueryObject, GraphDatabaseService graphDatabaseService)
            {
                RelationshipExplicitIndexCursor cursor = ktx.Cursors().allocateRelationshipExplicitIndexCursor();

                ktx.IndexRead().relationshipExplicitIndexQuery(cursor, name, queryOrQueryObject, -1, -1);
                return(new CursorWrappingRelationshipIndexHits(cursor, graphDatabaseService, ktx, name));
            }
コード例 #7
0
ファイル: ExplicitIndexProxy.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.graphdb.index.IndexHits<org.neo4j.graphdb.Relationship> get(org.neo4j.kernel.api.KernelTransaction ktx, String name, String key, Object value, org.neo4j.graphdb.GraphDatabaseService graphDatabaseService) throws org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException
            public IndexHits <Relationship> get(KernelTransaction ktx, string name, string key, object value, GraphDatabaseService graphDatabaseService)
            {
                RelationshipExplicitIndexCursor cursor = ktx.Cursors().allocateRelationshipExplicitIndexCursor();

                ktx.IndexRead().relationshipExplicitIndexLookup(cursor, name, key, value, -1, -1);
                return(new CursorWrappingRelationshipIndexHits(cursor, graphDatabaseService, ktx, name));
            }
コード例 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleCompositeSizesCloseToTheLimit() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleCompositeSizesCloseToTheLimit()
        {
            // given
            CreateIndex(KEY, KEY2);

            // when a string longer than native string limit, but within lucene limit
            int    length  = 20_000;
            string string1 = Random.nextAlphaNumericString(length, length);
            string string2 = Random.nextAlphaNumericString(length, length);
            Node   node;

            using (Transaction tx = Db.beginTx())
            {
                node = Db.createNode(LABEL);
                node.SetProperty(KEY, string1);
                node.SetProperty(KEY2, string2);
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                KernelTransaction ktx = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                int labelId           = ktx.TokenRead().nodeLabel(LABEL.Name());
                int propertyKeyId1    = ktx.TokenRead().propertyKey(KEY);
                int propertyKeyId2    = ktx.TokenRead().propertyKey(KEY2);
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    ktx.DataRead().nodeIndexSeek(TestIndexDescriptorFactory.forLabel(labelId, propertyKeyId1, propertyKeyId2), cursor, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId1, string1), IndexQuery.exact(propertyKeyId2, string2));
                    assertTrue(cursor.Next());
                    assertEquals(node.Id, cursor.NodeReference());
                    assertFalse(cursor.Next());
                }
                tx.Success();
            }
        }
コード例 #9
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);
        }
コード例 #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertIndexedNodesMatchesStoreNodes() throws Exception
        private void AssertIndexedNodesMatchesStoreNodes()
        {
            int   nodesInStore = 0;
            Label label        = Label.label(PERSON_LABEL);

            using (Transaction tx = _db.beginTx())
            {
                KernelTransaction ktx        = (( GraphDatabaseAPI )_db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                IList <string>    mismatches = new List <string>();
                int            labelId       = ktx.TokenRead().nodeLabel(PERSON_LABEL);
                int            propertyKeyId = ktx.TokenRead().propertyKey(NAME_PROPERTY);
                IndexReference index         = ktx.SchemaRead().index(labelId, propertyKeyId);
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    // Node --> Index
                    foreach (Node node in filter(n => n.hasLabel(label) && n.hasProperty(NAME_PROPERTY), _db.AllNodes))
                    {
                        nodesInStore++;
                        string name = ( string )node.GetProperty(NAME_PROPERTY);
                        ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, name));
                        bool found = false;
                        while (cursor.Next())
                        {
                            long indexedNode = cursor.NodeReference();
                            if (indexedNode == node.Id)
                            {
                                if (found)
                                {
                                    mismatches.Add("Index has multiple entries for " + name + " and " + indexedNode);
                                }
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            mismatches.Add("Index is missing entry for " + name + " " + node);
                        }
                    }
                    if (mismatches.Count > 0)
                    {
                        fail(join(mismatches.ToArray(), format("%n")));
                    }
                    // Node count == indexed node count
                    ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exists(propertyKeyId));
                    int nodesInIndex = 0;
                    while (cursor.Next())
                    {
                        nodesInIndex++;
                    }
                    assertEquals(nodesInStore, nodesInIndex);
                }
            }
        }
コード例 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void concurrentIndexPopulationAndInsertsShouldNotProduceDuplicates() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConcurrentIndexPopulationAndInsertsShouldNotProduceDuplicates()
        {
            // Given
            Config config           = Config.defaults();
            GraphDatabaseService db = NewEmbeddedGraphDatabaseWithSlowJobScheduler(config);

            try
            {
                // When
                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().indexFor(label(LABEL)).on(KEY).create();
                    tx.Success();
                }
                Node node;
                using (Transaction tx = Db.beginTx())
                {
                    node = Db.createNode(label(LABEL));
                    node.SetProperty(KEY, VALUE);
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().awaitIndexesOnline(1, MINUTES);
                    tx.Success();
                }

                // Then
                using (Transaction tx = Db.beginTx())
                {
                    KernelTransaction    ktx    = (( GraphDatabaseAPI )db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                    IndexReference       index  = ktx.SchemaRead().index(ktx.TokenRead().nodeLabel(LABEL), ktx.TokenRead().propertyKey(KEY));
                    NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor();
                    ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(1, VALUE));
                    assertTrue(cursor.Next());
                    assertEquals(node.Id, cursor.NodeReference());
                    assertFalse(cursor.Next());
                    tx.Success();
                }
            }
            finally
            {
                Db.shutdown();
            }
        }
コード例 #12
0
ファイル: NodeProxy.cs プロジェクト: Neo4Net/Neo4Net
        public virtual int getDegree(RelationshipType type)
        {
            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);

                return(Nodes.countAll(nodes, transaction.Cursors(), typeId));
            }
        }