//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void addIndexRuleInATransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AddIndexRuleInATransaction() { // GIVEN SchemaWrite schemaWriteOperations = SchemaWriteInNewTransaction(); // WHEN IndexReference expectedRule = schemaWriteOperations.IndexCreate(_descriptor); Commit(); // THEN SchemaRead schemaRead = NewTransaction().schemaRead(); assertEquals(asSet(expectedRule), asSet(schemaRead.IndexesGetForLabel(_labelId))); assertEquals(expectedRule, schemaRead.Index(_descriptor.LabelId, _descriptor.PropertyIds)); Commit(); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public Iterable<org.neo4j.graphdb.schema.IndexDefinition> getIndexes(final org.neo4j.graphdb.Label label) public override IEnumerable <IndexDefinition> GetIndexes(Label label) { KernelTransaction transaction = _transactionSupplier.get(); using (Statement ignore = transaction.AcquireStatement()) { TokenRead tokenRead = transaction.TokenRead(); SchemaRead schemaRead = transaction.SchemaRead(); IList <IndexDefinition> definitions = new List <IndexDefinition>(); int labelId = tokenRead.NodeLabel(label.Name()); if (labelId == [email protected]_Fields.NO_TOKEN) { return(emptyList()); } IEnumerator <IndexReference> indexes = schemaRead.IndexesGetForLabel(labelId); AddDefinitions(definitions, tokenRead, IndexReference.sortByType(indexes)); return(definitions); } }
public virtual GraphResult BuildSchemaGraph() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String,VirtualNodeHack> nodes = new java.util.HashMap<>(); IDictionary <string, VirtualNodeHack> nodes = new Dictionary <string, VirtualNodeHack>(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String,java.util.Set<VirtualRelationshipHack>> relationships = new java.util.HashMap<>(); IDictionary <string, ISet <VirtualRelationshipHack> > relationships = new Dictionary <string, ISet <VirtualRelationshipHack> >(); using (Statement statement = _kernelTransaction.acquireStatement()) { Read dataRead = _kernelTransaction.dataRead(); TokenRead tokenRead = _kernelTransaction.tokenRead(); TokenNameLookup tokenNameLookup = new SilentTokenNameLookup(tokenRead); SchemaRead schemaRead = _kernelTransaction.schemaRead(); using (Transaction transaction = _graphDatabaseAPI.beginTx()) { // add all labelsInDatabase using (ResourceIterator <Label> labelsInDatabase = _graphDatabaseAPI.AllLabelsInUse.GetEnumerator()) { while (labelsInDatabase.MoveNext()) { Label label = labelsInDatabase.Current; int labelId = tokenRead.NodeLabel(label.Name()); IDictionary <string, object> properties = new Dictionary <string, object>(); IEnumerator <IndexReference> indexReferences = schemaRead.IndexesGetForLabel(labelId); List <string> indexes = new List <string>(); while (indexReferences.MoveNext()) { IndexReference index = indexReferences.Current; if (!index.Unique) { string[] propertyNames = PropertyNameUtils.getPropertyKeys(tokenNameLookup, index.Properties()); indexes.Add(string.join(",", propertyNames)); } } properties["indexes"] = indexes; IEnumerator <ConstraintDescriptor> nodePropertyConstraintIterator = schemaRead.ConstraintsGetForLabel(labelId); List <string> constraints = new List <string>(); while (nodePropertyConstraintIterator.MoveNext()) { ConstraintDescriptor constraint = nodePropertyConstraintIterator.Current; constraints.Add(constraint.PrettyPrint(tokenNameLookup)); } properties["constraints"] = constraints; GetOrCreateLabel(label.Name(), properties, nodes); } } //add all relationships using (ResourceIterator <RelationshipType> relationshipTypeIterator = _graphDatabaseAPI.AllRelationshipTypesInUse.GetEnumerator()) { while (relationshipTypeIterator.MoveNext()) { RelationshipType relationshipType = relationshipTypeIterator.Current; string relationshipTypeGetName = relationshipType.Name(); int relId = tokenRead.RelationshipType(relationshipTypeGetName); using (ResourceIterator <Label> labelsInUse = _graphDatabaseAPI.AllLabelsInUse.GetEnumerator()) { IList <VirtualNodeHack> startNodes = new LinkedList <VirtualNodeHack>(); IList <VirtualNodeHack> endNodes = new LinkedList <VirtualNodeHack>(); while (labelsInUse.MoveNext()) { Label labelToken = labelsInUse.Current; string labelName = labelToken.Name(); IDictionary <string, object> properties = new Dictionary <string, object>(); VirtualNodeHack node = GetOrCreateLabel(labelName, properties, nodes); int labelId = tokenRead.NodeLabel(labelName); if (dataRead.CountsForRelationship(labelId, relId, [email protected]_Fields.ANY_LABEL) > 0) { startNodes.Add(node); } if (dataRead.CountsForRelationship([email protected]_Fields.ANY_LABEL, relId, labelId) > 0) { endNodes.Add(node); } } foreach (VirtualNodeHack startNode in startNodes) { foreach (VirtualNodeHack endNode in endNodes) { AddRelationship(startNode, endNode, relationshipTypeGetName, relationships); } } } } } transaction.Success(); return(GetGraphResult(nodes, relationships)); } } }