Skip to content

Commit

Permalink
Simplify relationshipCursorById APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Jan 4, 2017
1 parent 652ebb6 commit 4acf3ae
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 47 deletions.
Expand Up @@ -206,8 +206,6 @@ long nodesCountIndexed( IndexDescriptor index, long nodeId, Object value )

boolean nodeExists( long nodeId );

boolean relationshipExists( long relId );

/**
* Checks if a node is labeled with a certain label or not. Returns
* {@code true} if the node is labeled with the label, otherwise {@code false.}
Expand Down Expand Up @@ -259,7 +257,7 @@ <EXCEPTION extends Exception> void relationshipVisit( long relId, RelationshipVi

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

Cursor<RelationshipItem> relationshipCursor( long relId );
Cursor<RelationshipItem> relationshipCursorById( long relId ) throws EntityNotFoundException;

//===========================================
//== SCHEMA OPERATIONS ======================
Expand Down
Expand Up @@ -425,18 +425,12 @@ public Cursor<NodeItem> nodeCursorById( KernelStatement statement, long nodeId )
return entityReadOperations.nodeCursorById( statement, nodeId );
}

@Override
@Override
public Cursor<RelationshipItem> relationshipCursorById( KernelStatement statement, long relId ) throws EntityNotFoundException
{
return entityReadOperations.relationshipCursorById( statement, relId );
}

@Override
public Cursor<RelationshipItem> relationshipCursor( KernelStatement statement, long relId )
{
return entityReadOperations.relationshipCursor( statement, relId );
}

@Override
public Cursor<RelationshipItem> relationshipCursorGetAll( KernelStatement statement )
{
Expand Down
Expand Up @@ -309,13 +309,6 @@ public Cursor<RelationshipItem> relationshipCursorById( KernelStatement statemen
return entityReadDelegate.relationshipCursorById( statement, relId );
}

@Override
public Cursor<RelationshipItem> relationshipCursor( KernelStatement statement, long relId )
{
guard.check( statement );
return entityReadDelegate.relationshipCursor( statement, relId );
}

@Override
public Cursor<RelationshipItem> relationshipCursorGetAll( KernelStatement statement )
{
Expand Down
Expand Up @@ -297,16 +297,6 @@ public boolean nodeExists( long nodeId )
return dataRead().nodeExists( statement, nodeId );
}

@Override
public boolean relationshipExists( long relId )
{
statement.assertOpen();
try ( Cursor<RelationshipItem> cursor = relationshipCursor( relId ) )
{
return cursor.next();
}
}

@Override
public boolean nodeHasLabel( long nodeId, int labelId ) throws EntityNotFoundException
{
Expand Down Expand Up @@ -605,10 +595,10 @@ public Cursor<NodeItem> nodeCursorById( long nodeId ) throws EntityNotFoundExcep
}

@Override
public Cursor<RelationshipItem> relationshipCursor( long relId )
public Cursor<RelationshipItem> relationshipCursorById( long relId ) throws EntityNotFoundException
{
statement.assertOpen();
return dataRead().relationshipCursor( statement, relId );
return dataRead().relationshipCursorById( statement, relId );
}
// </DataReadCursors>

Expand Down
Expand Up @@ -165,8 +165,7 @@ public Cursor<RelationshipItem> relationshipCursorById( KernelStatement statemen
return relationship;
}

@Override
public Cursor<RelationshipItem> relationshipCursor( KernelStatement statement, long relationshipId )
private Cursor<RelationshipItem> relationshipCursor( KernelStatement statement, long relationshipId )
{
Cursor<RelationshipItem> cursor = statement.getStoreStatement().acquireSingleRelationshipCursor(
relationshipId );
Expand Down
Expand Up @@ -140,8 +140,6 @@ <EXCEPTION extends Exception> void relationshipVisit( KernelStatement statement,
Cursor<RelationshipItem> relationshipCursorById( KernelStatement statement, long relId )
throws EntityNotFoundException;

Cursor<RelationshipItem> relationshipCursor( KernelStatement statement, long relId );

Cursor<RelationshipItem> relationshipCursorGetAll( KernelStatement statement );

Cursor<NodeItem> nodeCursorGetForLabel( KernelStatement statement, int labelId );
Expand Down
Expand Up @@ -250,19 +250,17 @@ public Map<String, Object> getProperties( String... keys )

try ( Statement statement = actions.statement() )
{
try ( Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursor( getId() ) )
try ( Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursorById( getId() ) )
{
if ( !relationship.next() )
{
throw new NotFoundException( "Relationship not found",
new EntityNotFoundException( EntityType.RELATIONSHIP, getId() ) );
}

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

Expand All @@ -271,14 +269,8 @@ public Map<String, Object> getAllProperties()
{
try ( Statement statement = actions.statement() )
{
try ( Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursor( getId() ) )
try ( Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursorById( getId() ) )
{
if ( !relationship.next() )
{
throw new NotFoundException( "Relationship not found",
new EntityNotFoundException( EntityType.RELATIONSHIP, getId() ) );
}

try ( Cursor<PropertyItem> propertyCursor = relationship.get().properties() )
{
Map<String, Object> properties = new HashMap<>();
Expand All @@ -294,6 +286,10 @@ public Map<String, Object> getAllProperties()
return properties;
}
}
catch ( EntityNotFoundException e )
{
throw new NotFoundException( "Relationship not found", e );
}
}
catch ( PropertyKeyIdNotFoundKernelException e )
{
Expand Down

0 comments on commit 4acf3ae

Please sign in to comment.