Example #1
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private int createSimpleDatabase(final org.neo4j.kernel.internal.GraphDatabaseAPI graph)
        private int CreateSimpleDatabase(GraphDatabaseAPI graph)
        {
            const int numberOfNodes = 10;

            (new Transactor(graph, () =>
            {
                for (int i = 0; i < numberOfNodes; i++)
                {
                    graph.CreateNode();
                }

                foreach (Node n1 in graph.AllNodes)
                {
                    foreach (Node n2 in graph.AllNodes)
                    {
                        if (n1.Equals(n2))
                        {
                            continue;
                        }

                        n1.createRelationshipTo(n2, RelationshipType.withName("REL"));
                    }
                }
            })).execute();

            return(numberOfNodes);
        }
Example #2
0
 public BatchRelationship(long id, long startNodeId, long endNodeId, RelationshipType type)
 {
     this._id          = id;
     this._startNodeId = startNodeId;
     this._endNodeId   = endNodeId;
     this._type        = type;
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMapDirectRelationship()
        public virtual void ShouldMapDirectRelationship()
        {
            // Given
            Node         start, end;
            Relationship relationship;

            using (Transaction tx = Db.beginTx())
            {
                start        = Db.createNode();
                end          = Db.createNode();
                relationship = start.CreateRelationshipTo(end, RelationshipType.withName("R"));
                tx.Success();
            }
            RelationshipValue relationshipValue = VirtualValues.relationshipValue(relationship.Id, nodeValue(start.Id, Values.EMPTY_TEXT_ARRAY, EMPTY_MAP), nodeValue(start.Id, Values.EMPTY_TEXT_ARRAY, EMPTY_MAP), stringValue("R"), EMPTY_MAP);

            // When
            Relationship coreAPIRelationship = _mapper.mapRelationship(relationshipValue);

            // Then
            using (Transaction ignore = Db.beginTx())
            {
                assertThat(coreAPIRelationship.Id, equalTo(relationship.Id));
                assertThat(coreAPIRelationship.StartNode, equalTo(start));
                assertThat(coreAPIRelationship.EndNode, equalTo(end));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void myFriendsAsWellAsYourFriends()
        public virtual void MyFriendsAsWellAsYourFriends()
        {
            /*
             * Hey, this looks like a futuristic gun or something
             *
             *  (f8)     _----(f1)--(f5)
             *   |      /      /
             * (f7)--(you)--(me)--(f2)--(f6)
             *         |   /   \
             *         (f4)    (f3)
             */

            CreateGraph("you KNOW me", "you KNOW f1", "you KNOW f4", "me KNOW f1", "me KNOW f4", "me KNOW f2", "me KNOW f3", "f1 KNOW f5", "f2 KNOW f6", "you KNOW f7", "f7 KNOW f8");

            using (Transaction tx = BeginTx())
            {
                RelationshipType knowRelType = withName("KNOW");
                Node             you         = GetNodeWithName("you");
                Node             me          = GetNodeWithName("me");

                string[]             levelOneFriends   = new string[] { "f1", "f2", "f3", "f4", "f7" };
                TraversalDescription levelOneTraversal = GraphDb.traversalDescription().relationships(knowRelType).evaluator(atDepth(1));
                ExpectNodes(levelOneTraversal.DepthFirst().traverse(you, me), levelOneFriends);
                ExpectNodes(levelOneTraversal.BreadthFirst().traverse(you, me), levelOneFriends);

                string[]             levelTwoFriends   = new string[] { "f5", "f6", "f8" };
                TraversalDescription levelTwoTraversal = GraphDb.traversalDescription().relationships(knowRelType).evaluator(atDepth(2));
                ExpectNodes(levelTwoTraversal.DepthFirst().traverse(you, me), levelTwoFriends);
                ExpectNodes(levelTwoTraversal.BreadthFirst().traverse(you, me), levelTwoFriends);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSingleRelationshipPath()
        public virtual void ShouldHandleSingleRelationshipPath()
        {
            // Given
            Node         start, end;
            Relationship relationship;

            using (Transaction tx = Db.beginTx())
            {
                start        = Db.createNode();
                end          = Db.createNode();
                relationship = start.CreateRelationshipTo(end, RelationshipType.withName("R"));
                tx.Success();
            }

            // When
            Path mapped = _mapper.mapPath(path(AsNodeValues(start, end), AsRelationshipsValues(relationship)));

            // Then
            using (Transaction ignore = Db.beginTx())
            {
                assertThat(mapped.Length(), equalTo(1));
                assertThat(mapped.StartNode(), equalTo(start));
                assertThat(mapped.EndNode(), equalTo(end));
                assertThat(Iterables.asList(mapped.Relationships()), equalTo(singletonList(relationship)));
                assertThat(Iterables.asList(mapped.ReverseRelationships()), equalTo(singletonList(relationship)));
                assertThat(Iterables.asList(mapped.Nodes()), equalTo(Arrays.asList(start, end)));
                assertThat(Iterables.asList(mapped.ReverseNodes()), equalTo(Arrays.asList(end, start)));
                assertThat(mapped.LastRelationship(), equalTo(relationship));
                assertThat(Iterators.asList(mapped.GetEnumerator()), equalTo(Arrays.asList(start, relationship, end)));
            }
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode()
        public virtual void ShouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode()
        {
            RelationshipType type = MyRelTypes.TEST;
            long             startId;
            long             endId;
            Relationship     rel;

            using (Transaction tx = Db.beginTx())
            {
                Node start = Db.createNode();
                Node end   = Db.createNode();
                startId = start.Id;
                endId   = end.Id;
                rel     = start.CreateRelationshipTo(end, type);
                rel.SetProperty("Type", type.Name());
                tx.Success();
            }

            using (Transaction tx = Db.beginTx())
            {
                ReadableRelationshipIndex autoRelationshipIndex = Db.index().RelationshipAutoIndexer.AutoIndex;
                Node start = Db.getNodeById(startId);
                Node end   = Db.getNodeById(endId);
                IndexHits <Relationship> hits = autoRelationshipIndex.Get("Type", type.Name(), start, end);
                assertEquals(1, count(hits));
                assertEquals(1, hits.Size());
                rel.Delete();
                autoRelationshipIndex = Db.index().RelationshipAutoIndexer.AutoIndex;
                hits = autoRelationshipIndex.Get("Type", type.Name(), start, end);
                assertEquals(0, count(hits));
                assertEquals(0, hits.Size());
                tx.Success();
            }
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void validateExplicitIndexedRelationshipProperties()
        internal virtual void ValidateExplicitIndexedRelationshipProperties()
        {
            setUp();
            Label            label        = Label.label("explicitIndexedRelationshipPropertiesTestLabel");
            string           propertyName = "explicitIndexedRelationshipProperties";
            string           explicitIndexedRelationshipIndex = "explicitIndexedRelationshipIndex";
            RelationshipType indexType = RelationshipType.withName("explicitIndexType");

            using (Transaction transaction = _database.beginTx())
            {
                Node         source       = _database.createNode(label);
                Node         destination  = _database.createNode(label);
                Relationship relationship = source.CreateRelationshipTo(destination, indexType);
                _database.index().forRelationships(explicitIndexedRelationshipIndex).add(relationship, propertyName, "shortString");
                transaction.Success();
            }

            System.ArgumentException argumentException = assertThrows(typeof(System.ArgumentException), () =>
            {
                using (Transaction transaction = _database.beginTx())
                {
                    Node source               = _database.createNode(label);
                    Node destination          = _database.createNode(label);
                    Relationship relationship = source.createRelationshipTo(destination, indexType);
                    string longValue          = StringUtils.repeat("a", IndexWriter.MAX_TERM_LENGTH + 1);
                    _database.index().forRelationships(explicitIndexedRelationshipIndex).add(relationship, propertyName, longValue);
                    transaction.Success();
                }
            });
            assertEquals("Property value size is too large for index. Please see index documentation for limitations.", argumentException.Message);
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPropagateRelationshipCountsInHA() throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPropagateRelationshipCountsInHA()
        {
            ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase master = cluster.Master;

            using (Transaction tx = master.BeginTx())
            {
                Node left  = master.CreateNode();
                Node right = master.CreateNode(Label.label("A"));
                left.CreateRelationshipTo(right, RelationshipType.withName("Type"));
                tx.Success();
            }

            cluster.Sync();

            foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers)
            {
                using ([email protected] tx = Db.DependencyResolver.resolveDependency(typeof(Kernel)).beginTransaction(@explicit, AUTH_DISABLED))
                {
                    assertEquals(1, tx.dataRead().countsForRelationship(-1, -1, -1));
                    assertEquals(1, tx.dataRead().countsForRelationship(-1, -1, 0));
                    assertEquals(1, tx.dataRead().countsForRelationship(-1, 0, -1));
                    assertEquals(1, tx.dataRead().countsForRelationship(-1, 0, 0));
                }
            }
        }
Example #9
0
        /// <summary>
        /// Used by cc </summary>
        /// <param name="db"> </param>
        /// <param name="tx"> </param>
        public static void CreateSomeData(GraphDatabaseService db, Transaction tx)
        {
            Node node = Db.createNode();

            node.SetProperty(PROP_NAME, "Neo");
            node.SetProperty(PROP_RANDOM, GlobalRandom.NextDouble * 10000);
            Db.createNode().createRelationshipTo(node, RelationshipType.withName("KNOWS"));
            tx.Success();
        }
Example #10
0
 /// <summary>
 /// Transactional version of <seealso cref="countsForRelationship(Label, RelationshipType, Label)"/>
 /// </summary>
 private MatchingRelationships NumberOfRelationshipsMatching(Label lhs, RelationshipType type, Label rhs)
 {
     using (Transaction tx = Db.GraphDatabaseAPI.beginTx())
     {
         long nodeCount = CountsForRelationship(lhs, type, rhs);
         tx.Success();
         return(new MatchingRelationships(string.Format("({0})-{1}->({2})", lhs == null ? "" : ":" + lhs.Name(), type == null ? "" : "[:" + type.Name() + "]", rhs == null ? "" : ":" + rhs.Name()), nodeCount));
     }
 }
Example #11
0
 /// <summary>
 /// Transactional version of <seealso cref="countsForRelationship(Label, RelationshipType, Label)"/> </summary>
 private long NumberOfRelationshipsMatching(Label lhs, RelationshipType type, Label rhs)
 {
     using (Transaction tx = Db.GraphDatabaseAPI.beginTx())
     {
         long nodeCount = CountsForRelationship(lhs, type, rhs);
         tx.Success();
         return(nodeCount);
     }
 }
Example #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: Object get(org.neo4j.kernel.internal.GraphDatabaseAPI graphDb, ParameterList parameters, String name) throws org.neo4j.server.rest.repr.BadInputException
        internal override object Get(GraphDatabaseAPI graphDb, ParameterList parameters, string name)
        {
            string typeName = parameters.GetString(name);

            if (string.ReferenceEquals(typeName, null))
            {
                return(null);
            }
            return(RelationshipType.withName(typeName));
        }
Example #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: Object[] getList(org.neo4j.kernel.internal.GraphDatabaseAPI graphDb, ParameterList parameters, String name) throws org.neo4j.server.rest.repr.BadInputException
        internal override object[] GetList(GraphDatabaseAPI graphDb, ParameterList parameters, string name)
        {
            string[] strings = parameters.GetStringList(name);
            if (strings == null)
            {
                return(null);
            }
            RelationshipType[] result = new RelationshipType[strings.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = RelationshipType.withName(strings[i]);
            }
            return(result);
        }
Example #14
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));
            }
        }
Example #15
0
        internal static void CreateData(GraphDatabaseService db, int size)
        {
            for (int i = 0; i < size; i++)
            {
                Node node1 = Db.createNode(_label);
                Node node2 = Db.createNode(_label);

                node1.SetProperty(PROPERTY_KEY, "svej" + i);
                node2.SetProperty("tjabba", "tjena");
                node1.SetProperty("foobar", "baz_bat");
                node2.SetProperty("foobar", "baz_bat");

                Relationship rel = node1.CreateRelationshipTo(node2, RelationshipType.withName("halla"));
                rel.SetProperty("this", "that");
            }
        }
Example #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateACountStoreWhenDBContainsDenseNodes()
        public virtual void ShouldCreateACountStoreWhenDBContainsDenseNodes()
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("deprecation") final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) dbBuilder.setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.dense_node_threshold, "2").newGraphDatabase();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.setConfig(GraphDatabaseSettings.dense_node_threshold, "2").newGraphDatabase();

            using (Transaction tx = Db.beginTx())
            {
                Node nodeA = Db.createNode(Label.label("A"));
                Node nodeC = Db.createNode(Label.label("C"));
                Node nodeD = Db.createNode(Label.label("D"));
                nodeA.CreateRelationshipTo(nodeA, RelationshipType.withName("TYPE1"));
                nodeA.CreateRelationshipTo(nodeC, RelationshipType.withName("TYPE2"));
                nodeA.CreateRelationshipTo(nodeD, RelationshipType.withName("TYPE3"));
                nodeD.CreateRelationshipTo(nodeC, RelationshipType.withName("TYPE4"));
                tx.Success();
            }
            long lastCommittedTransactionId = GetLastTxId(db);

            Db.shutdown();

            RebuildCounts(lastCommittedTransactionId);

            using (Lifespan life = new Lifespan())
            {
                CountsTracker store = life.Add(CreateCountsTracker());
                assertEquals(BASE_TX_ID + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1, store.TxId());
                assertEquals(22, store.TotalEntriesStored());
                assertEquals(3, Get(store, nodeKey(-1)));
                assertEquals(1, Get(store, nodeKey(0)));
                assertEquals(1, Get(store, nodeKey(1)));
                assertEquals(1, Get(store, nodeKey(2)));
                assertEquals(0, Get(store, nodeKey(3)));
                assertEquals(4, Get(store, relationshipKey(-1, -1, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 0, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 1, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 2, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 3, -1)));
                assertEquals(0, Get(store, relationshipKey(-1, 4, -1)));
                assertEquals(1, Get(store, relationshipKey(-1, 1, 1)));
                assertEquals(2, Get(store, relationshipKey(-1, -1, 1)));
                assertEquals(3, Get(store, relationshipKey(0, -1, -1)));
            }
        }
