Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void visitsLabelIds()
        public virtual void VisitsLabelIds()
        {
            // GIVEN
            DbStructureVisitor visitor = mock(typeof(DbStructureVisitor));

            _graph.createNode(label("Person"));
            _graph.createNode(label("Party"));
            _graph.createNode(label("Animal"));
            int personLabelId;
            int partyLabelId;
            int animalLabelId;

            KernelTransaction ktx       = ktx();
            TokenRead         tokenRead = ktx.TokenRead();

            personLabelId = tokenRead.NodeLabel("Person");
            partyLabelId  = tokenRead.NodeLabel("Party");
            animalLabelId = tokenRead.NodeLabel("Animal");

            // WHEN
            Accept(visitor);

            // THEN
            verify(visitor).visitLabel(personLabelId, "Person");
            verify(visitor).visitLabel(partyLabelId, "Party");
            verify(visitor).visitLabel(animalLabelId, "Animal");
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void visitsRelationshipTypeIds()
        public virtual void VisitsRelationshipTypeIds()
        {
            // GIVEN
            DbStructureVisitor visitor = mock(typeof(DbStructureVisitor));
            Node lhs = _graph.createNode();
            Node rhs = _graph.createNode();

            lhs.CreateRelationshipTo(rhs, withName("KNOWS"));
            lhs.CreateRelationshipTo(rhs, withName("LOVES"));
            lhs.CreateRelationshipTo(rhs, withName("FAWNS_AT"));
            int knowsId;
            int lovesId;
            int fawnsAtId;
            KernelTransaction ktx = ktx();

            TokenRead tokenRead = ktx.TokenRead();

            knowsId   = tokenRead.RelationshipType("KNOWS");
            lovesId   = tokenRead.RelationshipType("LOVES");
            fawnsAtId = tokenRead.RelationshipType("FAWNS_AT");

            // WHEN
            Accept(visitor);

            // THEN
            verify(visitor).visitRelationshipType(knowsId, "KNOWS");
            verify(visitor).visitRelationshipType(lovesId, "LOVES");
            verify(visitor).visitRelationshipType(fawnsAtId, "FAWNS_AT");
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            KernelTransaction transaction = mock(typeof(KernelTransaction));

            _tokenRead  = mock(typeof(TokenRead));
            _schemaRead = mock(typeof(SchemaRead));
            _procedure  = new IndexProcedures(transaction, null);

            when(transaction.TokenRead()).thenReturn(_tokenRead);
            when(transaction.SchemaRead()).thenReturn(_schemaRead);
            _indexingService = mock(typeof(IndexingService));
            _procedure       = new IndexProcedures(transaction, _indexingService);
        }
Ejemplo n.º 5
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));
            }
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
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));
        }