示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowReadStatementAfterReadStatement()
        public virtual void ShouldAllowReadStatementAfterReadStatement()
        {
            // given
            KernelTransaction tx = kernelTransaction(AnonymousContext.read());

            tx.DataRead();

            // when / then
            tx.DataRead();
        }
示例#2
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);
                }
            }
        }
示例#3
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);
            }

            PropertyCursor properties = transaction.AmbientPropertyCursor();

            transaction.DataRead().graphProperties(properties);
            while (properties.Next())
            {
                if (propertyKey == properties.PropertyKey())
                {
                    return(true);
                }
            }
            return(false);
        }
示例#4
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);
            }
        }
示例#5
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();
            }
        }
示例#6
0
        private void RightSide(KernelTransaction ktx, DbStructureVisitor visitor, Label label, int labelId, RelationshipType relType, int relTypeId)
        {
            string userDescription = format("MATCH ()-[%s]->(%s) RETURN count(*)", Colon(relType.Name()), Colon(label.Name()));
            long   amount          = ktx.DataRead().countsForRelationship(ANY_LABEL, relTypeId, labelId);

            visitor.VisitRelCount(ANY_LABEL, relTypeId, labelId, userDescription, amount);
        }
示例#7
0
        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));
            }

            PropertyCursor properties = transaction.AmbientPropertyCursor();

            transaction.DataRead().graphProperties(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));
        }
示例#8
0
        private static void CheckLabelCounts(GraphDatabaseAPI db)
        {
            using (Transaction ignored = Db.beginTx())
            {
                Dictionary <Label, long> counts = new Dictionary <Label, long>();
                foreach (Node node in Db.AllNodes)
                {
                    foreach (Label label in node.Labels)
                    {
                        long?count = counts[label];
                        if (count != null)
                        {
                            counts[label] = count + 1;
                        }
                        else
                        {
                            counts[label] = 1L;
                        }
                    }
                }

                ThreadToStatementContextBridge bridge = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge));
                KernelTransaction kernelTransaction   = bridge.GetKernelTransactionBoundToThisThread(true);

                foreach (KeyValuePair <Label, long> entry in Counts.SetOfKeyValuePairs())
                {
                    assertEquals(entry.Value.longValue(), kernelTransaction.DataRead().countsForNode(kernelTransaction.TokenRead().nodeLabel(entry.Key.name())));
                }
            }
        }
示例#9
0
 private void SingleNode(KernelTransaction transaction, NodeCursor nodes)
 {
     transaction.DataRead().singleNode(_nodeId, nodes);
     if (!nodes.Next())
     {
         throw new NotFoundException(new EntityNotFoundException(EntityType.NODE, _nodeId));
     }
 }
示例#10
0
 private void SingleRelationship(KernelTransaction transaction, RelationshipScanCursor relationships)
 {
     transaction.DataRead().singleRelationship(_id, relationships);
     if (!relationships.Next())
     {
         throw new NotFoundException(new EntityNotFoundException(EntityType.RELATIONSHIP, _id));
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.TransactionTerminatedException.class) public void shouldThrowTerminateExceptionWhenTransactionTerminated() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowTerminateExceptionWhenTransactionTerminated()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            transaction.Success();
            transaction.MarkForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError);

            TransactionOperation.operate(transaction.DataRead(), transaction.DataWrite(), transaction.SchemaRead());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.NotInTransactionException.class) public void shouldThrowNotInTransactionWhenTransactionClosedAndAccessingOperations() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNotInTransactionWhenTransactionClosedAndAccessingOperations()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            transaction.Success();
            transaction.Close();

            TransactionOperation.operate(transaction.DataRead(), transaction.DataWrite(), transaction.SchemaRead());
        }
示例#13
0
        private static void CheckGlobalNodeCount(Store store, GraphDatabaseAPI db)
        {
            using (Transaction ignored = Db.beginTx())
            {
                ThreadToStatementContextBridge bridge = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge));
                KernelTransaction kernelTransaction   = bridge.GetKernelTransactionBoundToThisThread(true);

                assertThat(kernelTransaction.DataRead().countsForNode(-1), @is(store.ExpectedNodeCount));
            }
        }
示例#14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowSchemaStatementAfterReadStatement() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowSchemaStatementAfterReadStatement()
        {
            // given
            KernelTransaction tx = kernelTransaction(AUTH_DISABLED);

            tx.DataRead();

            // when / then
            tx.SchemaWrite();
        }
示例#15
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);
        }
示例#16
0
        private void ShowNodeCounts(KernelTransaction ktx, DbStructureVisitor visitor)
        {
            Read read = ktx.DataRead();

            visitor.VisitAllNodesCount(read.CountsForNode(ANY_LABEL));
            foreach (Label label in _db.AllLabels)
            {
                int labelId = ktx.TokenRead().nodeLabel(label.Name());
                visitor.VisitNodeCount(labelId, label.Name(), read.CountsForNode(labelId));
            }
        }