Example #17
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()
        {
            _cluster = ClusterRule.startCluster();
            _slave   = _cluster.AnySlave;

            // Create some basic data
            using (Transaction tx = _slave.beginTx())
            {
                Node node = _slave.createNode(Label.label("Person"));
                node.SetProperty("name", "Bob");
                node.CreateRelationshipTo(_slave.createNode(), RelationshipType.withName("KNOWS"));

                tx.Success();
            }

            // And now monitor the master for incoming calls
            _cluster.Master.DependencyResolver.resolveDependency(typeof(Monitors)).addMonitorListener(_masterMonitor);
        }
Example #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void createStore(java.io.File super, org.neo4j.io.fs.FileSystemAbstraction fileSystem, String dbName, int nodesToCreate, String recordFormat, boolean recoveryNeeded, String logicalLogsLocation) throws java.io.IOException
            internal static void CreateStore(File @base, FileSystemAbstraction fileSystem, string dbName, int nodesToCreate, string recordFormat, bool recoveryNeeded, string logicalLogsLocation)
            {
                File storeDir           = new File(@base, dbName);
                GraphDatabaseService db = (new TestGraphDatabaseFactory()).setFileSystem(fileSystem).newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.record_format, recordFormat).setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString()).setConfig(GraphDatabaseSettings.logical_logs_location, logicalLogsLocation).newGraphDatabase();

                for (int i = 0; i < (nodesToCreate / 2); i++)
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        Node node1 = Db.createNode(Label.label("Label-" + i));
                        Node node2 = Db.createNode(Label.label("Label-" + i));
                        node1.CreateRelationshipTo(node2, RelationshipType.withName("REL-" + i));
                        tx.Success();
                    }
                }

                if (recoveryNeeded)
                {
                    File tmpLogs = new File(@base, "unrecovered");
                    fileSystem.Mkdir(tmpLogs);
                    File txLogsDir = new File(storeDir, logicalLogsLocation);
                    foreach (File file in fileSystem.ListFiles(txLogsDir, TransactionLogFiles.DEFAULT_FILENAME_FILTER))
                    {
                        fileSystem.CopyFile(file, new File(tmpLogs, file.Name));
                    }

                    Db.shutdown();

                    foreach (File file in fileSystem.ListFiles(txLogsDir, TransactionLogFiles.DEFAULT_FILENAME_FILTER))
                    {
                        fileSystem.DeleteFile(file);
                    }

                    foreach (File file in fileSystem.ListFiles(tmpLogs, TransactionLogFiles.DEFAULT_FILENAME_FILTER))
                    {
                        fileSystem.CopyFile(file, new File(txLogsDir, file.Name));
                    }
                }
                else
                {
                    Db.shutdown();
                }
            }
