Exemple #1
0
        private void CollectAndSortNodeIds(long nodeId, Transaction transaction, NodeCursor nodes)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet nodeIdSet = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet();
            MutableLongSet nodeIdSet = new LongHashSet();

            nodeIdSet.add(nodeId);

            [email protected] read = transaction.DataRead();
            read.SingleNode(nodeId, nodes);
            if (!nodes.Next())
            {
                this._sortedNodeIds = _empty;
                return;
            }
            using (RelationshipSelectionCursor rels = RelationshipSelections.allCursor(transaction.Cursors(), nodes, null))
            {
                while (rels.Next())
                {
                    if (_firstRelId == NO_SUCH_RELATIONSHIP)
                    {
                        _firstRelId = rels.RelationshipReference();
                    }

                    nodeIdSet.add(rels.SourceNodeReference());
                    nodeIdSet.add(rels.TargetNodeReference());
                }
            }

            this._sortedNodeIds = nodeIdSet.toSortedArray();
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void lockAllNodesAndConsumeRelationships(long nodeId, final org.neo4j.internal.kernel.api.Transaction transaction, org.neo4j.internal.kernel.api.NodeCursor nodes) throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        internal virtual void LockAllNodesAndConsumeRelationships(long nodeId, Transaction transaction, NodeCursor nodes)
        {
            bool retry;

            do
            {
                retry       = false;
                _firstRelId = NO_SUCH_RELATIONSHIP;

                // lock all the nodes involved by following the node id ordering
                CollectAndSortNodeIds(nodeId, transaction, nodes);
                LockAllNodes(_sortedNodeIds);

                // perform the action on each relationship, we will retry if the the relationship iterator contains
                // new relationships
                [email protected] read = transaction.DataRead();
                read.SingleNode(nodeId, nodes);
                //if the node is not there, someone else probably deleted it, just ignore
                if (nodes.Next())
                {
                    using (RelationshipSelectionCursor rels = RelationshipSelections.allCursor(transaction.Cursors(), nodes, null))
                    {
                        bool first = true;
                        while (rels.Next() && !retry)
                        {
                            retry = PerformAction(rels.RelationshipReference(), first);
                            first = false;
                        }
                    }
                }
            } while (retry);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AddingUniqueNodeWithUnrelatedValueShouldNotAffectLookup()
        {
            // given
            CreateConstraint("Person", "id");

            long ourNode;
            {
                Transaction transaction = NewTransaction(AnonymousContext.writeToken());
                ourNode = CreateLabeledNode(transaction, "Person", "id", 1);
                Commit();
            }

            Transaction    transaction = NewTransaction(AnonymousContext.writeToken());
            TokenRead      tokenRead   = transaction.TokenRead();
            int            person      = tokenRead.NodeLabel("Person");
            int            propId      = tokenRead.PropertyKey("id");
            IndexReference idx         = transaction.SchemaRead().index(person, propId);

            // when
            CreateLabeledNode(transaction, "Person", "id", 2);

            // then I should find the original node
            assertThat(transaction.DataRead().lockingNodeUniqueIndexSeek(idx, exact(propId, Values.of(1))), equalTo(ourNode));
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEnforceUniquenessConstraintOnAddLabelForNumberPropertyOnNodeNotFromTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldEnforceUniquenessConstraintOnAddLabelForNumberPropertyOnNodeNotFromTransaction()
        {
            // given
            ConstrainedNode("Label1", "key1", 1);

            // when
            Transaction transaction = NewTransaction(AnonymousContext.writeToken());
            long        node        = CreateNode(transaction, "key1", 1);

            Commit();

            transaction = NewTransaction(AnonymousContext.writeToken());
            try
            {
                int label = transaction.TokenWrite().labelGetOrCreateForName("Label1");
                transaction.DataWrite().nodeAddLabel(node, label);

                fail("should have thrown exception");
            }
            // then
            catch (UniquePropertyValueValidationException e)
            {
                assertThat(e.GetUserMessage(TokenLookup(transaction)), containsString("`key1` = 1"));
            }
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void roundingErrorsFromLongToDoubleShouldNotPreventTxFromCommitting() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RoundingErrorsFromLongToDoubleShouldNotPreventTxFromCommitting()
        {
            // Given
            // a node with a constrained label and a long value
            long propertyValue = 285414114323346805L;
            long firstNode     = ConstrainedNode("label1", "key1", propertyValue);

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            long node = CreateLabeledNode(transaction, "label1");

            assertNotEquals(firstNode, node);

            // When
            // a new node with the same constraint is added, with a value not equal but which would be mapped to the same double
            propertyValue++;
            // note how propertyValue is definitely not equal to propertyValue++ but they do equal if they are cast to double
            int propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

            transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(propertyValue));

            // Then
            // the commit should still succeed
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldComputeDegreeWithoutType() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldComputeDegreeWithoutType()
        {
            // GIVEN
            long node;

            using (Transaction tx = Transaction())
            {
                Write write = tx.DataWrite();
                node = write.NodeCreate();
                write.RelationshipCreate(node, tx.TokenWrite().relationshipTypeGetOrCreateForName("R1"), write.NodeCreate());
                write.RelationshipCreate(node, tx.TokenWrite().relationshipTypeGetOrCreateForName("R2"), write.NodeCreate());
                write.RelationshipCreate(write.NodeCreate(), tx.TokenWrite().relationshipTypeGetOrCreateForName("R3"), node);
                write.RelationshipCreate(node, tx.TokenWrite().relationshipTypeGetOrCreateForName("R4"), node);

                tx.Success();
            }

            using (Transaction tx = Transaction())
            {
                Read          read    = tx.DataRead();
                CursorFactory cursors = tx.Cursors();
                using (NodeCursor nodes = cursors.AllocateNodeCursor())
                {
                    assertThat(CompiledExpandUtils.NodeGetDegreeIfDense(read, node, nodes, cursors, OUTGOING), equalTo(3));
                    assertThat(CompiledExpandUtils.NodeGetDegreeIfDense(read, node, nodes, cursors, INCOMING), equalTo(2));
                    assertThat(CompiledExpandUtils.NodeGetDegreeIfDense(read, node, nodes, cursors, BOTH), equalTo(4));
                }
            }
        }
Exemple #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createEntity(org.neo4j.internal.kernel.api.Transaction transaction, String property, String value) throws Exception
            internal override long CreateEntity(Transaction transaction, string property, string value)
            {
                long node        = transaction.DataWrite().nodeCreate();
                int  propertyKey = transaction.TokenWrite().propertyKeyGetOrCreateForName(property);

                transaction.DataWrite().nodeSetProperty(node, propertyKey, Values.of(value));
                return(node);
            }
Exemple #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createEntity(org.neo4j.internal.kernel.api.Transaction transaction, String type) throws Exception
            internal override long CreateEntity(Transaction transaction, string type)
            {
                long node    = transaction.DataWrite().nodeCreate();
                int  labelId = transaction.TokenWrite().labelGetOrCreateForName(type);

                transaction.DataWrite().nodeAddLabel(node, labelId);
                return(node);
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void dropIndex(org.neo4j.internal.kernel.api.IndexReference reference) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void DropIndex(IndexReference reference)
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                transaction.SchemaWrite().indexDrop(reference);
                transaction.Success();
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void dropConstraint(org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private void DropConstraint(ConstraintDescriptor descriptor)
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                transaction.SchemaWrite().constraintDrop(descriptor);
                transaction.Success();
            }
        }
Exemple #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createEntity(org.neo4j.internal.kernel.api.Transaction transaction, String type) throws Exception
            internal override long CreateEntity(Transaction transaction, string type)
            {
                long start   = transaction.DataWrite().nodeCreate();
                long end     = transaction.DataWrite().nodeCreate();
                int  relType = transaction.TokenWrite().relationshipTypeGetOrCreateForName(type);

                return(transaction.DataWrite().relationshipCreate(start, relType, end));
            }
Exemple #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: int entityCount() throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
            internal override int EntityCount()
            {
                Transaction transaction = NewTransaction();
                int         result      = CountRelationships(transaction);

                Rollback();
                return(result);
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long createLabeledNode(org.neo4j.internal.kernel.api.Transaction transaction, String label, String key, Object value) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private long CreateLabeledNode(Transaction transaction, string label, string key, object value)
        {
            long node          = CreateLabeledNode(transaction, label);
            int  propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName(key);

            transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(value));
            return(node);
        }
Exemple #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createEntity(org.neo4j.internal.kernel.api.Transaction transaction, String type, String property, String value) throws Exception
            internal override long CreateEntity(Transaction transaction, string type, string property, string value)
            {
                long relationship = CreateEntity(transaction, type);
                int  propertyKey  = transaction.TokenWrite().propertyKeyGetOrCreateForName(property);

                transaction.DataWrite().relationshipSetProperty(relationship, propertyKey, Values.of(value));
                return(relationship);
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long createLabeledNode(org.neo4j.internal.kernel.api.Transaction transaction, String label) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private long CreateLabeledNode(Transaction transaction, string label)
        {
            long node    = transaction.DataWrite().nodeCreate();
            int  labelId = transaction.TokenWrite().labelGetOrCreateForName(label);

            transaction.DataWrite().nodeAddLabel(node, labelId);
            return(node);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.internal.kernel.api.IndexReference createIndex() throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private IndexReference CreateIndex()
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                IndexReference reference = transaction.SchemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(1, 1));
                transaction.Success();
                return(reference);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void awaitIndexOnline(org.neo4j.internal.kernel.api.IndexReference descriptor, String keyForProbing) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException, org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private void AwaitIndexOnline(IndexReference descriptor, string keyForProbing)
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                SchemaIndexTestHelper.awaitIndexOnline(transaction.SchemaRead(), descriptor);
                transaction.Success();
            }
            AwaitSchemaStateCleared(keyForProbing);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private String commitToSchemaState(String key, String value) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private string CommitToSchemaState(string key, string value)
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                string result = GetOrCreateFromState(transaction, key, value);
                transaction.Success();
                return(result);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor createConstraint() throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private ConstraintDescriptor CreateConstraint()
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                ConstraintDescriptor descriptor = transaction.SchemaWrite().uniquePropertyConstraintCreate(SchemaDescriptorFactory.forLabel(1, 1));
                transaction.Success();
                return(descriptor);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void awaitSchemaStateCleared(String keyForProbing) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
        private void AwaitSchemaStateCleared(string keyForProbing)
        {
            using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED))
            {
                while (transaction.SchemaRead().schemaStateGetOrCreate(keyForProbing, ignored => null) != null)
                {
                    LockSupport.parkNanos(MILLISECONDS.toNanos(10));
                }
                transaction.Success();
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static java.util.Map<String,int> count(org.neo4j.internal.kernel.api.Transaction transaction, RelationshipTraversalCursor relationship) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        internal static IDictionary <string, int> Count([email protected] transaction, RelationshipTraversalCursor relationship)
        {
            Dictionary <string, int> counts = new Dictionary <string, int>();

            while (relationship.next())
            {
                string key = ComputeKey(transaction, relationship);
                Counts.compute(key, (k, value) => value == null ? 1 : value + 1);
            }
            return(counts);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_DeleteNode() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionDeleteNode()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            transaction.DataWrite().nodeDelete(node);
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
Exemple #23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized int createToken(String name) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        public override int CreateToken(string name)
        {
            lock (this)
            {
                Kernel kernel = _kernelSupplier.get();
                using (Transaction tx = kernel.BeginTransaction(Transaction_Type.@implicit, LoginContext.AUTH_DISABLED))
                {
                    int id = CreateKey(tx, name);
                    tx.Success();
                    return(id);
                }
            }
        }
Exemple #24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createEntity(org.neo4j.internal.kernel.api.Transaction transaction, String property, String value) throws Exception
            internal override long CreateEntity(Transaction transaction, string property, string value)
            {
                long   start = transaction.DataWrite().nodeCreate();
                long   end   = transaction.DataWrite().nodeCreate();
                string relationshipTypeName = System.Guid.randomUUID().ToString();
                int    relType      = transaction.TokenWrite().relationshipTypeGetOrCreateForName(relationshipTypeName);
                long   relationship = transaction.DataWrite().relationshipCreate(start, relType, end);

                int propertyKey = transaction.TokenWrite().propertyKeyGetOrCreateForName(property);

                transaction.DataWrite().relationshipSetProperty(relationship, propertyKey, Values.of(value));
                return(relationship);
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionChangeProperty()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            int propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

            transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of("value2"));
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionRemoveProperty()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            int key = transaction.TokenRead().propertyKey("key1");

            transaction.DataWrite().nodeRemoveProperty(node, key);
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveLabel() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionRemoveLabel()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            int label = transaction.TokenWrite().labelGetOrCreateForName("Label1");

            transaction.DataWrite().nodeRemoveLabel(node, label);
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
Exemple #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowNoopLabelUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldAllowNoopLabelUpdate()
            {
                // given
                long entityId = CreateConstraintAndEntity("Label1", "key1", "value1");

                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                int label = transaction.TokenWrite().labelGetOrCreateForName("Label1");

                transaction.DataWrite().nodeAddLabel(entityId, label);

                // then should not throw exception
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void assertCount(org.neo4j.internal.kernel.api.Transaction transaction, RelationshipTraversalCursor relationship, java.util.Map<String,int> expectedCounts, int expectedType, org.neo4j.graphdb.Direction direction) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        internal static void AssertCount([email protected] transaction, RelationshipTraversalCursor relationship, IDictionary <string, int> expectedCounts, int expectedType, Direction direction)
        {
            string key           = ComputeKey(transaction.Token().relationshipTypeName(expectedType), direction);
            int    expectedCount = expectedCounts.getOrDefault(key, 0);
            int    count         = 0;

            while (relationship.next())
            {
                assertEquals("same type", expectedType, relationship.Type());
                count++;
            }

            assertEquals(format("expected number of relationships for key '%s'", key), expectedCount, count);
        }
Exemple #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowNoopPropertyUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldAllowNoopPropertyUpdate()
            {
                // given
                long entity = CreateConstraintAndEntity("Type1", "key1", "value1");

                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                int key = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

                SetProperty(transaction.DataWrite(), entity, key, Values.of("value1"));

                // then should not throw exception
            }