public override NodeValueIndexCursor AllocateNodeValueIndexCursor() { NodeValueIndexCursor n = _cursors.allocateNodeValueIndexCursor(); _allCursors.Add(n); return(n); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleCompositeSizesCloseToTheLimit() throws org.neo4j.internal.kernel.api.exceptions.KernelException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleCompositeSizesCloseToTheLimit() { // given CreateIndex(KEY, KEY2); // when a string longer than native string limit, but within lucene limit int length = 20_000; string string1 = Random.nextAlphaNumericString(length, length); string string2 = Random.nextAlphaNumericString(length, length); Node node; using (Transaction tx = Db.beginTx()) { node = Db.createNode(LABEL); node.SetProperty(KEY, string1); node.SetProperty(KEY2, string2); tx.Success(); } using (Transaction tx = Db.beginTx()) { KernelTransaction ktx = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true); int labelId = ktx.TokenRead().nodeLabel(LABEL.Name()); int propertyKeyId1 = ktx.TokenRead().propertyKey(KEY); int propertyKeyId2 = ktx.TokenRead().propertyKey(KEY2); using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor()) { ktx.DataRead().nodeIndexSeek(TestIndexDescriptorFactory.forLabel(labelId, propertyKeyId1, propertyKeyId2), cursor, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId1, string1), IndexQuery.exact(propertyKeyId2, string2)); assertTrue(cursor.Next()); assertEquals(node.Id, cursor.NodeReference()); assertFalse(cursor.Next()); } tx.Success(); } }
/// <summary> /// Perform an index scan and assert that the correct nodes and values were found. /// /// Since this method modifies TX state for the test it is not safe to call this method more than once in the same transaction. /// </summary> /// <param name="expected"> the expected nodes and values </param> /// <param name="tx"> the transaction </param> /// <param name="index"> the index </param> /// <param name="needsValues"> if the index is expected to provide values </param> /// <param name="anotherValueFoundByQuery"> a values that would be found by, if a node with that value existed. This method /// will create a node with that value, after initializing the cursor and assert that the new node is not found. </param> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertNodeAndValueForScan(java.util.Set<org.neo4j.helpers.collection.Pair<long,org.neo4j.values.storable.Value>> expected, Transaction tx, IndexReference index, boolean needsValues, Object anotherValueFoundByQuery) throws Exception private void AssertNodeAndValueForScan(ISet <Pair <long, Value> > expected, Transaction tx, IndexReference index, bool needsValues, object anotherValueFoundByQuery) { using (NodeValueIndexCursor nodes = tx.Cursors().allocateNodeValueIndexCursor()) { tx.DataRead().nodeIndexScan(index, nodes, IndexOrder.None, needsValues); AssertNodeAndValue(expected, tx, needsValues, anotherValueFoundByQuery, nodes); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void nodeIndexDistinctValues(org.neo4j.internal.kernel.api.IndexReference index, org.neo4j.internal.kernel.api.NodeValueIndexCursor cursor, boolean needsValues) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException public override void NodeIndexDistinctValues(IndexReference index, NodeValueIndexCursor cursor, bool needsValues) { Ktx.assertOpen(); DefaultNodeValueIndexCursor cursorImpl = ( DefaultNodeValueIndexCursor )cursor; IndexReader reader = IndexReader(index, true); cursorImpl.Read = this; using (CursorPropertyAccessor accessor = new CursorPropertyAccessor(_cursors.allocateNodeCursor(), _cursors.allocatePropertyCursor(), this)) { reader.DistinctValues(cursorImpl, accessor, needsValues); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertIndexedNodesMatchesStoreNodes() throws Exception private void AssertIndexedNodesMatchesStoreNodes() { int nodesInStore = 0; Label label = Label.label(PERSON_LABEL); using (Transaction tx = _db.beginTx()) { KernelTransaction ktx = (( GraphDatabaseAPI )_db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true); IList <string> mismatches = new List <string>(); int labelId = ktx.TokenRead().nodeLabel(PERSON_LABEL); int propertyKeyId = ktx.TokenRead().propertyKey(NAME_PROPERTY); IndexReference index = ktx.SchemaRead().index(labelId, propertyKeyId); using (NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor()) { // Node --> Index foreach (Node node in filter(n => n.hasLabel(label) && n.hasProperty(NAME_PROPERTY), _db.AllNodes)) { nodesInStore++; string name = ( string )node.GetProperty(NAME_PROPERTY); ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, name)); bool found = false; while (cursor.Next()) { long indexedNode = cursor.NodeReference(); if (indexedNode == node.Id) { if (found) { mismatches.Add("Index has multiple entries for " + name + " and " + indexedNode); } found = true; } } if (!found) { mismatches.Add("Index is missing entry for " + name + " " + node); } } if (mismatches.Count > 0) { fail(join(mismatches.ToArray(), format("%n"))); } // Node count == indexed node count ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exists(propertyKeyId)); int nodesInIndex = 0; while (cursor.Next()) { nodesInIndex++; } assertEquals(nodesInStore, nodesInIndex); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertIndexData(org.neo4j.internal.kernel.api.Transaction transaction, int[] propertyKeyIds, org.neo4j.values.storable.TextValue value, long node, org.neo4j.internal.kernel.api.IndexReference index) throws org.neo4j.internal.kernel.api.exceptions.KernelException private void AssertIndexData(Transaction transaction, int[] propertyKeyIds, TextValue value, long node, IndexReference index) { using (NodeValueIndexCursor indexCursor = transaction.Cursors().allocateNodeValueIndexCursor()) { IndexQuery[] query = new IndexQuery[propertyKeyIds.Length]; for (int i = 0; i < propertyKeyIds.Length; i++) { query[i] = IndexQuery.exact(propertyKeyIds[i], value); } transaction.DataRead().nodeIndexSeek(index, indexCursor, IndexOrder.NONE, false, query); assertTrue(indexCursor.Next()); assertEquals(node, indexCursor.NodeReference()); assertFalse(indexCursor.Next()); } }
/// <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); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProvideResultInOrderIfCapable() throws org.neo4j.internal.kernel.api.exceptions.KernelException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProvideResultInOrderIfCapable() { int label = Token.nodeLabel("Node"); int prop = Token.propertyKey("prop"); RandomValues randomValues = RandomRule.randomValues(); IndexReference index = SchemaRead.index(label, prop); for (int i = 0; i < _nIterations; i++) { ValueType type = randomValues.Among(_targetedTypes); IndexOrder[] order = index.OrderCapability(type.valueGroup.category()); foreach (IndexOrder indexOrder in order) { if (indexOrder == IndexOrder.NONE) { continue; } NodeValueTuple from = new NodeValueTuple(this, long.MinValue, randomValues.NextValueOfType(type)); NodeValueTuple to = new NodeValueTuple(this, long.MaxValue, randomValues.NextValueOfType(type)); if (COMPARATOR.compare(from, to) > 0) { NodeValueTuple tmp = from; from = to; to = tmp; } bool fromInclusive = randomValues.NextBoolean(); bool toInclusive = randomValues.NextBoolean(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.internal.kernel.api.IndexQuery.RangePredicate<?> range = org.neo4j.internal.kernel.api.IndexQuery.range(prop, from.getOnlyValue(), fromInclusive, to.getOnlyValue(), toInclusive); IndexQuery.RangePredicate <object> range = IndexQuery.range(prop, from.OnlyValue, fromInclusive, to.OnlyValue, toInclusive); using (NodeValueIndexCursor node = Cursors.allocateNodeValueIndexCursor()) { Read.nodeIndexSeek(index, node, indexOrder, false, range); IList <long> expectedIdsInOrder = expectedIdsInOrder(from, fromInclusive, to, toInclusive, indexOrder); IList <long> actualIdsInOrder = new List <long>(); while (node.Next()) { actualIdsInOrder.Add(node.NodeReference()); } assertEquals(expectedIdsInOrder, actualIdsInOrder, "actual node ids not in same order as expected"); } } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public final void nodeIndexSeek(org.neo4j.internal.kernel.api.IndexReference index, org.neo4j.internal.kernel.api.NodeValueIndexCursor cursor, org.neo4j.internal.kernel.api.IndexOrder indexOrder, boolean needsValues, org.neo4j.internal.kernel.api.IndexQuery... query) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException public override void NodeIndexSeek(IndexReference index, NodeValueIndexCursor cursor, IndexOrder indexOrder, bool needsValues, params IndexQuery[] query) { Ktx.assertOpen(); if (HasForbiddenProperties(index)) { cursor.Close(); return; } DefaultNodeValueIndexCursor cursorImpl = ( DefaultNodeValueIndexCursor )cursor; IndexReader reader = IndexReader(index, false); cursorImpl.Read = this; Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient withFullPrecision = InjectFullValuePrecision(cursorImpl, query, reader); reader.Query(withFullPrecision, indexOrder, needsValues, query); }
//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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void concurrentIndexPopulationAndInsertsShouldNotProduceDuplicates() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ConcurrentIndexPopulationAndInsertsShouldNotProduceDuplicates() { // Given Config config = Config.defaults(); GraphDatabaseService db = NewEmbeddedGraphDatabaseWithSlowJobScheduler(config); try { // When using (Transaction tx = Db.beginTx()) { Db.schema().indexFor(label(LABEL)).on(KEY).create(); tx.Success(); } Node node; using (Transaction tx = Db.beginTx()) { node = Db.createNode(label(LABEL)); node.SetProperty(KEY, VALUE); tx.Success(); } using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(1, MINUTES); tx.Success(); } // Then using (Transaction tx = Db.beginTx()) { KernelTransaction ktx = (( GraphDatabaseAPI )db).DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true); IndexReference index = ktx.SchemaRead().index(ktx.TokenRead().nodeLabel(LABEL), ktx.TokenRead().propertyKey(KEY)); NodeValueIndexCursor cursor = ktx.Cursors().allocateNodeValueIndexCursor(); ktx.DataRead().nodeIndexSeek(index, cursor, IndexOrder.NONE, false, IndexQuery.exact(1, VALUE)); assertTrue(cursor.Next()); assertEquals(node.Id, cursor.NodeReference()); assertFalse(cursor.Next()); tx.Success(); } } finally { Db.shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRangeScanInOrder() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRangeScanInOrder() { IList <Pair <long, Value> > expected = new List <Pair <long, Value> >(); using (Transaction tx = beginTransaction()) { expected.Add(NodeWithProp(tx, "hello")); NodeWithProp(tx, "bellow"); expected.Add(NodeWithProp(tx, "schmello")); expected.Add(NodeWithProp(tx, "low")); expected.Add(NodeWithProp(tx, "trello")); NodeWithProp(tx, "yellow"); expected.Add(NodeWithProp(tx, "low")); NodeWithProp(tx, "below"); tx.Success(); } CreateIndex(); // when using (Transaction tx = beginTransaction()) { int label = tx.TokenRead().nodeLabel("Node"); int prop = tx.TokenRead().propertyKey("prop"); IndexReference index = tx.SchemaRead().index(label, prop); using (NodeValueIndexCursor cursor = tx.Cursors().allocateNodeValueIndexCursor()) { NodeWithProp(tx, "allow"); expected.Add(NodeWithProp(tx, "now")); expected.Add(NodeWithProp(tx, "jello")); NodeWithProp(tx, "willow"); IndexQuery query = IndexQuery.Range(prop, "hello", true, "trello", true); tx.DataRead().nodeIndexSeek(index, cursor, IndexOrder, true, query); AssertResultsInOrder(expected, cursor); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPrefixScanInOrder() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPrefixScanInOrder() { IList <Pair <long, Value> > expected = new List <Pair <long, Value> >(); using (Transaction tx = beginTransaction()) { expected.Add(NodeWithProp(tx, "bee hive")); NodeWithProp(tx, "a"); expected.Add(NodeWithProp(tx, "become")); expected.Add(NodeWithProp(tx, "be")); expected.Add(NodeWithProp(tx, "bachelor")); NodeWithProp(tx, "street smart"); expected.Add(NodeWithProp(tx, "builder")); NodeWithProp(tx, "ceasar"); tx.Success(); } CreateIndex(); // when using (Transaction tx = beginTransaction()) { int label = tx.TokenRead().nodeLabel("Node"); int prop = tx.TokenRead().propertyKey("prop"); IndexReference index = tx.SchemaRead().index(label, prop); using (NodeValueIndexCursor cursor = tx.Cursors().allocateNodeValueIndexCursor()) { NodeWithProp(tx, "allow"); expected.Add(NodeWithProp(tx, "bastard")); expected.Add(NodeWithProp(tx, "bully")); NodeWithProp(tx, "willow"); IndexQuery query = IndexQuery.StringPrefix(prop, stringValue("b")); tx.DataRead().nodeIndexSeek(index, cursor, IndexOrder, true, query); AssertResultsInOrder(expected, cursor); } } }
private void AssertResultsInOrder(IList <Pair <long, Value> > expected, NodeValueIndexCursor cursor) { IComparer <Pair <long, Value> > comparator = IndexOrder == IndexOrder.Ascending ? (a, b) => Values.COMPARATOR.Compare(a.other(), b.other()) : (a, b) => Values.COMPARATOR.Compare(b.other(), a.other()); expected.sort(comparator); IEnumerator <Pair <long, Value> > expectedRows = expected.GetEnumerator(); while (cursor.Next() && expectedRows.MoveNext()) { Pair <long, Value> expectedRow = expectedRows.Current; assertThat(cursor.NodeReference(), equalTo(expectedRow.First())); for (int i = 0; i < cursor.NumberOfProperties(); i++) { Value value = cursor.PropertyValue(i); assertThat(value, equalTo(expectedRow.Other())); } } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(expectedRows.hasNext()); assertFalse(cursor.Next()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGetAllSinglePropertyValues() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldGetAllSinglePropertyValues() { int label = Token.nodeLabel("Node"); int prop = Token.propertyKey("prop"); IndexReference index = SchemaRead.index(label, prop); using (NodeValueIndexCursor node = Cursors.allocateNodeValueIndexCursor()) { Read.nodeIndexScan(index, node, IndexOrder.NONE, true); IList <Value> values = new List <Value>(); while (node.Next()) { values.Add(node.PropertyValue(0)); } values.sort(Values.COMPARATOR); for (int i = 0; i < _singlePropValues.Count; i++) { assertEquals(_singlePropValues[i], values[i]); } } }
public override void NodeIndexScan(IndexReference index, NodeValueIndexCursor cursor, IndexOrder indexOrder, bool needsValues) { throw new System.NotSupportedException(); }
public override void NodeIndexDistinctValues(IndexReference index, NodeValueIndexCursor cursor, bool needsValues) { throw new System.NotSupportedException(); }
public override void NodeIndexSeek(IndexReference index, NodeValueIndexCursor cursor, IndexOrder indexOrder, bool needsValues, params IndexQuery[] query) { throw new System.NotSupportedException(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertNodeAndValue(java.util.Set<org.neo4j.helpers.collection.Pair<long,org.neo4j.values.storable.Value>> expected, Transaction tx, boolean needsValues, Object anotherValueFoundByQuery, NodeValueIndexCursor nodes) throws Exception private void AssertNodeAndValue(ISet <Pair <long, Value> > expected, Transaction tx, bool needsValues, object anotherValueFoundByQuery, NodeValueIndexCursor nodes) { // Modify tx state with changes that should not be reflected in the cursor, since it was already initialized in the above statement foreach (Pair <long, Value> pair in expected) { tx.DataWrite().nodeDelete(pair.First()); } NodeWithPropId(tx, anotherValueFoundByQuery); if (needsValues) { ISet <Pair <long, Value> > found = new HashSet <Pair <long, Value> >(); while (nodes.Next()) { found.Add(Pair.of(nodes.NodeReference(), nodes.PropertyValue(0))); } assertThat(found, equalTo(expected)); } else { ISet <long> foundIds = new HashSet <long>(); while (nodes.Next()) { foundIds.Add(nodes.NodeReference()); } //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: Most Java stream collectors are not converted by Java to C# Converter: ImmutableSet <long> expectedIds = expected.Select(Pair::first).collect(Collectors2.toImmutableSet()); assertThat(foundIds, equalTo(expectedIds)); } }
public abstract void NodeIndexSeek(IndexReference index, NodeValueIndexCursor cursor, IndexOrder indexOrder, bool needsValues, params IndexQuery[] query);