Example #19
0
 internal virtual long DeleteNeighbours(Node node, RelationshipType relType)
 {
     try
     {
         long deleted = 0;
         foreach (Relationship rel in node.Relationships)
         {
             Node other = rel.GetOtherNode(node);
             rel.Delete();
             other.Delete();
             deleted++;
         }
         return(deleted);
     }
     catch (NotFoundException)
     {
         // Procedures should internally handle missing nodes due to lazy interactions
         return(0);
     }
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void should_remove_all_data()
        public virtual void ShouldRemoveAllData()
        {
            using (Transaction tx = _db.beginTx())
            {
                RelationshipType relationshipType = RelationshipType.withName("R");

                Node n1 = _db.createNode();
                Node n2 = _db.createNode();
                Node n3 = _db.createNode();

                n1.CreateRelationshipTo(n2, relationshipType);
                n2.CreateRelationshipTo(n1, relationshipType);
                n3.CreateRelationshipTo(n1, relationshipType);

                tx.Success();
            }

            CleanDatabaseContent(_db);

            assertThat(NodeCount(), @is(0L));
        }
Example #21
0
 internal static void CreateTestData(GraphDatabaseService db)
 {
     using (Transaction tx = Db.beginTx())
     {
         Label            label            = Label.label("Label");
         RelationshipType relationshipType = RelationshipType.withName("REL");
         long[]           largeValue       = new long[1024];
         for (int i = 0; i < 1000; i++)
         {
             Node node = Db.createNode(label);
             node.SetProperty("Niels", "Borh");
             node.SetProperty("Albert", largeValue);
             for (int j = 0; j < 30; j++)
             {
                 Relationship rel = node.CreateRelationshipTo(node, relationshipType);
                 rel.SetProperty("Max", "Planck");
             }
         }
         tx.Success();
     }
 }
Example #22
0
        private void CreateChainOfNodesWithLabelAndProperty(int length, string relationshipName, string labelName, string property, string value)
        {
            RelationshipType relationshipType = RelationshipType.withName(relationshipName);
            Label            label            = Label.label(labelName);
            Node             prev             = null;

            for (int i = 0; i < length; i++)
            {
                Node node = _db.createNode(label);
                node.SetProperty(property, value);
                if (!property.Equals("name"))
                {
                    node.SetProperty("name", labelName + " " + i);
                }
                if (prev != null)
                {
                    prev.CreateRelationshipTo(node, relationshipType);
                }
                prev = node;
            }
        }
Example #23
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()
        {
            for (int i = 0; i < 100; i++)
            {
                using (Transaction tx = Db.beginTx())
                {
                    Node prev = null;
                    for (int j = 0; j < 100; j++)
                    {
                        Node node = Db.createNode(label("L"));

                        if (prev != null)
                        {
                            Relationship rel = prev.CreateRelationshipTo(node, RelationshipType.withName("T"));
                            rel.SetProperty("prop", i + j);
                        }
                        prev = node;
                    }
                    tx.Success();
                }
            }
        }
Example #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void question5346011()
        public virtual void Question5346011()
        {
            GraphDatabaseService service = (new TestGraphDatabaseFactory()).newImpermanentDatabase();

            using (Transaction tx = service.BeginTx())
            {
                RelationshipIndex index = service.Index().forRelationships("exact");
                // ...creation of the nodes and relationship
                Node         node1        = service.CreateNode();
                Node         node2        = service.CreateNode();
                string       uuid         = "xyz";
                Relationship relationship = node1.CreateRelationshipTo(node2, RelationshipType.withName("related"));
                index.add(relationship, "uuid", uuid);
                // query
                using (IndexHits <Relationship> hits = index.Get("uuid", uuid, node1, node2))
                {
                    assertEquals(1, hits.Size());
                }
                tx.Success();
            }
            service.Shutdown();
        }
Example #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPrintCypherEsqueRelationshipToString()
        public virtual void ShouldPrintCypherEsqueRelationshipToString()
        {
            // GIVEN
            Node             start;
            Node             end;
            RelationshipType type = RelationshipType.withName("NICE");
            Relationship     relationship;

            using (Transaction tx = Db.beginTx())
            {
                // GIVEN
                start        = Db.createNode();
                end          = Db.createNode();
                relationship = start.CreateRelationshipTo(end, type);
                tx.Success();

                // WHEN
                string toString = relationship.ToString();

                // THEN
                assertEquals("(" + start.Id + ")-[" + type + "," + relationship.Id + "]->(" + end.Id + ")", toString);
            }
        }
Example #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleLongPath()
        public virtual void ShouldHandleLongPath()
        {
            // Given
            Node         a, b, c, d, e;
            Relationship r1, r2, r3, r4;

            using (Transaction tx = Db.beginTx())
            {
                a  = Db.createNode();
                b  = Db.createNode();
                c  = Db.createNode();
                d  = Db.createNode();
                e  = Db.createNode();
                r1 = a.CreateRelationshipTo(b, RelationshipType.withName("R"));
                r2 = b.CreateRelationshipTo(c, RelationshipType.withName("R"));
                r3 = c.CreateRelationshipTo(d, RelationshipType.withName("R"));
                r4 = d.CreateRelationshipTo(e, RelationshipType.withName("R"));
                tx.Success();
            }

            // When
            Path mapped = _mapper.mapPath(path(AsNodeValues(a, b, c, d, e), AsRelationshipsValues(r1, r2, r3, r4)));

            // Then
            using (Transaction ignore = Db.beginTx())
            {
                assertThat(mapped.Length(), equalTo(4));
                assertThat(mapped.StartNode(), equalTo(a));
                assertThat(mapped.EndNode(), equalTo(e));
                assertThat(Iterables.asList(mapped.Relationships()), equalTo(Arrays.asList(r1, r2, r3, r4)));
                assertThat(Iterables.asList(mapped.ReverseRelationships()), equalTo(Arrays.asList(r4, r3, r2, r1)));
                assertThat(Iterables.asList(mapped.Nodes()), equalTo(Arrays.asList(a, b, c, d, e)));
                assertThat(Iterables.asList(mapped.ReverseNodes()), equalTo(Arrays.asList(e, d, c, b, a)));
                assertThat(mapped.LastRelationship(), equalTo(r4));
                assertThat(Iterators.asList(mapped.GetEnumerator()), equalTo(Arrays.asList(a, r1, b, r2, c, r3, d, r4, e)));
            }
        }
Example #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canAvoidDeadlockThatWouldHappenIfTheRelationshipTypeCreationTransactionModifiedData()
        public virtual void CanAvoidDeadlockThatWouldHappenIfTheRelationshipTypeCreationTransactionModifiedData()
        {
            GraphDatabaseService graphdb = Database.GraphDatabaseAPI;
            Node node = null;

            using (Transaction tx = graphdb.BeginTx())
            {
                node = graphdb.CreateNode();
                node.SetProperty("counter", 0L);
                tx.Success();
            }

            graphdb.RegisterTransactionEventHandler(new RelationshipCounterTransactionEventHandler(node));

            using (Transaction tx = graphdb.BeginTx())
            {
                node.SetProperty("state", "not broken yet");
                node.CreateRelationshipTo(graphdb.CreateNode(), RelationshipType.withName("TEST"));
                node.RemoveProperty("state");
                tx.Success();
            }

            assertThat(node, inTx(graphdb, hasProperty("counter").withValue(1L)));
        }
Example #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAcceptValuesWithNullToString() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAcceptValuesWithNullToString()
        {
            using (Transaction tx = Db.beginTx())
            {
                Node              node              = Db.createNode();
                Node              otherNode         = Db.createNode();
                Relationship      rel               = node.CreateRelationshipTo(otherNode, RelationshipType.withName("recovery"));
                Index <Node>      nodeIndex         = Db.index().forNodes("node-index");
                RelationshipIndex relationshipIndex = Db.index().forRelationships("rel-index");

                // Add
                AssertAddFailsWithIllegalArgument(nodeIndex, node, "key1", new ClassWithToStringAlwaysNull());
                AssertAddFailsWithIllegalArgument(relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull());

                // Remove
                AssertRemoveFailsWithIllegalArgument(nodeIndex, node, "key1", new ClassWithToStringAlwaysNull());
                AssertRemoveFailsWithIllegalArgument(relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull());
                tx.Success();
            }

            ForceRecover();
        }
Example #29
0
 public RelationshipPropertyExistenceConstraintDefinition(InternalSchemaActions actions, RelationshipType relationshipType, string propertyKey) : base(actions, relationshipType, propertyKey)
 {
 }
Example #30
0
 public virtual Stream <Output> DeleteNeighboursNotEagerized(Node node, string relation)
 {
     return(Stream.of(new Output(DeleteNeighbours(node, RelationshipType.withName(relation)))));
 }