Elffuss BraidHub

kikocis/java-driver public

JAVA-1351: Include Custom Payload in Request.copy (#773)

Motivation:

When a request is retried or speculatively executed, a new Request
instance is created from the existing one using Request.copy.  This has
a side effect of not carrying over custom payload from the previous
request.  This change ensures Request.copy carries over custom payload
from the previous Request if present.

Modifications:

Renamed existing copy implementations to copyInternal and introduced new
copy methods that call copyInternal and then setCustomPayload to carry
over custom payload from previous Request.

Result:

Custom payload is now carried over on retries and speculative
executions.
Changeseteb74149ffde994cde4aadabe5f4d25e43b64438fd3711e762d877635d3afa7da
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-09 17:54 -06:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2016-12-09 15:54 -08:00
Parents37a0d01b83e2

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -3,6 +3,7 @@
33 ### 3.0.6 (in progress)
44
55 - [bug] JAVA-1330: Add un/register for SchemaChangeListener in DelegatingCluster
6+- [bug] JAVA-1351: Include Custom Payload in Request.copy.
67
78
89 ### 3.0.5
modified driver-core/src/main/java/com/datastax/driver/core/Message.java +13 −1
@@ -180,9 +180,21 @@
180180 }
181181 }
182182
183- abstract Request copy();
183+ Request copy() {
184+ Request request = copyInternal();
185+ request.setCustomPayload(this.getCustomPayload());
186+ return request;
187+ }
188+
189+ protected abstract Request copyInternal();
184190
185191 Request copy(ConsistencyLevel newConsistencyLevel) {
192+ Request request = copyInternal(newConsistencyLevel);
193+ request.setCustomPayload(this.getCustomPayload());
194+ return request;
195+ }
196+
197+ protected Request copyInternal(ConsistencyLevel newConsistencyLevel) {
186198 throw new UnsupportedOperationException();
187199 }
188200 }
modified driver-core/src/main/java/com/datastax/driver/core/Requests.java +12 −12
@@ -63,7 +63,7 @@
6363 }
6464
6565 @Override
66- Request copy() {
66+ protected Request copyInternal() {
6767 return new Startup(compression);
6868 }
6969
@@ -99,7 +99,7 @@
9999 }
100100
101101 @Override
102- Request copy() {
102+ protected Request copyInternal() {
103103 return new Credentials(credentials);
104104 }
105105 }
@@ -122,7 +122,7 @@
122122 }
123123
124124 @Override
125- Request copy() {
125+ protected Request copyInternal() {
126126 return new Options();
127127 }
128128
@@ -162,12 +162,12 @@
162162 }
163163
164164 @Override
165- Request copy() {
165+ protected Request copyInternal() {
166166 return new Query(this.query, options, isTracingRequested());
167167 }
168168
169169 @Override
170- Request copy(ConsistencyLevel newConsistencyLevel) {
170+ protected Request copyInternal(ConsistencyLevel newConsistencyLevel) {
171171 return new Query(this.query, options.copy(newConsistencyLevel), isTracingRequested());
172172 }
173173
@@ -203,12 +203,12 @@
203203 }
204204
205205 @Override
206- Request copy() {
206+ protected Request copyInternal() {
207207 return new Execute(statementId, options, isTracingRequested());
208208 }
209209
210210 @Override
211- Request copy(ConsistencyLevel newConsistencyLevel) {
211+ protected Request copyInternal(ConsistencyLevel newConsistencyLevel) {
212212 return new Execute(statementId, options.copy(newConsistencyLevel), isTracingRequested());
213213 }
214214
@@ -460,12 +460,12 @@
460460 }
461461
462462 @Override
463- Request copy() {
463+ protected Request copyInternal() {
464464 return new Batch(type, queryOrIdList, values, options, isTracingRequested());
465465 }
466466
467467 @Override
468- Request copy(ConsistencyLevel newConsistencyLevel) {
468+ protected Request copyInternal(ConsistencyLevel newConsistencyLevel) {
469469 return new Batch(type, queryOrIdList, values, options.copy(newConsistencyLevel), isTracingRequested());
470470 }
471471
@@ -571,7 +571,7 @@
571571 }
572572
573573 @Override
574- Request copy() {
574+ protected Request copyInternal() {
575575 return new Prepare(query);
576576 }
577577
@@ -608,7 +608,7 @@
608608 }
609609
610610 @Override
611- Request copy() {
611+ protected Request copyInternal() {
612612 return new Register(eventTypes);
613613 }
614614
@@ -641,7 +641,7 @@
641641 }
642642
643643 @Override
644- Request copy() {
644+ protected Request copyInternal() {
645645 return new AuthResponse(token);
646646 }
647647 }