Skip to content

Commit 6fe9585

Browse files
tolbertamolim7t
authored andcommitted
JAVA-1879: Duplicate basic.request options as Statement attributes
1 parent 2b9d189 commit 6fe9585

25 files changed

Lines changed: 1255 additions & 149 deletions

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.0.0-beta1 (in progress)
66

7+
- [improvement] JAVA-1879: Duplicate basic.request options as Request/Statement attributes
78
- [improvement] JAVA-1870: Use sensible defaults in RequestLogger if config options are missing
89
- [improvement] JAVA-1877: Use a separate reconnection schedule for the control connection
910
- [improvement] JAVA-1763: Generate a binary tarball as part of the build process

core/src/main/java/com/datastax/oss/driver/api/core/cql/BatchStatement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ static BatchStatement newInstance(@NonNull BatchType batchType) {
5656
false,
5757
false,
5858
Long.MIN_VALUE,
59+
null,
60+
Integer.MIN_VALUE,
61+
null,
62+
null,
5963
null);
6064
}
6165

@@ -79,6 +83,10 @@ static BatchStatement newInstance(
7983
false,
8084
false,
8185
Long.MIN_VALUE,
86+
null,
87+
Integer.MIN_VALUE,
88+
null,
89+
null,
8290
null);
8391
}
8492

core/src/main/java/com/datastax/oss/driver/api/core/cql/BatchStatementBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public BatchStatement build() {
142142
idempotent,
143143
tracing,
144144
timestamp,
145-
pagingState);
145+
pagingState,
146+
pageSize,
147+
consistencyLevel,
148+
serialConsistencyLevel,
149+
timeout);
146150
}
147151
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/BoundStatementBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public BoundStatement build() {
130130
tracing,
131131
timestamp,
132132
pagingState,
133+
pageSize,
134+
consistencyLevel,
135+
serialConsistencyLevel,
136+
timeout,
133137
codecRegistry,
134138
protocolVersion);
135139
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/PrepareRequest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.datastax.oss.driver.api.core.cql;
1717

18+
import com.datastax.oss.driver.api.core.ConsistencyLevel;
1819
import com.datastax.oss.driver.api.core.CqlSession;
1920
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
2021
import com.datastax.oss.driver.api.core.retry.RetryPolicy;
@@ -110,4 +111,24 @@ default boolean isTracing() {
110111
*/
111112
@Nullable
112113
Boolean areBoundStatementsIdempotent();
114+
115+
/**
116+
* The page size to use for the bound statements that will be created from the prepared statement.
117+
* If the value is 0 or negative, the default value will be used from the configuration.
118+
*/
119+
int getPageSizeForBoundStatements();
120+
121+
/**
122+
* The consistency level to use for the bound statements that will be created from the prepared
123+
* statement or {@link null} to use the default value from the configuration.
124+
*/
125+
@Nullable
126+
ConsistencyLevel getConsistencyLevelForBoundStatements();
127+
128+
/**
129+
* The serial consistency level to use for the bound statements that will be created from the
130+
* prepared statement or {@code null} to use the default value from the configuration.
131+
*/
132+
@Nullable
133+
ConsistencyLevel getSerialConsistencyLevelForBoundStatements();
113134
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/SimpleStatement.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ static SimpleStatement newInstance(@NonNull String cqlQuery) {
7373
null,
7474
false,
7575
Long.MIN_VALUE,
76+
null,
77+
Integer.MIN_VALUE,
78+
null,
79+
null,
7680
null);
7781
}
7882

@@ -99,6 +103,10 @@ static SimpleStatement newInstance(
99103
null,
100104
false,
101105
Long.MIN_VALUE,
106+
null,
107+
Integer.MIN_VALUE,
108+
null,
109+
null,
102110
null);
103111
}
104112

@@ -122,6 +130,10 @@ static SimpleStatement newInstance(
122130
null,
123131
false,
124132
Long.MIN_VALUE,
133+
null,
134+
Integer.MIN_VALUE,
135+
null,
136+
null,
125137
null);
126138
}
127139

core/src/main/java/com/datastax/oss/driver/api/core/cql/SimpleStatementBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ public SimpleStatement build() {
172172
idempotent,
173173
tracing,
174174
timestamp,
175-
pagingState);
175+
pagingState,
176+
pageSize,
177+
consistencyLevel,
178+
serialConsistencyLevel,
179+
timeout);
176180
}
177181
}

