Skip to content

Commit d744902

Browse files
author
Zhen Li
committed
Improved javadoc and error classes
1 parent bc1baba commit d744902

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

driver/src/main/java/org/neo4j/driver/exceptions/ResultConsumedException.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
*/
2828
public class ResultConsumedException extends ClientException
2929
{
30-
public ResultConsumedException()
30+
public ResultConsumedException( String message )
3131
{
32-
super( "Cannot access records on this result any more as the result has already been consumed " +
33-
"or the statement runner where the result is created has already been closed." );
32+
super( message );
3433
}
3534
}

driver/src/main/java/org/neo4j/driver/exceptions/TransactionNestingException.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,4 @@ public TransactionNestingException( String message )
2727
{
2828
super( message );
2929
}
30-
31-
public TransactionNestingException()
32-
{
33-
this( "You cannot run another query or begin a new transaction in the same session before you've fully consumed the previous run result." );
34-
}
3530
}

driver/src/main/java/org/neo4j/driver/internal/cursor/DisposableAsyncStatementResultCursor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import java.util.function.Function;
2626

2727
import org.neo4j.driver.Record;
28-
import org.neo4j.driver.exceptions.ResultConsumedException;
2928
import org.neo4j.driver.summary.ResultSummary;
3029

30+
import static org.neo4j.driver.internal.util.ErrorUtil.newResultConsumedError;
3131
import static org.neo4j.driver.internal.util.Futures.completedWithNull;
3232
import static org.neo4j.driver.internal.util.Futures.failedFuture;
3333

@@ -109,7 +109,7 @@ private <T> CompletableFuture<T> assertNotDisposed()
109109
{
110110
if ( isDisposed )
111111
{
112-
return failedFuture( new ResultConsumedException() );
112+
return failedFuture( newResultConsumedError() );
113113
}
114114
return completedWithNull();
115115
}

driver/src/main/java/org/neo4j/driver/internal/cursor/RxStatementResultCursorImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
import java.util.function.BiConsumer;
2626

2727
import org.neo4j.driver.Record;
28-
import org.neo4j.driver.exceptions.ResultConsumedException;
28+
import org.neo4j.driver.exceptions.TransactionNestingException;
2929
import org.neo4j.driver.internal.handlers.RunResponseHandler;
3030
import org.neo4j.driver.internal.handlers.pulln.PullResponseHandler;
31-
import org.neo4j.driver.exceptions.TransactionNestingException;
3231
import org.neo4j.driver.summary.ResultSummary;
3332

33+
import static org.neo4j.driver.internal.util.ErrorUtil.newResultConsumedError;
34+
3435
public class RxStatementResultCursorImpl implements RxStatementResultCursor
3536
{
3637
static final BiConsumer<Record,Throwable> DISCARD_RECORD_CONSUMER = ( record, throwable ) -> {/*do nothing*/};
@@ -69,7 +70,7 @@ public void installRecordConsumer( BiConsumer<Record,Throwable> recordConsumer )
6970
{
7071
if ( resultConsumed )
7172
{
72-
throw new ResultConsumedException();
73+
throw newResultConsumedError();
7374
}
7475
if ( isRecordConsumerInstalled() )
7576
{
@@ -109,7 +110,8 @@ public CompletionStage<Throwable> pullAllFailureAsync()
109110
{
110111
if ( isRecordConsumerInstalled() && !isDone() )
111112
{
112-
return CompletableFuture.completedFuture( new TransactionNestingException() );
113+
return CompletableFuture.completedFuture( new TransactionNestingException(
114+
"You cannot run another query or begin a new transaction in the same session before you've fully consumed the previous run result." ) );
113115
}
114116
// It is safe to discard records as either the streaming has not started at all, or the streaming is fully finished.
115117
return discardAllFailureAsync();

driver/src/main/java/org/neo4j/driver/internal/util/ErrorUtil.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
import org.neo4j.driver.exceptions.AuthenticationException;
2727
import org.neo4j.driver.exceptions.ClientException;
2828
import org.neo4j.driver.exceptions.DatabaseException;
29-
import org.neo4j.driver.exceptions.Neo4jException;
3029
import org.neo4j.driver.exceptions.FatalDiscoveryException;
30+
import org.neo4j.driver.exceptions.Neo4jException;
31+
import org.neo4j.driver.exceptions.ResultConsumedException;
3132
import org.neo4j.driver.exceptions.ServiceUnavailableException;
3233
import org.neo4j.driver.exceptions.TransientException;
3334

@@ -53,6 +54,12 @@ public static ServiceUnavailableException newConnectionTerminatedError()
5354
"or due to restarts of the database" );
5455
}
5556

57+
public static ResultConsumedException newResultConsumedError()
58+
{
59+
return new ResultConsumedException( "Cannot access records on this result any more as the result has already been consumed " +
60+
"or the statement runner where the result is created has already been closed." );
61+
}
62+
5663
public static Neo4jException newNeo4jError( String code, String message )
5764
{
5865
String classification = extractClassification( code );

driver/src/main/java/org/neo4j/driver/reactive/RxStatementResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.neo4j.driver.Record;
2626
import org.neo4j.driver.Statement;
27+
import org.neo4j.driver.exceptions.ResultConsumedException;
2728
import org.neo4j.driver.summary.ResultSummary;
2829

2930
/**
@@ -83,8 +84,7 @@ public interface RxStatementResult
8384
* This publisher can only be subscribed by one {@link Subscriber} once.
8485
* <p>
8586
* If this publisher is subscribed after {@link #keys()}, then the publish of records is carried out after the arrival of keys.
86-
* If this publisher is subscribed after {@link #consume()}, then the publish of records is already cancelled
87-
* and an empty publisher of zero record will be return.
87+
* If this publisher is subscribed after {@link #consume()}, then a {@link ResultConsumedException} will be thrown.
8888
* @return a cold unicast publisher of records.
8989
*/
9090
Publisher<Record> records();
@@ -94,7 +94,7 @@ public interface RxStatementResult
9494
* <p>
9595
* {@linkplain Publisher#subscribe(Subscriber) Subscribing} the summary publisher results in the execution of the query followed by the result summary returned.
9696
* The summary publisher cancels record publishing if not yet subscribed and directly streams back the summary on query execution completion.
97-
* As a result, the invocation of {@link #records()} after this method, would receive an empty publisher.
97+
* As a result, the invocation of {@link #records()} after this method, would receive an {@link ResultConsumedException}.
9898
* <p>
9999
* If subscribed after {@link #keys()}, then the result summary will be published after the query execution without streaming any record to client.
100100
* If subscribed after {@link #records()}, then the result summary will be published after the query execution and the streaming of records.

0 commit comments

Comments
 (0)