Skip to content

Commit

Permalink
Simplify nodeCursorById APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Jan 4, 2017
1 parent ceef06d commit 652ebb6
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 83 deletions.
Expand Up @@ -179,15 +179,13 @@ class EagerizationAcceptanceTest
try {
val idX = input(0).asInstanceOf[Node].getId
val idY = input(1).asInstanceOf[Node].getId
val nodeCursor = statement.readOperations().nodeCursor(idX)
val nodeCursor = statement.readOperations().nodeCursorById(idX)
val result = Array.newBuilder[Array[AnyRef]]
while (nodeCursor.next()) {
val relCursor = nodeCursor.get().relationships( Direction.OUTGOING )
while (relCursor.next()) {
val item: RelationshipItem = relCursor.get()
if (item.endNode() == idY)
result += Array(new java.lang.Long(item.id()))
}
val relCursor = nodeCursor.get().relationships( Direction.OUTGOING )
while (relCursor.next()) {
val item: RelationshipItem = relCursor.get()
if (item.endNode() == idY)
result += Array(new java.lang.Long(item.id()))
}
RawIterator.of(result.result(): _*)
} finally {
Expand Down Expand Up @@ -227,14 +225,12 @@ class EagerizationAcceptanceTest
try {
val idX = input(0).asInstanceOf[Node].getId
val idY = input(1).asInstanceOf[Node].getId
val nodeCursor = statement.readOperations().nodeCursor(idX)
while (nodeCursor.next()) {
val relCursor = nodeCursor.get().relationships( Direction.OUTGOING )
while (relCursor.next()) {
val item: RelationshipItem = relCursor.get()
if (item.endNode() == idY)
counter += 1
}
val nodeCursor = statement.readOperations().nodeCursorById(idX)
val relCursor = nodeCursor.get().relationships(Direction.OUTGOING)
while (relCursor.next()) {
val item: RelationshipItem = relCursor.get()
if (item.endNode() == idY)
counter += 1
}
RawIterator.empty()
} finally {
Expand Down
Expand Up @@ -257,7 +257,7 @@ <EXCEPTION extends Exception> void relationshipVisit( long relId, RelationshipVi
//== CURSOR ACCESS OPERATIONS ===============
//===========================================

Cursor<NodeItem> nodeCursor( long nodeId );
Cursor<NodeItem> nodeCursorById( long nodeId ) throws EntityNotFoundException;

Cursor<RelationshipItem> relationshipCursor( long relId );

Expand Down
Expand Up @@ -425,13 +425,7 @@ public Cursor<NodeItem> nodeCursorById( KernelStatement statement, long nodeId )
return entityReadOperations.nodeCursorById( statement, nodeId );
}

@Override
public Cursor<NodeItem> nodeCursor( KernelStatement statement, long nodeId )
{
return entityReadOperations.nodeCursor( statement, nodeId );
}

@Override
@Override
public Cursor<RelationshipItem> relationshipCursorById( KernelStatement statement, long relId ) throws EntityNotFoundException
{
return entityReadOperations.relationshipCursorById( statement, relId );
Expand Down
Expand Up @@ -301,13 +301,6 @@ public Cursor<NodeItem> nodeCursorById( KernelStatement statement, long nodeId )
return entityReadDelegate.nodeCursorById( statement, nodeId );
}

@Override
public Cursor<NodeItem> nodeCursor( KernelStatement statement, long nodeId )
{
guard.check( statement );
return entityReadDelegate.nodeCursor( statement, nodeId );
}

@Override
public Cursor<RelationshipItem> relationshipCursorById( KernelStatement statement, long relId )
throws EntityNotFoundException
Expand Down
Expand Up @@ -130,18 +130,11 @@ private static class OperationsBasedExactMatchPredicate extends BaseExactMatchPr
@Override
Property nodeProperty( long nodeId, int propertyKeyId ) throws EntityNotFoundException
{
try ( Cursor<NodeItem> node = readOperations.nodeCursor( state, nodeId ) )
try ( Cursor<NodeItem> node = readOperations.nodeCursorById( state, nodeId ) )
{
if ( node.next() )
{
Object value = node.get().getProperty( propertyKeyId );
return value == null ? Property.noNodeProperty( nodeId, propertyKeyId ) : Property.property(
propertyKeyId, value );
}
else
{
throw new EntityNotFoundException( EntityType.NODE, nodeId );
}
Object value = node.get().getProperty( propertyKeyId );
return value == null ? Property.noNodeProperty( nodeId, propertyKeyId )
: Property.property( propertyKeyId, value );
}
}
}
Expand Down Expand Up @@ -191,9 +184,13 @@ static class NumericRangeMatchPredicate implements LongPredicate
@Override
public boolean test( long nodeId )
{
try ( Cursor<NodeItem> node = readOperations.nodeCursor( state, nodeId ) )
try ( Cursor<NodeItem> node = readOperations.nodeCursorById( state, nodeId ) )
{
return node.next() && inRange( node.get().getProperty( propertyKeyId ) );
return inRange( node.get().getProperty( propertyKeyId ) );
}
catch ( EntityNotFoundException e )
{
return false;
}
}

Expand Down
Expand Up @@ -598,10 +598,10 @@ public long nodesCountIndexed( IndexDescriptor index, long nodeId, Object value

// <DataReadCursors>
@Override
public Cursor<NodeItem> nodeCursor( long nodeId )
public Cursor<NodeItem> nodeCursorById( long nodeId ) throws EntityNotFoundException
{
statement.assertOpen();
return dataRead().nodeCursor( statement, nodeId );
return dataRead().nodeCursorById( statement, nodeId );
}

@Override
Expand Down
Expand Up @@ -142,8 +142,7 @@ public Cursor<NodeItem> nodeCursorById( KernelStatement statement, long nodeId )
return node;
}

@Override
public Cursor<NodeItem> nodeCursor( KernelStatement statement, long nodeId )
private Cursor<NodeItem> nodeCursor( KernelStatement statement, long nodeId )
{
Cursor<NodeItem> cursor = statement.getStoreStatement().acquireSingleNodeCursor( nodeId );
if ( statement.hasTxStateWithChanges() )
Expand Down
Expand Up @@ -137,8 +137,6 @@ <EXCEPTION extends Exception> void relationshipVisit( KernelStatement statement,

Cursor<NodeItem> nodeCursorById( KernelStatement statement, long nodeId ) throws EntityNotFoundException;

Cursor<NodeItem> nodeCursor( KernelStatement statement, long nodeId );

Cursor<RelationshipItem> relationshipCursorById( KernelStatement statement, long relId )
throws EntityNotFoundException;

Expand Down
Expand Up @@ -392,19 +392,17 @@ public Map<String, Object> getProperties( String... keys )

try ( Statement statement = actions.statement() )
{
try ( Cursor<NodeItem> node = statement.readOperations().nodeCursor( nodeId ) )
try ( Cursor<NodeItem> node = statement.readOperations().nodeCursorById( nodeId ) )
{
if ( !node.next() )
{
throw new NotFoundException( "Node not found",
new EntityNotFoundException( EntityType.NODE, getId() ) );
}

try ( Cursor<PropertyItem> propertyCursor = node.get().properties() )
{
return PropertyContainerProxyHelper.getProperties( statement, propertyCursor, keys );
}
}
catch ( EntityNotFoundException e )
{
throw new NotFoundException( "Node not found", e );
}
}
}

Expand All @@ -413,14 +411,8 @@ public Map<String, Object> getAllProperties()
{
try ( Statement statement = actions.statement() )
{
try ( Cursor<NodeItem> node = statement.readOperations().nodeCursor( nodeId ) )
try ( Cursor<NodeItem> node = statement.readOperations().nodeCursorById( nodeId ) )
{
if ( !node.next() )
{
throw new NotFoundException( "Node not found",
new EntityNotFoundException( EntityType.NODE, getId() ) );
}

try ( Cursor<PropertyItem> propertyCursor = node.get().properties() )
{
Map<String, Object> properties = new HashMap<>();
Expand All @@ -436,6 +428,10 @@ public Map<String, Object> getAllProperties()
return properties;
}
}
catch ( EntityNotFoundException e )
{
throw new NotFoundException( "Node not found", e );
}
}
catch ( PropertyKeyIdNotFoundKernelException e )
{
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.GraphDatabaseDependencies;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.factory.CommunityEditionModule;
import org.neo4j.kernel.impl.factory.DatabaseInfo;
Expand Down Expand Up @@ -552,7 +553,7 @@ public void shouldCreateNodeWithLotsOfLabelsAndThenRemoveMostOfThem() throws Exc
}

@Test
public void shouldAllowManyLabelsAndPropertyCursor()
public void shouldAllowManyLabelsAndPropertyCursor() throws Exception
{
int propertyCount = 10;
int labelCount = 15;
Expand Down Expand Up @@ -581,21 +582,18 @@ public void shouldAllowManyLabelsAndPropertyCursor()
ThreadToStatementContextBridge bridge = resolver.resolveDependency( ThreadToStatementContextBridge.class );
try ( Statement statement = bridge.getTopLevelTransactionBoundToThisThread( true ).acquireStatement() )
{
try ( Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursor( node.getId() ) )
try ( Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById( node.getId() ) )
{
if ( nodeCursor.next() )
try ( Cursor<PropertyItem> properties = nodeCursor.get().properties() )
{
try ( Cursor<PropertyItem> properties = nodeCursor.get().properties() )
while ( properties.next() )
{
while ( properties.next() )
seenProperties.add( properties.get().propertyKeyId() );
try ( Cursor<LabelItem> labels = nodeCursor.get().labels() )
{
seenProperties.add( properties.get().propertyKeyId() );
try ( Cursor<LabelItem> labels = nodeCursor.get().labels() )
while ( labels.next() )
{
while ( labels.next() )
{
seenLabels.add( labels.get().getAsInt() );
}
seenLabels.add( labels.get().getAsInt() );
}
}
}
Expand Down
Expand Up @@ -599,10 +599,8 @@ public void txReturnsCorrectIdWhenReadOnly() throws Exception

KernelTransaction tx = kernel.newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED );
try ( Statement statement = tx.acquireStatement();
Cursor<NodeItem> cursor = statement.readOperations().nodeCursor( 1 ) )
Cursor<NodeItem> cursor = statement.readOperations().nodeCursorById( 1 ) )
{
assertTrue( cursor.next() );
cursor.close();
}
tx.success();

Expand Down
Expand Up @@ -362,7 +362,7 @@ private void commitLabels( Integer... labels ) throws Exception

private void assertLabels( Integer... labels ) throws EntityNotFoundException
{
try ( Cursor<NodeItem> cursor = txContext.nodeCursor( state, nodeId ) )
try ( Cursor<NodeItem> cursor = txContext.nodeCursorById( state, nodeId ) )
{
if ( cursor.next() )
{
Expand All @@ -372,7 +372,7 @@ private void assertLabels( Integer... labels ) throws EntityNotFoundException

for ( int label : labels )
{
try ( Cursor<NodeItem> cursor = txContext.nodeCursor( state, nodeId ) )
try ( Cursor<NodeItem> cursor = txContext.nodeCursorById( state, nodeId ) )
{
if ( cursor.next() )
{
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.neo4j.kernel.api.KernelAPI;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.kernel.api.security.AnonymousContext;
import org.neo4j.kernel.api.security.SecurityContext;
Expand Down Expand Up @@ -195,11 +196,10 @@ private void verifyDenseRepresentation( GraphDatabaseService db, Node node, bool
try ( KernelTransaction tx = kernelAPI.newTransaction( KernelTransaction.Type.implicit, AnonymousContext.read() );
Statement statement = tx.acquireStatement() )
{
Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursor( node.getId() );
assertTrue( nodeCursor.next() );
Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById( node.getId() );
assertEquals( dense, nodeCursor.get().isDense() );
}
catch ( TransactionFailureException | IllegalArgumentException e )
catch ( TransactionFailureException | IllegalArgumentException | EntityNotFoundException e )
{
throw new RuntimeException( e );
}
Expand Down

0 comments on commit 652ebb6

Please sign in to comment.