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 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))));
            }
        }
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 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)));
            }
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
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());
            }
        }