示例#17
0
        public virtual long CountNodes()
        {
            long result;

            using (Transaction tx = _graph.beginTransaction(KernelTransaction.Type.@explicit, AnonymousContext.read()))
            {
                KernelTransaction kernelTransaction = this._txBridge.getKernelTransactionBoundToThisThread(true);
                result = kernelTransaction.DataRead().countsForNode(-1);
                tx.Success();
            }
            return(result);
        }
示例#18
0
 public static bool IsDeletedInCurrentTransaction(Relationship relationship)
 {
     if (relationship is RelationshipProxy)
     {
         RelationshipProxy proxy = ( RelationshipProxy )relationship;
         KernelTransaction ktx   = proxy._spi.kernelTransaction();
         using (Statement ignore = ktx.AcquireStatement())
         {
             return(ktx.DataRead().relationshipDeletedInTransaction(proxy._id));
         }
     }
     return(false);
 }
示例#19
0
 public static bool IsDeletedInCurrentTransaction(Node node)
 {
     if (node is NodeProxy)
     {
         NodeProxy         proxy = ( NodeProxy )node;
         KernelTransaction ktx   = proxy._spi.kernelTransaction();
         using (Statement ignore = ktx.AcquireStatement())
         {
             return(ktx.DataRead().nodeDeletedInTransaction(proxy._nodeId));
         }
     }
     return(false);
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.NotInTransactionException.class) public void shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            Read       read       = transaction.DataRead();
            Write      write      = transaction.DataWrite();
            SchemaRead schemaRead = transaction.SchemaRead();

            transaction.Success();
            transaction.Close();

            TransactionOperation.operate(read, write, schemaRead);
        }
示例#21
0
        public override IDictionary <string, object> GetProperties(params string[] names)
        {
            Objects.requireNonNull(names, "Properties keys should be not null array.");

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

            KernelTransaction transaction = SafeAcquireTransaction();

            int itemsToReturn = names.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 = names[i];
                if (string.ReferenceEquals(key, null))
                {
                    throw new System.NullReferenceException(string.Format("Key {0:D} was null", i));
                }
                propertyIds[i] = token.PropertyKey(key);
            }

            PropertyCursor propertyCursor = transaction.AmbientPropertyCursor();

            transaction.DataRead().graphProperties(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[names[i]] = propertyCursor.PropertyValue().asObjectCopy();
                        propertiesToFind--;
                        break;
                    }
                }
            }
            return(properties);
        }
示例#22
0
        public override bool HasLabel(Label label)
        {
            KernelTransaction transaction = SafeAcquireTransaction();
            NodeCursor        nodes       = transaction.AmbientNodeCursor();

            using (Statement ignore = transaction.AcquireStatement())
            {
                int labelId = transaction.TokenRead().nodeLabel(label.Name());
                if (labelId == NO_SUCH_LABEL)
                {
                    return(false);
                }
                transaction.DataRead().singleNode(_nodeId, nodes);
                return(nodes.Next() && nodes.HasLabel(labelId));
            }
        }
示例#23
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();
            }
        }
示例#24
0
 public virtual bool InitializeData()
 {
     // It enough to check only start node, since it's absence will indicate that data was not yet loaded.
     if (_startNode == AbstractBaseRecord.NO_ID)
     {
         KernelTransaction transaction = _spi.kernelTransaction();
         using (Statement ignore = transaction.AcquireStatement())
         {
             RelationshipScanCursor relationships = transaction.AmbientRelationshipCursor();
             transaction.DataRead().singleRelationship(_id, relationships);
             // At this point we don't care if it is there or not just load what we got.
             bool wasPresent = relationships.Next();
             this._type      = relationships.Type();
             this._startNode = relationships.SourceNodeReference();
             this._endNode   = relationships.TargetNodeReference();
             // But others might care, e.g. the Bolt server needs to know for serialisation purposes.
             return(wasPresent);
         }
     }
     return(true);
 }
示例#25
0
 internal override bool inUse(KernelTransaction transaction, SchemaReadCore schemaReadCore, int tokenId)
 {
     return(HasAny(schemaReadCore.IndexesGetForRelationshipType(tokenId)) || HasAny(schemaReadCore.ConstraintsGetForRelationshipType(tokenId)) || transaction.DataRead().countsForRelationship(ANY_LABEL, tokenId, ANY_LABEL) > 0);                          // used by data
 }
示例#26
0
 internal override bool inUse(KernelTransaction transaction, SchemaReadCore schemaReadCore, int tokenId)
 {
     return(HasAny(schemaReadCore.IndexesGetForLabel(tokenId)) || HasAny(schemaReadCore.ConstraintsGetForLabel(tokenId)) || transaction.DataRead().countsForNode(tokenId) > 0);                          // used by data
 }