core/src/main/java/com/datastax/oss/driver/api/core/cql/Statement.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package com.datastax.oss.driver.api.core.cql;
1717

18+
import com.datastax.oss.driver.api.core.ConsistencyLevel;
1819
import com.datastax.oss.driver.api.core.CqlIdentifier;
1920
import com.datastax.oss.driver.api.core.CqlSession;
21+
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
2022
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
2123
import com.datastax.oss.driver.api.core.context.DriverContext;
2224
import com.datastax.oss.driver.api.core.metadata.token.Token;
@@ -28,6 +30,7 @@
2830
import edu.umd.cs.findbugs.annotations.NonNull;
2931
import edu.umd.cs.findbugs.annotations.Nullable;
3032
import java.nio.ByteBuffer;
33+
import java.time.Duration;
3134
import java.util.Map;
3235
import java.util.concurrent.CompletionStage;
3336

@@ -195,6 +198,17 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
195198
@NonNull
196199
T setTimestamp(long newTimestamp);
197200

201+
/**
202+
* Sets how long to wait for this request to complete. This is a global limit on the duration of a
203+
* session.execute() call, including any retries the driver might do.
204+
*
205+
* @param newTimeout the timeout to use, or {@code null} to use the default value defined in the
206+
* configuration.
207+
* @see DefaultDriverOption#REQUEST_TIMEOUT
208+
*/
209+
@NonNull
210+
T setTimeout(@Nullable Duration newTimeout);
211+
198212
/**
199213
* Returns the paging state to send with the statement, or {@code null} if this statement has no
200214
* paging state.
@@ -225,6 +239,65 @@ default T setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
225239
@NonNull
226240
T setPagingState(@Nullable ByteBuffer newPagingState);
227241

242+
/**
243+
* Returns the page size to use for the statement.
244+
*
245+
* @return the set page size, otherwise 0 or a negative value to use the default value defined in
246+
* the configuration.
247+
* @see DefaultDriverOption#REQUEST_PAGE_SIZE
248+
*/
249+
int getPageSize();
250+
251+
/**
252+
* Configures how many rows will be retrieved simultaneously in a single network roundtrip (the
253+
* goal being to avoid loading too many results in memory at the same time).
254+
*
255+
* @param newPageSize the page size to use, set to 0 or a negative value to use the default value
256+
* defined in the configuration.
257+
* @see DefaultDriverOption#REQUEST_PAGE_SIZE
258+
*/
259+
@NonNull
260+
T setPageSize(int newPageSize);
261+
262+
/**
263+
* Returns the {@link ConsistencyLevel} to use for the statement.
264+
*
265+
* @return the set consistency, or {@code null} to use the default value defined in the
266+
* configuration.
267+
* @see DefaultDriverOption#REQUEST_CONSISTENCY
268+
*/
269+
@Nullable
270+
ConsistencyLevel getConsistencyLevel();
271+
272+
/**
273+
* Sets the {@link ConsistencyLevel} to use for this statement.
274+
*
275+
* @param newConsistencyLevel the consistency level to use, or null to use the default value
276+
* defined in the configuration.
277+
* @see DefaultDriverOption#REQUEST_CONSISTENCY
278+
*/
279+
T setConsistencyLevel(@Nullable ConsistencyLevel newConsistencyLevel);
280+
281+
/**
282+
* Returns the serial {@link ConsistencyLevel} to use for the statement.
283+
*
284+
* @return the set serial consistency, or {@code null} to use the default value defined in the
285+
* configuration.
286+
* @see DefaultDriverOption#REQUEST_SERIAL_CONSISTENCY
287+
*/
288+
@Nullable
289+
ConsistencyLevel getSerialConsistencyLevel();
290+
291+
/**
292+
* Sets the serial {@link ConsistencyLevel} to use for this statement.
293+
*
294+
* @param newSerialConsistencyLevel the serial consistency level to use, or null to use the
295+
* default value defined in the configuration.
296+
* @see DefaultDriverOption#REQUEST_SERIAL_CONSISTENCY
297+
*/
298+
@NonNull
299+
T setSerialConsistencyLevel(@Nullable ConsistencyLevel newSerialConsistencyLevel);
300+
228301
/**
229302
* Calculates the approximate size in bytes that the statement will have when encoded.
230303
*

core/src/main/java/com/datastax/oss/driver/api/core/cql/StatementBuilder.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
*/
1616
package com.datastax.oss.driver.api.core.cql;
1717

