Skip to content

Commit

Permalink
migrate GraphDatabaseFacade.getRelationshipById
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Feb 2, 2018
1 parent eb798ec commit 87ac498
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
Expand Up @@ -75,6 +75,7 @@ void nodeIndexSeek( IndexReference index, NodeValueIndexCursor cursor, IndexOrde


/** /**
* Checks if a node exists in the database * Checks if a node exists in the database
*
* @param reference The reference of the node to check * @param reference The reference of the node to check
* @return <tt>true</tt> if the node exists, otherwise <tt>false</tt> * @return <tt>true</tt> if the node exists, otherwise <tt>false</tt>
*/ */
Expand All @@ -88,6 +89,14 @@ void nodeIndexSeek( IndexReference index, NodeValueIndexCursor cursor, IndexOrde
*/ */
void singleRelationship( long reference, RelationshipScanCursor cursor ); void singleRelationship( long reference, RelationshipScanCursor cursor );


/**
* Checks if a relationship exists in the database
*
* @param reference The reference of the relationship to check
* @return <tt>true</tt> if the relationship exists, otherwise <tt>false</tt>
*/
boolean relationshipExists( long reference );

void allRelationshipsScan( RelationshipScanCursor cursor ); void allRelationshipsScan( RelationshipScanCursor cursor );


Scan<RelationshipScanCursor> allRelationshipsScan(); Scan<RelationshipScanCursor> allRelationshipsScan();
Expand Down
Expand Up @@ -103,6 +103,12 @@ public void singleRelationship( long reference, RelationshipScanCursor cursor )
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override
public boolean relationshipExists( long reference )
{
throw new UnsupportedOperationException();
}

@Override @Override
public void allRelationshipsScan( RelationshipScanCursor cursor ) public void allRelationshipsScan( RelationshipScanCursor cursor )
{ {
Expand Down
Expand Up @@ -545,6 +545,12 @@ public boolean nodeExists( long id )
return nodeStore.isInUse( id ); return nodeStore.isInUse( id );
} }


@Override
public boolean relationshipExists( long id )
{
return relationshipStore.isInUse( id );
}

@Override @Override
public PrimitiveIntSet relationshipTypes( StorageStatement statement, NodeItem node ) public PrimitiveIntSet relationshipTypes( StorageStatement statement, NodeItem node )
{ {
Expand Down
Expand Up @@ -321,18 +321,17 @@ public Relationship getRelationshipById( long id )
throw new NotFoundException( format( "Relationship %d not found", id ), throw new NotFoundException( format( "Relationship %d not found", id ),
new EntityNotFoundException( EntityType.RELATIONSHIP, id ) ); new EntityNotFoundException( EntityType.RELATIONSHIP, id ) );
} }
try ( Statement statement = statementContext.get() )
KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true );
assertTransactionOpen( ktx );
try ( Statement ignore = statementContext.get() )
{ {
try if ( !ktx.dataRead().relationshipExists( id ) )
{
RelationshipProxy relationship = newRelationshipProxy( id );
statement.readOperations().relationshipVisit( id, relationship );
return relationship;
}
catch ( EntityNotFoundException e )
{ {
throw new NotFoundException( format( "Relationship %d not found", id ), e ); throw new NotFoundException( format( "Relationship %d not found", id ),
new EntityNotFoundException( EntityType.RELATIONSHIP, id ) );
} }
return newRelationshipProxy( id );
} }
} }


Expand Down
Expand Up @@ -115,6 +115,26 @@ else if ( txState.nodeIsAddedInThisTx( reference ) )
return storeReadLayer.nodeExists( reference ); return storeReadLayer.nodeExists( reference );
} }


@Override
public boolean relationshipExists( long reference )
{
ktx.assertOpen();

if ( hasTxStateWithChanges() )
{
TransactionState txState = txState();
if ( txState.relationshipIsDeletedInThisTx( reference ) )
{
return false;
}
else if ( txState.relationshipIsAddedInThisTx( reference ) )
{
return true;
}
}
return storeReadLayer.relationshipExists( reference );
}

@Override @Override
long graphPropertiesReference() long graphPropertiesReference()
{ {
Expand Down
Expand Up @@ -384,6 +384,8 @@ DoubleLongRegister indexSample( LabelSchemaDescriptor descriptor, DoubleLongRegi


boolean nodeExists( long id ); boolean nodeExists( long id );


boolean relationshipExists( long id );

PrimitiveIntSet relationshipTypes( StorageStatement statement, NodeItem node ); PrimitiveIntSet relationshipTypes( StorageStatement statement, NodeItem node );


void degrees( StorageStatement statement, NodeItem nodeItem, DegreeVisitor visitor ); void degrees( StorageStatement statement, NodeItem nodeItem, DegreeVisitor visitor );
Expand Down
Expand Up @@ -195,6 +195,12 @@ public boolean nodeExists( long id )
throw new UnsupportedOperationException( "not implemented" ); throw new UnsupportedOperationException( "not implemented" );
} }


@Override
public boolean relationshipExists( long reference )
{
throw new UnsupportedOperationException( "not implemented" );
}

private abstract static class Record<R extends AbstractBaseRecord> private abstract static class Record<R extends AbstractBaseRecord>
{ {
abstract void initialize( R record ); abstract void initialize( R record );
Expand Down

0 comments on commit 87ac498

Please sign in to comment.