public virtual Stream <NodeResult> CreateNodeWithLoop(string label, string relType) { Node node = Db.createNode(Label.label(label)); node.CreateRelationshipTo(node, RelationshipType.withName(relType)); return(Stream.of(new NodeResult(node))); }
private void CreateSomeTransactions(GraphDatabaseService db) { Transaction tx = Db.beginTx(); Node node1 = Db.createNode(); Node node2 = Db.createNode(); node1.CreateRelationshipTo(node2, RelationshipType.withName("relType1")); tx.Success(); tx.Close(); tx = Db.beginTx(); node1.Delete(); tx.Success(); try { // Will throw exception, causing the tx to be rolledback. tx.Close(); } catch (Exception) { // InvalidRecordException coming, node1 has rels } /* * The damage has already been done. The following just makes sure * the corrupting tx is flushed to disk, since we will exit * uncleanly. */ tx = Db.beginTx(); node1.SetProperty("foo", "bar"); tx.Success(); tx.Close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testRemoveRelationshipRemovesDocument() public virtual void TestRemoveRelationshipRemovesDocument() { NewTransaction(); AutoIndexer <Relationship> autoIndexer = _graphDb.index().RelationshipAutoIndexer; autoIndexer.StartAutoIndexingProperty("foo"); autoIndexer.Enabled = true; Node node1 = _graphDb.createNode(); Node node2 = _graphDb.createNode(); Relationship rel = node1.CreateRelationshipTo(node2, RelationshipType.withName("foo")); rel.SetProperty("foo", "bar"); NewTransaction(); using (IndexHits <Relationship> relationshipIndexHits = _graphDb.index().forRelationships("relationship_auto_index").query("_id_:*")) { assertThat(relationshipIndexHits.Size(), equalTo(1)); } NewTransaction(); rel.Delete(); NewTransaction(); using (IndexHits <Relationship> relationshipIndexHits = _graphDb.index().forRelationships("relationship_auto_index").query("_id_:*")) { assertThat(relationshipIndexHits.Size(), equalTo(0)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void nonRecoveredDatabase() throws java.io.IOException private void NonRecoveredDatabase() { File tmpLogDir = new File(_testDirectory.directory(), "logs"); _fs.mkdir(tmpLogDir); File storeDir = _testDirectory.databaseDir(); GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.record_format, RecordFormatName).setConfig("dbms.backup.enabled", "false").newGraphDatabase(); RelationshipType relationshipType = RelationshipType.withName("testRelationshipType"); using (Transaction tx = Db.beginTx()) { Node node1 = set(Db.createNode()); Node node2 = set(Db.createNode(), property("key", "value")); node1.CreateRelationshipTo(node2, relationshipType); tx.Success(); } File[] txLogs = LogFilesBuilder.logFilesBasedOnlyBuilder(storeDir, _fs).build().logFiles(); foreach (File file in txLogs) { _fs.copyToDirectory(file, tmpLogDir); } Db.shutdown(); foreach (File txLog in txLogs) { _fs.deleteFile(txLog); } foreach (File file in LogFilesBuilder.logFilesBasedOnlyBuilder(tmpLogDir, _fs).build().logFiles()) { _fs.moveToDirectory(file, storeDir); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void startDb() public virtual void StartDb() { _graphDb = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newImpermanentDatabaseBuilder().setConfig(new Dictionary <string, string>()).newGraphDatabase(); using (Transaction tx = _graphDb.beginTx()) { // Create the node and relationship auto-indexes _graphDb.index().NodeAutoIndexer.Enabled = true; _graphDb.index().NodeAutoIndexer.startAutoIndexingProperty("nodeProp"); _graphDb.index().RelationshipAutoIndexer.Enabled = true; _graphDb.index().RelationshipAutoIndexer.startAutoIndexingProperty("type"); tx.Success(); } using (Transaction tx = _graphDb.beginTx()) { Node node1 = _graphDb.createNode(); Node node2 = _graphDb.createNode(); Node node3 = _graphDb.createNode(); _id1 = node1.Id; _id2 = node2.Id; _id3 = node3.Id; Relationship rel = node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO")); rel.SetProperty("type", "FOO"); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustBeAbleToConsistencyCheckRelationshipIndexWithMultipleRelationshipTypesAndOneProperty() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustBeAbleToConsistencyCheckRelationshipIndexWithMultipleRelationshipTypesAndOneProperty() { GraphDatabaseService db = CreateDatabase(); RelationshipType relType1 = RelationshipType.withName("R1"); RelationshipType relType2 = RelationshipType.withName("R2"); using (Transaction tx = Db.beginTx()) { Db.execute(format(RELATIONSHIP_CREATE, "rels", array("R1", "R2"), array("p1"))).close(); tx.Success(); } using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES); Node n1 = Db.createNode(); Node n2 = Db.createNode(); n1.CreateRelationshipTo(n1, relType1).setProperty("p1", "value"); n1.CreateRelationshipTo(n1, relType2).setProperty("p1", "value"); n2.CreateRelationshipTo(n2, relType1).setProperty("p1", "value"); n2.CreateRelationshipTo(n2, relType2).setProperty("p1", "value"); tx.Success(); } Db.shutdown(); AssertIsConsistent(CheckConsistency()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustBeAbleToConsistencyCheckRelationshipIndexWithOneRelationshipTypeAndMultipleProperties() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustBeAbleToConsistencyCheckRelationshipIndexWithOneRelationshipTypeAndMultipleProperties() { GraphDatabaseService db = CreateDatabase(); RelationshipType relationshipType = RelationshipType.withName("R1"); using (Transaction tx = Db.beginTx()) { Db.execute(format(RELATIONSHIP_CREATE, "rels", array("R1"), array("p1", "p2"))).close(); tx.Success(); } using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES); Node node = Db.createNode(); Relationship r1 = node.CreateRelationshipTo(node, relationshipType); r1.SetProperty("p1", "value"); r1.SetProperty("p2", "value"); Relationship r2 = node.CreateRelationshipTo(node, relationshipType); // This relationship will have a different id value than the node. r2.SetProperty("p1", "value"); r2.SetProperty("p2", "value"); node.CreateRelationshipTo(node, relationshipType).setProperty("p1", "value"); node.CreateRelationshipTo(node, relationshipType).setProperty("p2", "value"); tx.Success(); } Db.shutdown(); AssertIsConsistent(CheckConsistency()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustBeAbleToConsistencyCheckNodeAndRelationshipIndexesAtTheSameTime() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustBeAbleToConsistencyCheckNodeAndRelationshipIndexesAtTheSameTime() { GraphDatabaseService db = CreateDatabase(); using (Transaction tx = Db.beginTx()) { Db.execute(format(NODE_CREATE, "nodes", array("L1", "L2", "L3"), array("p1", "p2"))).close(); Db.execute(format(RELATIONSHIP_CREATE, "rels", array("R1", "R2"), array("p1", "p2"))).close(); tx.Success(); } using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES); Node n1 = Db.createNode(Label.label("L1"), Label.label("L3")); n1.SetProperty("p1", "value"); n1.SetProperty("p2", "value"); n1.CreateRelationshipTo(n1, RelationshipType.withName("R2")).setProperty("p1", "value"); Node n2 = Db.createNode(Label.label("L2")); n2.SetProperty("p2", "value"); Relationship r1 = n2.CreateRelationshipTo(n2, RelationshipType.withName("R1")); r1.SetProperty("p1", "value"); r1.SetProperty("p2", "value"); tx.Success(); } Db.shutdown(); AssertIsConsistent(CheckConsistency()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void createAndQueryFulltextRelationshipIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CreateAndQueryFulltextRelationshipIndex() { FulltextIndexProvider provider = ( FulltextIndexProvider )Db.resolveDependency(typeof(IndexProviderMap)).lookup(DESCRIPTOR); IndexReference indexReference; using (KernelTransactionImplementation transaction = KernelTransaction) { MultiTokenSchemaDescriptor multiTokenSchemaDescriptor = multiToken(new int[] { 0, 1, 2 }, EntityType.RELATIONSHIP, 0, 1, 2, 3); FulltextSchemaDescriptor schema = new FulltextSchemaDescriptor(multiTokenSchemaDescriptor, new Properties()); indexReference = transaction.SchemaWrite().indexCreate(schema, DESCRIPTOR.name(), "fulltext"); transaction.Success(); } Await(indexReference); long secondRelId; using (Transaction transaction = Db.beginTx()) { Relationship ho = _node1.createRelationshipTo(_node2, RelationshipType.withName("ho")); secondRelId = ho.Id; ho.SetProperty("hej", "villa"); ho.SetProperty("ho", "value3"); transaction.Success(); } VerifyRelationshipData(provider, secondRelId); Db.restartDatabase(DatabaseRule.RestartAction_Fields.EMPTY); provider = ( FulltextIndexProvider )Db.resolveDependency(typeof(IndexProviderMap)).lookup(DESCRIPTOR); VerifyRelationshipData(provider, secondRelId); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") public static org.neo4j.graphdb.PathExpander describeRelationships(java.util.Map<String, Object> description) public static PathExpander DescribeRelationships(IDictionary <string, object> description) { PathExpanderBuilder expander = PathExpanderBuilder.allTypesAndDirections(); object relationshipsDescription = description["relationships"]; if (relationshipsDescription != null) { ICollection <object> pairDescriptions; if (relationshipsDescription is System.Collections.ICollection) { pairDescriptions = (ICollection <object>)relationshipsDescription; } else { pairDescriptions = Arrays.asList(relationshipsDescription); } foreach (object pairDescription in pairDescriptions) { System.Collections.IDictionary map = (System.Collections.IDictionary)pairDescription; string name = ( string )map["type"]; RelationshipType type = RelationshipType.withName(name); string directionName = ( string )map["direction"]; expander = (string.ReferenceEquals(directionName, null)) ? expander.Add(type) : expander.Add(type, StringToEnum(directionName, typeof(RelationshipDirection), true).@internal); } } return(expander.Build()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testCircularBug() public virtual void TestCircularBug() { const long timestamp = 3; using (Transaction tx = BeginTx()) { GetNodeWithName("2").setProperty("timestamp", 1L); GetNodeWithName("3").setProperty("timestamp", 2L); tx.Success(); } using (Transaction tx2 = BeginTx()) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.RelationshipType type = org.neo4j.graphdb.RelationshipType.withName("TO"); RelationshipType type = RelationshipType.withName("TO"); IEnumerator <Node> nodes = GraphDb.traversalDescription().depthFirst().relationships(type, Direction.OUTGOING).evaluator(path => { Relationship rel = path.lastRelationship(); bool relIsOfType = rel != null && rel.isType(type); bool prune = relIsOfType && ( long? )path.endNode().getProperty("timestamp").Value >= timestamp; return(Evaluation.of(relIsOfType, !prune)); }).traverse(Node("1")).nodes().GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals("2", nodes.next().getProperty("name")); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals("3", nodes.next().getProperty("name")); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(nodes.hasNext()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUpdatePropertyToRelationshipInTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldUpdatePropertyToRelationshipInTransaction() { // Given long relationshipId; string propertyKey = "prop"; using (Org.Neo4j.Graphdb.Transaction tx = graphDb.beginTx()) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); relationshipId = node1.CreateRelationshipTo(node2, RelationshipType.withName("R")).Id; tx.Success(); } // When using (Transaction tx = beginTransaction()) { int token = tx.token().propertyKeyGetOrCreateForName(propertyKey); assertThat(tx.dataWrite().relationshipSetProperty(relationshipId, token, stringValue("hello")), equalTo(NO_VALUE)); assertThat(tx.dataWrite().relationshipSetProperty(relationshipId, token, stringValue("world")), equalTo(stringValue("hello"))); assertThat(tx.dataWrite().relationshipSetProperty(relationshipId, token, intValue(1337)), equalTo(stringValue("world"))); tx.Success(); } // Then using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx()) { assertThat(graphDb.getRelationshipById(relationshipId).getProperty("prop"), equalTo(1337)); } }
public virtual Path PathToReference(Node me) { PathFinder <Path> finder = GraphAlgoFactory.shortestPath(PathExpanders.allTypesAndDirections(), 6); using (Transaction tx = me.GraphDatabase.beginTx()) { Node other; if (me.hasRelationship(RelationshipType.withName("friend"))) { ResourceIterable <Relationship> relationships = (ResourceIterable <Relationship>)me.getRelationships(RelationshipType.withName("friend")); using (ResourceIterator <Relationship> resourceIterator = relationships.GetEnumerator()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: other = resourceIterator.next().getOtherNode(me); } } else { other = me.GraphDatabase.createNode(); } Path path = finder.FindSinglePath(other, me); tx.Success(); return(path); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotWriteWhenSettingPropertyToSameValue() { // Given long relationshipId; string propertyKey = "prop"; Value theValue = stringValue("The Value"); using (Org.Neo4j.Graphdb.Transaction ctx = graphDb.beginTx()) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Relationship r = node1.CreateRelationshipTo(node2, RelationshipType.withName("R")); r.SetProperty(propertyKey, theValue.AsObject()); relationshipId = r.Id; ctx.Success(); } // When Transaction tx = beginTransaction(); int property = tx.Token().propertyKeyGetOrCreateForName(propertyKey); assertThat(tx.DataWrite().relationshipSetProperty(relationshipId, property, theValue), equalTo(theValue)); tx.Success(); assertThat(tx.CloseTransaction(), equalTo(Transaction_Fields.READ_ONLY)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeleteRelationship() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDeleteRelationship() { long n1, r; using (Org.Neo4j.Graphdb.Transaction tx = graphDb.beginTx()) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); n1 = node1.Id; r = node1.CreateRelationshipTo(node2, RelationshipType.withName("R")).Id; tx.Success(); } using (Transaction tx = beginTransaction()) { assertTrue("should delete relationship", tx.dataWrite().relationshipDelete(r)); tx.Success(); } using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx()) { assertEquals(0, graphDb.getNodeById(n1).Degree); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRemovePropertyFromRelationshipTwice() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRemovePropertyFromRelationshipTwice() { // Given long relationshipId; string propertyKey = "prop"; using (Org.Neo4j.Graphdb.Transaction tx = graphDb.beginTx()) { Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); Relationship proxy = node1.CreateRelationshipTo(node2, RelationshipType.withName("R")); relationshipId = proxy.Id; proxy.SetProperty(propertyKey, 42); tx.Success(); } // When using (Transaction tx = beginTransaction()) { int token = tx.token().propertyKeyGetOrCreateForName(propertyKey); assertThat(tx.dataWrite().relationshipRemoveProperty(relationshipId, token), equalTo(intValue(42))); assertThat(tx.dataWrite().relationshipRemoveProperty(relationshipId, token), equalTo(NO_VALUE)); tx.Success(); } // Then using (Org.Neo4j.Graphdb.Transaction ignore = graphDb.beginTx()) { assertFalse(graphDb.getRelationshipById(relationshipId).hasProperty("prop")); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGiveHelpfulExceptionWhenDeletingNodeWithRels() public virtual void ShouldGiveHelpfulExceptionWhenDeletingNodeWithRels() { // Given GraphDatabaseService db = this.Db.GraphDatabaseAPI; Node node; using (Transaction tx = Db.beginTx()) { node = Db.createNode(); node.CreateRelationshipTo(Db.createNode(), RelationshipType.withName("MAYOR_OF")); tx.Success(); } // And given a transaction deleting just the node Transaction tx = Db.beginTx(); node.Delete(); tx.Success(); // Expect Exception.expect(typeof(ConstraintViolationException)); Exception.expectMessage("Cannot delete node<" + node.Id + ">, because it still has relationships. " + "To delete this node, you must first delete its relationships."); // When I commit tx.Close(); }
private void CreateDbWithExplicitIndexAt(File fromPath, int pairNumberOfNodesToCreate) { GraphDatabaseService db = CreateDatabase(fromPath, fromPath.AbsolutePath); Index <Node> explicitNodeIndex; RelationshipIndex explicitRelationshipIndex; using (Transaction transaction = Db.beginTx()) { explicitNodeIndex = Db.index().forNodes("explicitNodeIndex"); explicitRelationshipIndex = Db.index().forRelationships("explicitRelationshipIndex"); transaction.Success(); } using (Transaction tx = Db.beginTx()) { for (int i = 0; i < pairNumberOfNodesToCreate; i += 2) { Node node = Db.createNode(); Node otherNode = Db.createNode(); Relationship relationship = node.CreateRelationshipTo(otherNode, RelationshipType.withName("rel")); explicitNodeIndex.Add(node, "a", "b"); explicitNodeIndex.Add(otherNode, "c", "d"); explicitRelationshipIndex.add(relationship, "x", "y"); } tx.Success(); } Db.shutdown(); }
private DbRepresentation CreateTransactionWithWeirdRelationshipGroupRecord(File path) { _db = StartGraphDatabase(path); int i = 0; Node node; RelationshipType typeToDelete = RelationshipType.withName("A"); RelationshipType theOtherType = RelationshipType.withName("B"); int defaultDenseNodeThreshold = int.Parse(GraphDatabaseSettings.dense_node_threshold.DefaultValue); using (Transaction tx = _db.beginTx()) { node = _db.createNode(); for ( ; i < defaultDenseNodeThreshold - 1; i++) { node.CreateRelationshipTo(_db.createNode(), theOtherType); } node.CreateRelationshipTo(_db.createNode(), typeToDelete); tx.Success(); } using (Transaction tx = _db.beginTx()) { node.CreateRelationshipTo(_db.createNode(), theOtherType); foreach (Relationship relationship in node.GetRelationships(Direction.BOTH, typeToDelete)) { relationship.Delete(); } tx.Success(); } DbRepresentation result = DbRepresentation.of(_db); _db.shutdown(); return(result); }
/* * Tests for a particular bug with dense nodes. It used to be that if a dense node had relationships * for only one direction, if a request for relationships of the other direction was made, no relationships * would be returned, ever. */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned() public virtual void GivenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned() { // Given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int denseNodeThreshold = int.Parse(org.neo4j.graphdb.factory.GraphDatabaseSettings.dense_node_threshold.getDefaultValue()) + 1; int denseNodeThreshold = int.Parse(GraphDatabaseSettings.dense_node_threshold.DefaultValue) + 1; Node node1; using (Transaction tx = Db.beginTx()) { node1 = Db.createNode(); Node node2 = Db.createNode(); for (int i = 0; i < denseNodeThreshold; i++) { node1.CreateRelationshipTo(node2, RelationshipType.withName("FOO")); } tx.Success(); } // When/Then using (Transaction ignored = Db.beginTx()) { Node node1b = Db.getNodeById(node1.Id); IEnumerable <Relationship> rels = node1b.GetRelationships(Direction.INCOMING); assertEquals(0, Iterables.count(rels)); IEnumerable <Relationship> rels2 = node1b.GetRelationships(Direction.OUTGOING); assertEquals(denseNodeThreshold, Iterables.count(rels2)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDefaultsAreSeparateForNodesAndRelationships() public virtual void TestDefaultsAreSeparateForNodesAndRelationships() { StopDb(); _config = new Dictionary <string, string>(); _config[GraphDatabaseSettings.node_keys_indexable.name()] = "propName"; _config[GraphDatabaseSettings.node_auto_indexing.name()] = "true"; // Now only node properties named propName should be indexed. StartDb(); NewTransaction(); Node node1 = _graphDb.createNode(); Node node2 = _graphDb.createNode(); node1.SetProperty("propName", "node1"); node2.SetProperty("propName", "node2"); node2.SetProperty("propName_", "node2"); Relationship rel = node1.CreateRelationshipTo(node2, RelationshipType.withName("DYNAMIC")); rel.SetProperty("propName", "rel1"); NewTransaction(); ReadableIndex <Node> autoIndex = _graphDb.index().NodeAutoIndexer.AutoIndex; assertEquals(node1, autoIndex.Get("propName", "node1").Single); assertEquals(node2, autoIndex.Get("propName", "node2").Single); assertFalse(_graphDb.index().RelationshipAutoIndexer.AutoIndex.get("propName", "rel1").hasNext()); }
private void PrepareDbWithDeletedRelationshipPartOfTheChain() { GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_testDirectory.databaseDir()).setConfig(GraphDatabaseSettings.record_format, RecordFormatName).setConfig("dbms.backup.enabled", "false").newGraphDatabase(); try { RelationshipType relationshipType = RelationshipType.withName("testRelationshipType"); using (Transaction tx = Db.beginTx()) { Node node1 = set(Db.createNode()); Node node2 = set(Db.createNode(), property("key", "value")); node1.CreateRelationshipTo(node2, relationshipType); node1.CreateRelationshipTo(node2, relationshipType); node1.CreateRelationshipTo(node2, relationshipType); node1.CreateRelationshipTo(node2, relationshipType); node1.CreateRelationshipTo(node2, relationshipType); node1.CreateRelationshipTo(node2, relationshipType); tx.Success(); } RecordStorageEngine recordStorageEngine = Db.DependencyResolver.resolveDependency(typeof(RecordStorageEngine)); NeoStores neoStores = recordStorageEngine.TestAccessNeoStores(); RelationshipStore relationshipStore = neoStores.RelationshipStore; RelationshipRecord relationshipRecord = new RelationshipRecord(-1); RelationshipRecord record = relationshipStore.GetRecord(4, relationshipRecord, RecordLoad.FORCE); record.InUse = false; relationshipStore.UpdateRecord(relationshipRecord); } finally { Db.shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mustDiscoverRelationshipInStoreMissingFromIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MustDiscoverRelationshipInStoreMissingFromIndex() { GraphDatabaseService db = CreateDatabase(); using (Transaction tx = Db.beginTx()) { Db.execute(format(RELATIONSHIP_CREATE, "rels", array("REL"), array("prop"))).close(); tx.Success(); } StoreIndexDescriptor indexDescriptor; long relId; using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES); indexDescriptor = GetIndexDescriptor(first(Db.schema().Indexes)); Node node = Db.createNode(); Relationship rel = node.CreateRelationshipTo(node, RelationshipType.withName("REL")); rel.SetProperty("prop", "value"); relId = rel.Id; tx.Success(); } IndexingService indexes = GetIndexingService(db); IndexProxy indexProxy = indexes.GetIndexProxy(indexDescriptor.Schema()); using (IndexUpdater updater = indexProxy.NewUpdater(IndexUpdateMode.ONLINE)) { updater.Process(IndexEntryUpdate.remove(relId, indexDescriptor, Values.stringValue("value"))); } Db.shutdown(); ConsistencyCheckService.Result result = CheckConsistency(); assertFalse(result.Successful); }
// Attempt at recreating this issue without cypher // https://github.com/neo4j/neo4j/issues/4160 //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAbortAsSoonAsPossible() public virtual void ShouldAbortAsSoonAsPossible() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Label A = org.neo4j.graphdb.Label.label("A"); Label a = Label.label("A"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Label B = org.neo4j.graphdb.Label.label("B"); Label b = Label.label("B"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Label C = org.neo4j.graphdb.Label.label("C"); Label c = Label.label("C"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Label D = org.neo4j.graphdb.Label.label("D"); Label d = Label.label("D"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Label E = org.neo4j.graphdb.Label.label("E"); Label e = Label.label("E"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Label F = org.neo4j.graphdb.Label.label("F"); Label f = Label.label("F"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.RelationshipType relType = org.neo4j.graphdb.RelationshipType.withName("TO"); RelationshipType relType = RelationshipType.withName("TO"); RecursiveSnowFlake(null, 0, 4, 5, new Label[] { a, b, c, d, e }, relType); Node a = GetNodeByLabel(a); using (ResourceIterator <Node> allE = GraphDb.findNodes(e)) { while (allE.MoveNext()) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node e = allE.Current; Node e = allE.Current; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node f = graphDb.createNode(F); Node f = GraphDb.createNode(f); f.CreateRelationshipTo(e, relType); } } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final CountingPathExpander countingPathExpander = new CountingPathExpander(org.neo4j.graphdb.PathExpanders.forTypeAndDirection(relType, org.neo4j.graphdb.Direction.OUTGOING)); CountingPathExpander countingPathExpander = new CountingPathExpander(this, PathExpanders.forTypeAndDirection(relType, Direction.OUTGOING)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final ShortestPath shortestPath = new ShortestPath(Integer.MAX_VALUE, countingPathExpander, Integer.MAX_VALUE); ShortestPath shortestPath = new ShortestPath(int.MaxValue, countingPathExpander, int.MaxValue); using (ResourceIterator <Node> allF = GraphDb.findNodes(f)) { while (allF.MoveNext()) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node f = allF.Current; Node f = allF.Current; shortestPath.FindAllPaths(a, f); } } assertEquals("There are 625 different end nodes. The algorithm should start one traversal for each such node. " + "That is 625*2 visited nodes if traversal is interrupted correctly.", 1250, countingPathExpander.NodesVisited.intValue()); }
private Relationship CreateRelationshipAssumingTxWith(string key, object value) { Node a = _db.createNode(); Node b = _db.createNode(); Relationship relationship = a.CreateRelationshipTo(b, RelationshipType.withName("FOO")); relationship.SetProperty(key, value); return(relationship); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ConsistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes() { GraphDatabaseService db = CreateDatabase(); //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: Label[] labels = IntStream.range(1, 7).mapToObj(i => Label.label("LABEL" + i)).toArray(Label[] ::new); //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: RelationshipType[] relTypes = IntStream.range(1, 5).mapToObj(i => RelationshipType.withName("REL" + i)).toArray(RelationshipType[] ::new); //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: string[] propertyKeys = IntStream.range(1, 7).mapToObj(i => "PROP" + i).toArray(string[] ::new); RandomValues randomValues = RandomValues.create(); using (Transaction tx = Db.beginTx()) { ThreadLocalRandom rng = ThreadLocalRandom.current(); int nodeCount = 1000; IList <Node> nodes = new List <Node>(nodeCount); for (int i = 0; i < nodeCount; i++) { //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: Label[] nodeLabels = rng.ints(rng.Next(labels.Length), 0, labels.Length).distinct().mapToObj(x => labels[x]).toArray(Label[] ::new); Node node = Db.createNode(nodeLabels); Stream.of(propertyKeys).forEach(p => node.setProperty(p, rng.nextBoolean() ? p : randomValues.NextValue().asObject())); nodes.Add(node); int localRelCount = Math.Min(nodes.Count, 5); rng.ints(localRelCount, 0, localRelCount).distinct().mapToObj(x => node.CreateRelationshipTo(nodes[x], relTypes[rng.Next(relTypes.Length)])).forEach(r => Stream.of(propertyKeys).forEach(p => r.setProperty(p, rng.nextBoolean() ? p : randomValues.NextValue().asObject()))); } tx.Success(); } using (Transaction tx = Db.beginTx()) { for (int i = 1; i < labels.Length; i++) { //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: Db.execute(format(NODE_CREATE, "nodes" + i, array(java.util.labels.Take(i).Select(Label::name).ToArray(string[] ::new)), array(Arrays.copyOf(propertyKeys, i)))).close(); } for (int i = 1; i < relTypes.Length; i++) { //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: Db.execute(format(RELATIONSHIP_CREATE, "rels" + i, array(java.util.relTypes.Take(i).Select(RelationshipType::name).ToArray(string[] ::new)), array(Arrays.copyOf(propertyKeys, i)))).close(); } tx.Success(); } using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES); tx.Success(); } Db.shutdown(); AssertIsConsistent(CheckConsistency()); }
protected internal override void generateInitialData(GraphDatabaseService graphDb) { using (Transaction tx = graphDb.BeginTx()) { Node node1 = set(graphDb.CreateNode()); Node node2 = set(graphDb.CreateNode(), property("key", "exampleValue")); node1.CreateRelationshipTo(node2, RelationshipType.withName("C")); tx.Success(); } }
private static Relationship MockRelationship(long id, Node start, string type, Node end, Properties properties) { Relationship relationship = MockPropertyContainer(typeof(Relationship), properties); when(relationship.Id).thenReturn(id); when(relationship.StartNode).thenReturn(start); when(relationship.EndNode).thenReturn(end); when(relationship.Type).thenReturn(RelationshipType.withName(type)); return(relationship); }
private static void CreateSomeData(GraphDatabaseService db) { using (Transaction tx = Db.beginTx()) { Node node = Db.createNode(); node.SetProperty("name", "Neo"); Db.createNode().createRelationshipTo(node, RelationshipType.withName("KNOWS")); tx.Success(); } }
protected internal override void generateInitialData(GraphDatabaseService graphDb) { // TODO: create bigger sample graph here using (Org.Neo4j.Graphdb.Transaction tx = graphDb.BeginTx()) { Node node1 = set(graphDb.CreateNode(label("Foo"))); Node node2 = set(graphDb.CreateNode(label("Foo")), property("key", "value")); node1.CreateRelationshipTo(node2, RelationshipType.withName("C")); tx.Success(); } }