Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeNewLabeledNodeInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeNewLabeledNodeInTransaction()
        {
            long         nodeId;
            int          labelId;
            const string labelName = "Town";

            using (Transaction tx = beginTransaction())
            {
                nodeId  = tx.DataWrite().nodeCreate();
                labelId = tx.Token().labelGetOrCreateForName(labelName);
                tx.DataWrite().nodeAddLabel(nodeId, labelId);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    LabelSet labels = node.Labels();
                    assertEquals(1, labels.NumberOfLabels());
                    assertEquals(labelId, labels.Label(0));
                    assertTrue(node.HasLabel(labelId));
                    assertFalse(node.HasLabel(labelId + 1));
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, equalTo(Iterables.iterable(label(labelName))));
            }
        }
Exemplo n.º 2
0
        private void ScanEverythingBelongingToNodes(NodeMappings nodeMappings)
        {
            using (NodeCursor nodeCursor = _cursors.allocateNodeCursor(), PropertyCursor propertyCursor = _cursors.allocatePropertyCursor())
            {
                _dataRead.allNodesScan(nodeCursor);
                while (nodeCursor.Next())
                {
                    // each node
                    SortedLabels labels = SortedLabels.From(nodeCursor.Labels());
                    nodeCursor.Properties(propertyCursor);
                    MutableIntSet propertyIds = IntSets.mutable.empty();

                    while (propertyCursor.Next())
                    {
                        Value currentValue           = propertyCursor.PropertyValue();
                        int   propertyKeyId          = propertyCursor.PropertyKey();
                        Pair <SortedLabels, int> key = Pair.of(labels, propertyKeyId);
                        UpdateValueTypeInMapping(currentValue, key, nodeMappings.LabelSetANDNodePropertyKeyIdToValueType);

                        propertyIds.add(propertyKeyId);
                    }
                    propertyCursor.Close();

                    MutableIntSet oldPropertyKeySet = nodeMappings.LabelSetToPropertyKeys.getOrDefault(labels, _emptyPropertyIdSet);

                    // find out which old properties we did not visited and mark them as nullable
                    if (oldPropertyKeySet == _emptyPropertyIdSet)
                    {
                        if (propertyIds.size() == 0)
                        {
                            // Even if we find property key on other nodes with those labels, set all of them nullable
                            nodeMappings.NullableLabelSets.Add(labels);
                        }

                        propertyIds.addAll(oldPropertyKeySet);
                    }
                    else
                    {
                        MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
                        currentPropertyIdsHelperSet.addAll(propertyIds);
                        propertyIds.removeAll(oldPropertyKeySet);                                     // only the brand new ones in propIds now
                        oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);                     // only the old ones that are not on the new node

                        propertyIds.addAll(oldPropertyKeySet);
                        propertyIds.forEach(id =>
                        {
                            Pair <SortedLabels, int> key = Pair.of(labels, id);
                            nodeMappings.LabelSetANDNodePropertyKeyIdToValueType[key].setNullable();
                        });

                        propertyIds.addAll(currentPropertyIdsHelperSet);
                    }

                    nodeMappings.LabelSetToPropertyKeys[labels] = propertyIds;
                }
                nodeCursor.Close();
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeLabelChangesInTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeLabelChangesInTransaction()
        {
            long         nodeId;
            int          toRetain, toDelete, toAdd, toRegret;
            const string toRetainName = "ToRetain";
            const string toDeleteName = "ToDelete";
            const string toAddName    = "ToAdd";
            const string toRegretName = "ToRegret";

            using (Transaction tx = beginTransaction())
            {
                nodeId   = tx.DataWrite().nodeCreate();
                toRetain = tx.Token().labelGetOrCreateForName(toRetainName);
                toDelete = tx.Token().labelGetOrCreateForName(toDeleteName);
                tx.DataWrite().nodeAddLabel(nodeId, toRetain);
                tx.DataWrite().nodeAddLabel(nodeId, toDelete);
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toDeleteName)));
            }

            using (Transaction tx = beginTransaction())
            {
                toAdd = tx.Token().labelGetOrCreateForName(toAddName);
                tx.DataWrite().nodeAddLabel(nodeId, toAdd);
                tx.DataWrite().nodeRemoveLabel(nodeId, toDelete);

                toRegret = tx.Token().labelGetOrCreateForName(toRegretName);
                tx.DataWrite().nodeAddLabel(nodeId, toRegret);
                tx.DataWrite().nodeRemoveLabel(nodeId, toRegret);

                using (NodeCursor node = tx.Cursors().allocateNodeCursor())
                {
                    tx.DataRead().singleNode(nodeId, node);
                    assertTrue("should access node", node.Next());

                    AssertLabels(node.Labels(), toRetain, toAdd);
                    assertTrue(node.HasLabel(toAdd));
                    assertTrue(node.HasLabel(toRetain));
                    assertFalse(node.HasLabel(toDelete));
                    assertFalse(node.HasLabel(toRegret));
                    assertFalse("should only find one node", node.Next());
                }
                tx.Success();
            }

            using (Org.Neo4j.Graphdb.Transaction ignored = graphDb.beginTx())
            {
                assertThat(graphDb.getNodeById(nodeId).Labels, containsInAnyOrder(label(toRetainName), label(toAddName)));
            }
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadLabels()
        public virtual void ShouldReadLabels()
        {
            // given
            using (NodeCursor nodes = cursors.allocateNodeCursor())
            {
                LabelSet labels;

                // when
                read.singleNode(_foo, nodes);

                // then
                assertTrue("should access defined node", nodes.Next());
                labels = nodes.Labels();
                assertEquals("number of labels", 1, labels.NumberOfLabels());
                int fooLabel = labels.Label(0);
                assertTrue(nodes.HasLabel(fooLabel));
                assertFalse("should only access a single node", nodes.Next());

                // when
                read.singleNode(_bar, nodes);

                // then
                assertTrue("should access defined node", nodes.Next());
                labels = nodes.Labels();
                assertEquals("number of labels", 1, labels.NumberOfLabels());
                int barLabel = labels.Label(0);
                assertFalse(nodes.HasLabel(fooLabel));
                assertTrue(nodes.HasLabel(barLabel));
                assertFalse("should only access a single node", nodes.Next());

                // when
                read.singleNode(_baz, nodes);

                // then
                assertTrue("should access defined node", nodes.Next());
                labels = nodes.Labels();
                assertEquals("number of labels", 1, labels.NumberOfLabels());
                int bazLabel = labels.Label(0);
                assertFalse(nodes.HasLabel(fooLabel));
                assertFalse(nodes.HasLabel(barLabel));
                assertTrue(nodes.HasLabel(bazLabel));
                assertFalse("should only access a single node", nodes.Next());

                assertNotEquals("distinct labels", fooLabel, barLabel);
                assertNotEquals("distinct labels", fooLabel, bazLabel);
                assertNotEquals("distinct labels", barLabel, bazLabel);

                // when
                read.singleNode(_barbaz, nodes);

                // then
                assertTrue("should access defined node", nodes.Next());
                labels = nodes.Labels();
                assertEquals("number of labels", 2, labels.NumberOfLabels());
                if (labels.Label(0) == barLabel)
                {
                    assertEquals(bazLabel, labels.Label(1));
                }
                else
                {
                    assertEquals(bazLabel, labels.Label(0));
                    assertEquals(barLabel, labels.Label(1));
                }
                assertFalse(nodes.HasLabel(fooLabel));
                assertTrue(nodes.HasLabel(barLabel));
                assertTrue(nodes.HasLabel(bazLabel));

                assertFalse("should only access a single node", nodes.Next());

                // when
                read.singleNode(_bare, nodes);

                // then
                assertTrue("should access defined node", nodes.Next());
                labels = nodes.Labels();
                assertEquals("number of labels", 0, labels.NumberOfLabels());
                assertFalse(nodes.HasLabel(fooLabel));
                assertFalse(nodes.HasLabel(barLabel));
                assertFalse(nodes.HasLabel(bazLabel));
                assertFalse("should only access a single node", nodes.Next());
            }
        }