18+
import com.datastax.oss.driver.api.core.ConsistencyLevel;
1819
import com.datastax.oss.driver.api.core.CqlIdentifier;
1920
import com.datastax.oss.driver.api.core.config.DriverConfigProfile;
2021
import com.datastax.oss.driver.api.core.metadata.token.Token;
2122
import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap;
2223
import edu.umd.cs.findbugs.annotations.NonNull;
2324
import edu.umd.cs.findbugs.annotations.Nullable;
2425
import java.nio.ByteBuffer;
26+
import java.time.Duration;
2527
import java.util.Map;
2628
import net.jcip.annotations.NotThreadSafe;
2729

@@ -48,6 +50,10 @@ public abstract class StatementBuilder<T extends StatementBuilder<T, S>, S exten
4850
protected boolean tracing;
4951
protected long timestamp = Long.MIN_VALUE;
5052
@Nullable protected ByteBuffer pagingState;
53+
protected int pageSize = Integer.MIN_VALUE;
54+
@Nullable protected ConsistencyLevel consistencyLevel;
55+
@Nullable protected ConsistencyLevel serialConsistencyLevel;
56+
@Nullable protected Duration timeout;
5157

5258
protected StatementBuilder() {
5359
// nothing to do
@@ -62,6 +68,10 @@ protected StatementBuilder(S template) {
6268
this.tracing = template.isTracing();
6369
this.timestamp = template.getTimestamp();
6470
this.pagingState = template.getPagingState();
71+
this.pageSize = template.getPageSize();
72+
this.consistencyLevel = template.getConsistencyLevel();
73+
this.serialConsistencyLevel = template.getSerialConsistencyLevel();
74+
this.timeout = template.getTimeout();
6575
}
6676

6777
/** @see Statement#setConfigProfileName(String) */
@@ -155,6 +165,34 @@ public T withPagingState(@Nullable ByteBuffer pagingState) {
155165
return self;
156166
}
157167

168+
/** @see Statement#setPageSize(int) */
169+
@NonNull
170+
public T withPageSize(int pageSize) {
171+
this.pageSize = pageSize;
172+
return self;
173+
}
174+
175+
/** @see Statement#setConsistencyLevel(ConsistencyLevel) */
176+
@NonNull
177+
public T withConsistencyLevel(@Nullable ConsistencyLevel consistencyLevel) {
178+
this.consistencyLevel = consistencyLevel;
179+
return self;
180+
}
181+
182+
/** @see Statement#setSerialConsistencyLevel(ConsistencyLevel) */
183+
@NonNull
184+
public T withSerialConsistencyLevel(@Nullable ConsistencyLevel serialConsistencyLevel) {
185+
this.serialConsistencyLevel = serialConsistencyLevel;
186+
return self;
187+
}
188+
189+
/** @see Statement#setTimeout(Duration) */
190+
@NonNull
191+
public T withTimeout(@Nullable Duration timeout) {
192+
this.timeout = timeout;
193+
return self;
194+
}
195+
158196
@NonNull
159197
protected Map<String, ByteBuffer> buildCustomPayload() {
160198
return (customPayloadBuilder == null)

core/src/main/java/com/datastax/oss/driver/api/core/session/Request.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import edu.umd.cs.findbugs.annotations.NonNull;
2525
import edu.umd.cs.findbugs.annotations.Nullable;
2626
import java.nio.ByteBuffer;
27+
import java.time.Duration;
2728
import java.util.Map;
2829

2930
/**
@@ -149,6 +150,17 @@ public interface Request {
149150
@Nullable
150151
Boolean isIdempotent();
151152

153+
/**
154+
* How long to wait for this request to complete. This is a global limit on the duration of a
155+
* session.execute() call, including any retries the driver might do.
156+
*
157+
* @return the set duration, or {@code null} to use the default value defined in the
158+
* configuration.
159+
* @see DefaultDriverOption#REQUEST_TIMEOUT
160+
*/
161+
@Nullable
162+
Duration getTimeout();
163+
152164
/**
153165
* Whether tracing information should be recorded for this request.
154166
*

0 commit comments

Comments
 (0)