/// <summary> /// Performs an index seek. /// </summary> /// <param name="read"> The Read instance to use for seeking </param> /// <param name="cursors"> Used for cursor allocation </param> /// <param name="index"> A reference to an index </param> /// <param name="value"> The value to seek for </param> /// <returns> A cursor positioned at the data found in index. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static org.neo4j.internal.kernel.api.NodeValueIndexCursor indexSeek(org.neo4j.internal.kernel.api.Read read, org.neo4j.internal.kernel.api.CursorFactory cursors, org.neo4j.internal.kernel.api.IndexReference index, Object value) throws org.neo4j.internal.kernel.api.exceptions.KernelException public static NodeValueIndexCursor IndexSeek(Read read, CursorFactory cursors, IndexReference index, object value) { Debug.Assert(index.Properties().Length == 1); if (value == Values.NO_VALUE || value == null) { return([email protected]_Fields.Empty); } else { NodeValueIndexCursor cursor = cursors.AllocateNodeValueIndexCursor(); IndexQuery.ExactPredicate query = exact(index.Properties()[0], makeValueNeoSafe(value)); read.NodeIndexSeek(index, cursor, IndexOrder.NONE, false, query); return(cursor); } }
private void AssertCorrectIndex(int labelId, int[] propertyKeyIds, bool expectedUnique, IndexReference index) { assertEquals("provider key", "lucene+native", index.ProviderKey()); assertEquals("provider version", "1.0", index.ProviderVersion()); assertEquals(expectedUnique, index.Unique); assertEquals("label id", labelId, index.Schema().EntityTokenIds[0]); for (int i = 0; i < propertyKeyIds.Length; i++) { assertEquals("property key id", propertyKeyIds[i], index.Properties()[i]); } }
private bool HasForbiddenProperties(IndexReference index) { AccessMode mode = Ktx.securityContext().mode(); foreach (int prop in index.Properties()) { if (!mode.AllowsPropertyReads(prop)) { return(true); } } return(false); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void assertPredicatesMatchSchema(org.neo4j.internal.kernel.api.IndexReference index, org.neo4j.internal.kernel.api.IndexQuery.ExactPredicate[] predicates) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException private static void AssertPredicatesMatchSchema(IndexReference index, IndexQuery.ExactPredicate[] predicates) { int[] propertyIds = index.Properties(); if (propertyIds.Length != predicates.Length) { throw new IndexNotApplicableKernelException(format("The index specifies %d properties, but only %d lookup predicates were given.", propertyIds.Length, predicates.Length)); } for (int i = 0; i < predicates.Length; i++) { if (predicates[i].PropertyKeyId() != propertyIds[i]) { throw new IndexNotApplicableKernelException(format("The index has the property id %d in position %d, but the lookup property id was %d.", propertyIds[i], i, predicates[i].PropertyKeyId())); } } }
// nodeGetUniqueWithLabelAndProperty(statement, :Person, foo=val) // // Given we have a unique constraint on :Person(foo) // (If not, throw) // // If there is a node n with n:Person and n.foo == val, return it // If there is no such node, return ? // // Ensure that if that method is called again with the same argument from some other transaction, // that transaction blocks until this transaction has finished // // [X] must return node from the unique index with the given property // [X] must return NO_SUCH_NODE if it is not in the index for the given property // // must block other transactions that try to call it with the same arguments //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFindMatchingNode() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFindMatchingNode() { // given IndexReference index = CreateUniquenessConstraint(_labelId, _propertyId1); Value value = Values.of("value"); long nodeId = CreateNodeWithValue(value); // when looking for it Read read = NewTransaction().dataRead(); int propertyId = index.Properties()[0]; long foundId = read.LockingNodeUniqueIndexSeek(index, exact(propertyId, value)); Commit(); // then assertEquals("Created node was not found", nodeId, foundId); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public final void nodeIndexScan(org.neo4j.internal.kernel.api.IndexReference index, org.neo4j.internal.kernel.api.NodeValueIndexCursor cursor, org.neo4j.internal.kernel.api.IndexOrder indexOrder, boolean needsValues) throws org.neo4j.internal.kernel.api.exceptions.KernelException public override void NodeIndexScan(IndexReference index, NodeValueIndexCursor cursor, IndexOrder indexOrder, bool needsValues) { Ktx.assertOpen(); if (HasForbiddenProperties(index)) { cursor.Close(); return; } // for a scan, we simply query for existence of the first property, which covers all entries in an index int firstProperty = index.Properties()[0]; DefaultNodeValueIndexCursor cursorImpl = ( DefaultNodeValueIndexCursor )cursor; cursorImpl.Read = this; IndexReader(index, false).query(cursorImpl, indexOrder, needsValues, IndexQuery.exists(firstProperty)); }
//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 org.neo4j.graphdb.schema.IndexDefinition descriptorToDefinition(final org.neo4j.internal.kernel.api.TokenRead tokenRead, org.neo4j.internal.kernel.api.IndexReference index) private IndexDefinition DescriptorToDefinition(TokenRead tokenRead, IndexReference index) { try { SchemaDescriptor schema = index.Schema(); int[] entityTokenIds = Schema.EntityTokenIds; bool constraintIndex = index.Unique; string[] propertyNames = PropertyNameUtils.GetPropertyKeys(tokenRead, index.Properties()); switch (Schema.entityType()) { case NODE: Label[] labels = new Label[entityTokenIds.Length]; for (int i = 0; i < labels.Length; i++) { labels[i] = label(tokenRead.NodeLabelName(entityTokenIds[i])); } return(new IndexDefinitionImpl(_actions, index, labels, propertyNames, constraintIndex)); case RELATIONSHIP: RelationshipType[] relTypes = new RelationshipType[entityTokenIds.Length]; for (int i = 0; i < relTypes.Length; i++) { relTypes[i] = withName(tokenRead.RelationshipTypeName(entityTokenIds[i])); } return(new IndexDefinitionImpl(_actions, index, relTypes, propertyNames, constraintIndex)); default: throw new System.ArgumentException("Cannot create IndexDefinition for " + Schema.entityType() + " entity-typed schema."); } } catch (KernelException e) { throw new Exception(e); } }
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)); } } }