Skip to content

Commit

Permalink
refactor and javadoc och IndexProgressor and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Nov 9, 2017
1 parent b8a0b8f commit c2f12be
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 124 deletions.
Expand Up @@ -20,24 +20,25 @@
package org.neo4j.kernel.impl.newapi;

import org.neo4j.kernel.api.ExplicitIndexHits;
import org.neo4j.storageengine.api.schema.IndexProgressor;

class ExplicitIndexProgressor implements IndexCursorProgressor
class ExplicitIndexProgressor implements IndexProgressor
{
private final ExplicitCursor cursor;
private final ExplicitClient client;
private final ExplicitIndexHits hits;

ExplicitIndexProgressor( ExplicitCursor cursor, ExplicitIndexHits hits )
ExplicitIndexProgressor( ExplicitIndexHits hits, ExplicitClient client )
{
this.cursor = cursor;
this.hits = hits;
this.client = client;
}

@Override
public boolean next()
{
while ( hits.hasNext() )
{
if ( cursor.entity( hits.next(), hits.currentScore() ) )
if ( client.acceptEntity( hits.next(), hits.currentScore() ) )
{
return true;
}
Expand Down
Expand Up @@ -19,11 +19,13 @@
*/
package org.neo4j.kernel.impl.newapi;

import org.neo4j.storageengine.api.schema.IndexProgressor;

abstract class IndexCursor
{
private IndexCursorProgressor progressor;
private IndexProgressor progressor;

final void initialize( IndexCursorProgressor progressor )
final void initialize( IndexProgressor progressor )
{
this.progressor = progressor;
}
Expand Down
Expand Up @@ -23,19 +23,20 @@
import java.util.Comparator;

import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.values.storable.Value;

class IndexCursorFilter implements IndexCursorProgressor.NodeValueCursor
class IndexCursorFilter implements IndexProgressor.NodeValueClient
{
private static final Comparator<IndexQuery> ASCENDING_BY_KEY = Comparator.comparingInt( IndexQuery::propertyKeyId );
private final IndexCursorProgressor.NodeValueCursor target;
private final IndexProgressor.NodeValueClient target;
private final NodeCursor node;
private final PropertyCursor property;
private final IndexQuery[] filters;
private int[] keys;

IndexCursorFilter(
IndexCursorProgressor.NodeValueCursor target,
IndexProgressor.NodeValueClient target,
NodeCursor node, PropertyCursor property, IndexQuery... filters )
{
this.target = target;
Expand All @@ -46,10 +47,10 @@ class IndexCursorFilter implements IndexCursorProgressor.NodeValueCursor
}

@Override
public void initialize( IndexCursorProgressor progressor, int[] keys )
public void initialize( IndexProgressor progressor, int[] propertyIds )
{
this.keys = keys;
target.initialize( progressor, keys );
this.keys = propertyIds;
target.initialize( progressor, propertyIds );
}

@Override
Expand All @@ -61,7 +62,7 @@ public void done()
}

@Override
public boolean node( long reference, Value[] values )
public boolean acceptNode( long reference, Value[] values )
{
if ( keys != null && values != null )
{
Expand Down Expand Up @@ -102,7 +103,7 @@ private boolean filterByIndexValues( long reference, Value[] values )
assert false : "Cannot satisfy filter " + filter + " - no corresponding key!";
return false;
}
return target.node( reference, values );
return target.acceptNode( reference, values );
}

private boolean filterByCursors( long reference, Value[] values )
Expand Down Expand Up @@ -132,6 +133,6 @@ else if ( property.propertyKey() < filter.propertyKeyId() )
{
return false; // not all filters were matched
}
return target.node( reference, values );
return target.acceptNode( reference, values );
}
}

This file was deleted.

Expand Up @@ -20,11 +20,13 @@
package org.neo4j.kernel.impl.newapi;

import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.storageengine.api.schema.IndexProgressor.ExplicitClient;

import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID;

class NodeExplicitIndexCursor extends IndexCursor
implements org.neo4j.internal.kernel.api.NodeExplicitIndexCursor, IndexCursorProgressor.ExplicitCursor
implements org.neo4j.internal.kernel.api.NodeExplicitIndexCursor, ExplicitClient
{
private final Read read;
private int expectedSize;
Expand All @@ -37,14 +39,14 @@ class NodeExplicitIndexCursor extends IndexCursor
}

@Override
public void initialize( IndexCursorProgressor progressor, int expectedSize )
public void initialize( IndexProgressor progressor, int expectedSize )
{
super.initialize( progressor );
this.expectedSize = expectedSize;
}

@Override
public boolean entity( long reference, float score )
public boolean acceptEntity( long reference, float score )
{
this.node = reference;
this.score = score;
Expand Down
Expand Up @@ -21,11 +21,13 @@

import org.neo4j.internal.kernel.api.LabelSet;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.storageengine.api.schema.IndexProgressor.NodeLabelClient;

import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID;

class NodeLabelIndexCursor extends IndexCursor
implements org.neo4j.internal.kernel.api.NodeLabelIndexCursor, IndexCursorProgressor.NodeLabelCursor
implements org.neo4j.internal.kernel.api.NodeLabelIndexCursor, NodeLabelClient
{
private final Read read;
private long node;
Expand All @@ -37,13 +39,13 @@ class NodeLabelIndexCursor extends IndexCursor
}

@Override
public void initialize( IndexCursorProgressor progressor, boolean providesLabels )
public void initialize( IndexProgressor progressor, boolean providesLabels )
{
super.initialize( progressor );
}

@Override
public boolean node( long reference, LabelSet labels )
public boolean acceptNode( long reference, LabelSet labels )
{
this.node = reference;
this.labels = labels;
Expand Down
Expand Up @@ -21,24 +21,25 @@

import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.graphdb.Resource;
import org.neo4j.storageengine.api.schema.IndexProgressor;

class NodeLabelIndexProgressor implements IndexCursorProgressor
class NodeLabelIndexProgressor implements IndexProgressor
{
private final PrimitiveLongIterator iterator;
private final NodeLabelCursor target;
private final NodeLabelClient client;

NodeLabelIndexProgressor( PrimitiveLongIterator iterator, NodeLabelCursor target )
NodeLabelIndexProgressor( PrimitiveLongIterator iterator, NodeLabelClient client )
{
this.iterator = iterator;
this.target = target;
this.client = client;
}

@Override
public boolean next()
{
while ( iterator.hasNext() )
{
if ( target.node( iterator.next(), null ) )
if ( client.acceptNode( iterator.next(), null ) )
{
return true;
}
Expand Down
Expand Up @@ -20,12 +20,14 @@
package org.neo4j.kernel.impl.newapi;

import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.storageengine.api.schema.IndexProgressor.NodeValueClient;
import org.neo4j.values.storable.Value;

import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID;

class NodeValueIndexCursor extends IndexCursor
implements org.neo4j.internal.kernel.api.NodeValueIndexCursor, IndexCursorProgressor.NodeValueCursor
implements org.neo4j.internal.kernel.api.NodeValueIndexCursor, NodeValueClient
{
private final Read read;
private long node;
Expand All @@ -38,14 +40,14 @@ class NodeValueIndexCursor extends IndexCursor
}

@Override
public void initialize( IndexCursorProgressor progressor, int[] keys )
public void initialize( IndexProgressor progressor, int[] propertyIds )
{
super.initialize( progressor );
this.keys = keys;
this.keys = propertyIds;
}

@Override
public boolean node( long reference, Value[] values )
public boolean acceptNode( long reference, Value[] values )
{
this.node = reference;
this.values = values;
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.storageengine.api.schema.LabelScanReader;
import org.neo4j.values.storable.ArrayValue;
Expand All @@ -59,7 +60,7 @@ public final void nodeIndexSeek(
org.neo4j.internal.kernel.api.NodeValueIndexCursor cursor,
IndexQuery... query ) throws KernelException
{
IndexCursorProgressor.NodeValueCursor target = (NodeValueIndexCursor) cursor;
IndexProgressor.NodeValueClient target = (NodeValueIndexCursor) cursor;
IndexReader reader = indexReader( (IndexReference) index );
if ( !reader.hasFullNumberPrecision( query ) )
{
Expand Down Expand Up @@ -127,9 +128,9 @@ public void nodeLabelIntersectionScan( org.neo4j.internal.kernel.api.NodeLabelIn
labelScan( (NodeLabelIndexCursor) cursor, labelScanReader().nodesWithAllLabels( labels ) );
}

private void labelScan( IndexCursorProgressor.NodeLabelCursor target, PrimitiveLongIterator iterator )
private void labelScan( IndexProgressor.NodeLabelClient client, PrimitiveLongIterator iterator )
{
target.initialize( new NodeLabelIndexProgressor( iterator, target ), false );
client.initialize( new NodeLabelIndexProgressor( iterator, client ), false );
}

@Override
Expand Down Expand Up @@ -339,9 +340,9 @@ public void relationshipExplicitIndexQuery(
key, query instanceof Value ? ((Value) query).asObject() : query, source, target ) );
}

private static void explicitIndex( IndexCursorProgressor.ExplicitCursor cursor, ExplicitIndexHits hits )
private static void explicitIndex( IndexProgressor.ExplicitClient client, ExplicitIndexHits hits )
{
cursor.initialize( new ExplicitIndexProgressor( cursor, hits ), hits.size() );
client.initialize( new ExplicitIndexProgressor( hits, client ), hits.size() );
}

@Override
Expand Down
Expand Up @@ -21,11 +21,13 @@

import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.RelationshipScanCursor;
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.storageengine.api.schema.IndexProgressor.ExplicitClient;

import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID;

class RelationshipExplicitIndexCursor extends IndexCursor
implements org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor, IndexCursorProgressor.ExplicitCursor
implements org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor, ExplicitClient
{
private final Read read;
private int expectedSize;
Expand All @@ -38,14 +40,14 @@ class RelationshipExplicitIndexCursor extends IndexCursor
}

@Override
public void initialize( IndexCursorProgressor progressor, int expectedSize )
public void initialize( IndexProgressor progressor, int expectedSize )
{
super.initialize( progressor );
this.expectedSize = expectedSize;
}

@Override
public boolean entity( long reference, float score )
public boolean acceptEntity( long reference, float score )
{
this.relationship = reference;
this.score = score;
Expand Down

0 comments on commit c2f12be

Please sign in to comment.