Skip to content

Commit 28bc6e8

Browse files
committed
StatementResult now only allow Single() if at pos -1. StatementResult always allows list() which gives the remaingin records
1 parent a03a3a7 commit 28bc6e8

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

driver/src/main/java/org/neo4j/driver/internal/InternalStatementResult.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.neo4j.driver.v1.util.Function;
4343
import org.neo4j.driver.v1.util.Functions;
4444

45-
import static java.lang.String.format;
4645
import static java.util.Collections.emptyList;
4746

4847
public class InternalStatementResult implements StatementResult
@@ -222,7 +221,7 @@ else if ( done )
222221
@Override
223222
public Record single()
224223
{
225-
if( position > 0 )
224+
if( position != -1 )
226225
{
227226
throw new NoSuchRecordException(
228227
"Cannot retrieve the first record, because other operations have already used the first record. " +
@@ -274,12 +273,7 @@ public List<Record> list()
274273
@Override
275274
public <T> List<T> list( Function<Record, T> mapFunction )
276275
{
277-
if ( isEmpty() )
278-
{
279-
assertOpen();
280-
return emptyList();
281-
}
282-
else if ( position == -1 && hasNext() )
276+
if ( hasNext() )
283277
{
284278
List<T> result = new ArrayList<>();
285279
do
@@ -293,9 +287,8 @@ else if ( position == -1 && hasNext() )
293287
}
294288
else
295289
{
296-
throw new ClientException(
297-
format( "Can't retain records when cursor is not pointing at the first record (currently at position %d)", position )
298-
);
290+
assertOpen();
291+
return emptyList();
299292
}
300293
}
301294

@@ -331,12 +324,6 @@ private void assertOpen()
331324
}
332325
}
333326

334-
private boolean isEmpty()
335-
{
336-
tryFetching();
337-
return position == -1 && recordBuffer.isEmpty() && done;
338-
}
339-
340327
private void tryFetching()
341328
{
342329
while ( recordBuffer.isEmpty() && !done )

0 commit comments

Comments
 (0)