Skip to content

Commit

Permalink
Throw IllegalStateException if calling get with no fetched item
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed May 8, 2017
1 parent f140f9d commit 2b428dd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
Expand Up @@ -39,6 +39,8 @@ public abstract class StoreAbstractRelationshipCursor implements Cursor<Relation
protected final RelationshipRecord relationshipRecord;
final RecordCursor<RelationshipRecord> relationshipRecordCursor;
private final LockService lockService;
protected boolean fetched;

StoreAbstractRelationshipCursor( RelationshipRecord relationshipRecord, RecordCursors cursors,
LockService lockService )
{
Expand All @@ -48,50 +50,63 @@ public abstract class StoreAbstractRelationshipCursor implements Cursor<Relation
}

@Override
public RelationshipItem get()
public final RelationshipItem get()
{
if ( !fetched )
{
throw new IllegalStateException();
}

return this;
}

@Override
public long id()
public final boolean next()
{
return fetched = fetchNext();
}

protected abstract boolean fetchNext();

@Override
public final long id()
{
return relationshipRecord.getId();
}

@Override
public int type()
public final int type()
{
return relationshipRecord.getType();
}

@Override
public long startNode()
public final long startNode()
{
return relationshipRecord.getFirstNode();
}

@Override
public long endNode()
public final long endNode()
{
return relationshipRecord.getSecondNode();
}

@Override
public long otherNode( long nodeId )
public final long otherNode( long nodeId )
{
return relationshipRecord.getFirstNode() == nodeId ?
relationshipRecord.getSecondNode() : relationshipRecord.getFirstNode();
}

@Override
public long nextPropertyId()
public final long nextPropertyId()
{
return relationshipRecord.getNextProp();
}

@Override
public Lock lock()
public final Lock lock()
{
Lock lock = lockService.acquireRelationshipLock( relationshipRecord.getId(), LockService.LockType.READ_LOCK );
if ( lockService != NO_LOCK_SERVICE )
Expand Down Expand Up @@ -121,4 +136,10 @@ public Lock lock()
}
return lock;
}

@Override
public void close()
{
fetched = false;
}
}
Expand Up @@ -52,7 +52,7 @@ public StoreIteratorRelationshipCursor init( PrimitiveLongIterator iterator )
}

@Override
public boolean next()
protected boolean fetchNext()
{
while ( iterator != null && iterator.hasNext() )
{
Expand All @@ -68,12 +68,8 @@ public boolean next()
@Override
public void close()
{
if ( iterator instanceof Resource )
{
((Resource) iterator).close();
}
super.close();
iterator = null;

instanceCache.accept( this );
}
}
Expand Up @@ -91,7 +91,7 @@ public StoreNodeRelationshipCursor init( boolean isDense,
}

@Override
public boolean next()
protected boolean fetchNext()
{
while ( relationshipId != NO_NEXT_RELATIONSHIP.intValue() )
{
Expand Down Expand Up @@ -178,6 +178,7 @@ else if ( relationshipRecord.getSecondNode() == fromNodeId )
@Override
public void close()
{
super.close();
instanceCache.accept( this );
}

Expand Down
Expand Up @@ -49,7 +49,7 @@ public StoreSingleRelationshipCursor init( long relId )
}

@Override
public boolean next()
protected boolean fetchNext()
{
if ( relationshipId != StatementConstants.NO_SUCH_RELATIONSHIP )
{
Expand All @@ -69,6 +69,7 @@ public boolean next()
@Override
public void close()
{
super.close();
instanceCache.accept( this );
}
}

0 comments on commit 2b428dd

Please sign in to comment.