示例#1
0
        private static void AssertOnNodeCounts(int expectedTotalNodes, int expectedLabelledNodes, Label label, HighlyAvailableGraphDatabase db)
        {
            using (Transaction ignored = Db.beginTx())
            {
                KernelTransaction transaction = KernelTransaction(db);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int labelId = transaction.tokenRead().nodeLabel(label.name());
                int labelId = transaction.TokenRead().nodeLabel(label.Name());
                assertEquals(expectedTotalNodes, transaction.DataRead().countsForNode(-1));
                assertEquals(expectedLabelledNodes, transaction.DataRead().countsForNode(labelId));
            }
        }
示例#2
0
        /// <param name="start"> the label of the start node of relationships to get the number of, or {@code null} for "any". </param>
        /// <param name="type">  the type of the relationships to get the number of, or {@code null} for "any". </param>
        /// <param name="end">   the label of the end node of relationships to get the number of, or {@code null} for "any". </param>
        private long CountsForRelationship(Label start, RelationshipType type, Label end)
        {
            KernelTransaction ktx = _ktxSupplier.get();

            using (Statement ignore = ktx.AcquireStatement())
            {
                TokenRead tokenRead = ktx.TokenRead();
                int       startId;
                int       typeId;
                int       endId;
                // start
                if (start == null)
                {
                    startId = [email protected]_Fields.ANY_LABEL;
                }
                else
                {
                    if ([email protected]_Fields.NO_TOKEN == (startId = tokenRead.NodeLabel(start.Name())))
                    {
                        return(0);
                    }
                }
                // type
                if (type == null)
                {
                    typeId = [email protected]_Fields.ANY_RELATIONSHIP_TYPE;
                }
                else
                {
                    if ([email protected]_Fields.NO_TOKEN == (typeId = tokenRead.RelationshipType(type.Name())))
                    {
                        return(0);
                    }
                }
                // end
                if (end == null)
                {
                    endId = [email protected]_Fields.ANY_LABEL;
                }
                else
                {
                    if ([email protected]_Fields.NO_TOKEN == (endId = tokenRead.NodeLabel(end.Name())))
                    {
                        return(0);
                    }
                }
                return(ktx.DataRead().countsForRelationship(startId, typeId, endId));
            }
        }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void lockNodeUsingUniqueIndexSeek(org.neo4j.kernel.internal.GraphDatabaseAPI database, org.neo4j.graphdb.Label label, String nameProperty) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private static void LockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, Label label, string nameProperty)
        {
            using (Transaction transaction = database.BeginTx())
            {
                ThreadToStatementContextBridge contextBridge = database.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge));
                KernelTransaction kernelTransaction          = contextBridge.GetKernelTransactionBoundToThisThread(true);
                TokenRead         tokenRead = kernelTransaction.TokenRead();
                Read dataRead = kernelTransaction.DataRead();

                int            labelId        = tokenRead.NodeLabel(label.Name());
                int            propertyId     = tokenRead.PropertyKey(nameProperty);
                IndexReference indexReference = kernelTransaction.SchemaRead().index(labelId, propertyId);
                dataRead.LockingNodeUniqueIndexSeek(indexReference, IndexQuery.ExactPredicate.exact(propertyId, "value"));
                transaction.Success();
            }
        }
示例#4
0
        /// <param name="label"> the label to get the number of nodes of, or {@code null} to get the total number of nodes. </param>
        private long CountsForNode(Label label)
        {
            KernelTransaction transaction = _transactionSupplier.get();
            Read read = transaction.DataRead();
            int  labelId;

            if (label == null)
            {
                labelId = StatementConstants.ANY_LABEL;
            }
            else
            {
                if ([email protected]_Fields.NO_TOKEN == (labelId = transaction.TokenRead().nodeLabel(label.Name())))
                {
                    return(0);
                }
            }
            return(read.CountsForNode(labelId));
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowConcurrentViolationOfConstraint() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowConcurrentViolationOfConstraint()
        {
            // Given
            GraphDatabaseAPI graphDb = Db.GraphDatabaseAPI;

            System.Func <KernelTransaction> ktxSupplier = () => graphDb.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);

            Label  label            = label("Foo");
            string propertyKey      = "bar";
            string conflictingValue = "baz";

            // a constraint
            using (Transaction tx = graphDb.BeginTx())
            {
                graphDb.Schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
                tx.Success();
            }

            // When
            using (Transaction tx = graphDb.BeginTx())
            {
                KernelTransaction ktx         = ktxSupplier();
                int             labelId       = ktx.TokenRead().nodeLabel(label.Name());
                int             propertyKeyId = ktx.TokenRead().propertyKey(propertyKey);
                IndexDescriptor index         = TestIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId);
                Read            read          = ktx.DataRead();
                using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor())
                {
                    read.NodeIndexSeek(ktx.SchemaRead().index(labelId, propertyKeyId), cursor, IndexOrder.NONE, false, IndexQuery.exact(index.Schema().PropertyId, "The value is irrelevant, we just want to perform some sort of lookup against this " + "index"));
                }
                // then let another thread come in and create a node
                Threads.execute(Db =>
                {
                    using (Transaction transaction = Db.beginTx())
                    {
                        Db.createNode(label).setProperty(propertyKey, conflictingValue);
                        transaction.success();
                    }
                    return(null);
                }, graphDb).get();

                // before we create a node with the same property ourselves - using the same statement that we have
                // already used for lookup against that very same index
                long node = ktx.DataWrite().nodeCreate();
                ktx.DataWrite().nodeAddLabel(node, labelId);
                try
                {
                    ktx.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(conflictingValue));

                    fail("exception expected");
                }
                // Then
                catch (UniquePropertyValueValidationException e)
                {
                    assertEquals(ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId), e.Constraint());
                    IndexEntryConflictException conflict = Iterators.single(e.Conflicts().GetEnumerator());
                    assertEquals(Values.stringValue(conflictingValue), conflict.SinglePropertyValue);
                }

                tx.Success();
            }
        }