30
30
import org .neo4j .driver .internal .handlers .pulln .PullResponseHandler ;
31
31
import org .neo4j .driver .summary .ResultSummary ;
32
32
33
+ import static org .neo4j .driver .internal .cursor .RxStatementResultCursorImpl .RecordConsumerStatus .DISCARD_INSTALLED ;
34
+ import static org .neo4j .driver .internal .cursor .RxStatementResultCursorImpl .RecordConsumerStatus .INSTALLED ;
35
+ import static org .neo4j .driver .internal .cursor .RxStatementResultCursorImpl .RecordConsumerStatus .NOT_INSTALLED ;
33
36
import static org .neo4j .driver .internal .util .ErrorUtil .newResultConsumedError ;
34
37
35
38
public class RxStatementResultCursorImpl implements RxStatementResultCursor
@@ -39,8 +42,8 @@ public class RxStatementResultCursorImpl implements RxStatementResultCursor
39
42
private final PullResponseHandler pullHandler ;
40
43
private final Throwable runResponseError ;
41
44
private final CompletableFuture <ResultSummary > summaryFuture = new CompletableFuture <>();
42
- private BiConsumer <Record ,Throwable > recordConsumer ;
43
45
private boolean resultConsumed ;
46
+ private RecordConsumerStatus consumerStatus = NOT_INSTALLED ;
44
47
45
48
public RxStatementResultCursorImpl ( RunResponseHandler runHandler , PullResponseHandler pullHandler )
46
49
{
@@ -72,20 +75,17 @@ public void installRecordConsumer( BiConsumer<Record,Throwable> recordConsumer )
72
75
{
73
76
throw newResultConsumedError ();
74
77
}
75
- if ( isRecordConsumerInstalled () )
78
+
79
+ if ( consumerStatus .isInstalled () )
76
80
{
77
81
return ;
78
82
}
79
- this .recordConsumer = recordConsumer ;
80
- pullHandler .installRecordConsumer ( this .recordConsumer );
83
+ consumerStatus = recordConsumer == DISCARD_RECORD_CONSUMER ?
84
+ DISCARD_INSTALLED : INSTALLED ;
85
+ pullHandler .installRecordConsumer ( recordConsumer );
81
86
assertRunCompletedSuccessfully ();
82
87
}
83
88
84
- private boolean isRecordConsumerInstalled ()
85
- {
86
- return this .recordConsumer != null ;
87
- }
88
-
89
89
@ Override
90
90
public void request ( long n )
91
91
{
@@ -108,7 +108,7 @@ public CompletionStage<Throwable> discardAllFailureAsync()
108
108
@ Override
109
109
public CompletionStage <Throwable > pullAllFailureAsync ()
110
110
{
111
- if ( isRecordConsumerInstalled () && !isDone () )
111
+ if ( consumerStatus . isInstalled () && !isDone () )
112
112
{
113
113
return CompletableFuture .completedFuture ( new TransactionNestingException (
114
114
"You cannot run another query or begin a new transaction in the same session before you've fully consumed the previous run result." ) );
@@ -146,7 +146,7 @@ private void assertRunCompletedSuccessfully()
146
146
private void installSummaryConsumer ()
147
147
{
148
148
pullHandler .installSummaryConsumer ( ( summary , error ) -> {
149
- if ( error != null && recordConsumer == DISCARD_RECORD_CONSUMER )
149
+ if ( error != null && consumerStatus . isDiscardConsumer () )
150
150
{
151
151
// We will only report the error to summary if there is no user record consumer installed
152
152
// When a user record consumer is installed, the error will be reported to record consumer instead.
@@ -167,4 +167,30 @@ private void assertRunResponseArrived( RunResponseHandler runHandler )
167
167
throw new IllegalStateException ( "Should wait for response of RUN before allowing PULL." );
168
168
}
169
169
}
170
+
171
+ enum RecordConsumerStatus
172
+ {
173
+ NOT_INSTALLED ( false , false ),
174
+ INSTALLED ( true , false ),
175
+ DISCARD_INSTALLED ( true , true );
176
+
177
+ private final boolean isInstalled ;
178
+ private final boolean isDiscardConsumer ;
179
+
180
+ RecordConsumerStatus ( boolean isInstalled , boolean isDiscardConsumer )
181
+ {
182
+ this .isInstalled = isInstalled ;
183
+ this .isDiscardConsumer = isDiscardConsumer ;
184
+ }
185
+
186
+ boolean isInstalled ()
187
+ {
188
+ return isInstalled ;
189
+ }
190
+
191
+ boolean isDiscardConsumer ()
192
+ {
193
+ return isDiscardConsumer ;
194
+ }
195
+ }
170
196
}
0 commit comments