Skip to content

Commit 09364c2

Browse files
committed
JAVA-2054: Add now_in_seconds to protocol v5 query messages
1 parent a33f23c commit 09364c2

22 files changed

Lines changed: 442 additions & 77 deletions

bom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>com.datastax.oss</groupId>
6363
<artifactId>native-protocol</artifactId>
64-
<version>1.4.9</version>
64+
<version>1.4.10-SNAPSHOT</version>
6565
</dependency>
6666
<dependency>
6767
<groupId>com.datastax.oss</groupId>

changelog/README.md

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

55
### 4.6.0 (in progress)
66

7+
- [new feature] JAVA-2054: Add now_in_seconds to protocol v5 query messages
78
- [bug] JAVA-2711: Fix handling of UDT keys in the mapper
89
- [improvement] JAVA-2631: Add getIndex() shortcuts to TableMetadata
910
- [improvement] JAVA-2679: Add port information to QueryTrace and TraceEvent

core/src/main/java/com/datastax/dse/driver/internal/core/insights/InsightsClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ private QueryOptions createQueryOptionsWithJson(String json) {
238238
QueryOptions.DEFAULT.pagingState,
239239
QueryOptions.DEFAULT.serialConsistency,
240240
QueryOptions.DEFAULT.defaultTimestamp,
241-
QueryOptions.DEFAULT.keyspace);
241+
QueryOptions.DEFAULT.keyspace,
242+
QueryOptions.DEFAULT.nowInSeconds);
242243
}
243244

244245
private boolean shouldSendEvent() {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ static BatchStatement newInstance(@NonNull BatchType batchType) {
6565
null,
6666
null,
6767
null,
68-
null);
68+
null,
69+
Statement.NO_NOW_IN_SECONDS);
6970
}
7071

7172
/**
@@ -95,7 +96,8 @@ static BatchStatement newInstance(
9596
null,
9697
null,
9798
null,
98-
null);
99+
null,
100+
Statement.NO_NOW_IN_SECONDS);
99101
}
100102

101103
/**
@@ -125,7 +127,8 @@ static BatchStatement newInstance(
125127
null,
126128
null,
127129
null,
128-
null);
130+
null,
131+
Statement.NO_NOW_IN_SECONDS);
129132
}
130133

131134
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public BatchStatement build() {
152152
consistencyLevel,
153153
serialConsistencyLevel,
154154
timeout,
155-
node);
155+
node,
156+
nowInSeconds);
156157
}
157158

158159
public int getStatementsCount() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public BoundStatement build() {
174174
timeout,
175175
codecRegistry,
176176
protocolVersion,
177-
node);
177+
node,
178+
nowInSeconds);
178179
}
179180
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ static SimpleStatement newInstance(@NonNull String cqlQuery) {
8080
null,
8181
null,
8282
null,
83-
null);
83+
null,
84+
Statement.NO_NOW_IN_SECONDS);
8485
}
8586

8687
/**
@@ -113,7 +114,8 @@ static SimpleStatement newInstance(
113114
null,
114115
null,
115116
null,
116-
null);
117+
null,
118+
Statement.NO_NOW_IN_SECONDS);
117119
}
118120

119121
/**
@@ -143,7 +145,8 @@ static SimpleStatement newInstance(
143145
null,
144146
null,
145147
null,
146-
null);
148+
null,
149+
Statement.NO_NOW_IN_SECONDS);
147150
}
148151

149152
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public SimpleStatement build() {
182182
consistencyLevel,
183183
serialConsistencyLevel,
184184
timeout,
185-
node);
185+
node,
186+
nowInSeconds);
186187
}
187188
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.datastax.oss.driver.api.core.time.TimestampGenerator;
3232
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
3333
import com.datastax.oss.driver.internal.core.util.RoutingKey;
34+
import com.datastax.oss.protocol.internal.request.query.QueryOptions;
3435
import edu.umd.cs.findbugs.annotations.CheckReturnValue;
3536
import edu.umd.cs.findbugs.annotations.NonNull;
3637
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -67,6 +68,13 @@ public interface Statement<SelfT extends Statement<SelfT>> extends Request {
6768
GenericType<CompletionStage<AsyncResultSet>> ASYNC =
6869
new GenericType<CompletionStage<AsyncResultSet>>() {};
6970

71+
/**
72+
* A special value for {@link #getNowInSeconds()} that means "no value".
73+
*
74+
* <p>It is equal to {@link Integer#MIN_VALUE}.
75+
*/
76+
int NO_NOW_IN_SECONDS = QueryOptions.NO_NOW_IN_SECONDS;
77+
7078
/**
7179
* Sets the name of the execution profile that will be used for this statement.
7280
*
@@ -348,6 +356,34 @@ default SelfT setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents) {
348356
/** Whether tracing information should be recorded for this statement. */
349357
boolean isTracing();
350358

359+
/**
360+
* A custom "now in seconds" to use when applying the request (for testing purposes).
361+
*
362+
* <p>This method's default implementation returns {@link #NO_NOW_IN_SECONDS}. The only reason it
363+
* exists is to preserve binary compatibility. Internally, the driver overrides it to return the
364+
* value that was set programmatically (if any).
365+
*
366+
* @see #NO_NOW_IN_SECONDS
367+
*/
368+
default int getNowInSeconds() {
369+
return NO_NOW_IN_SECONDS;
370+
}
371+
372+
/**
373+
* Sets the "now in seconds" to use when applying the request (for testing purposes).
374+
*
375+
* <p>This method's default implementation returns the statement unchanged. The only reason it
376+
* exists is to preserve binary compatibility. Internally, the driver overrides it to record the
377+
* new value.
378+
*
379+
* @see #NO_NOW_IN_SECONDS
380+
*/
381+
@NonNull
382+
@SuppressWarnings("unchecked")
383+
default SelfT setNowInSeconds(int nowInSeconds) {
384+
return (SelfT) this;
385+
}
386+
351387
/**
352388
* Calculates the approximate size in bytes that the statement will have when encoded.
353389
*

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public abstract class StatementBuilder<
5858
@Nullable protected ConsistencyLevel serialConsistencyLevel;
5959
@Nullable protected Duration timeout;
6060
@Nullable protected Node node;
61+
protected int nowInSeconds = Statement.NO_NOW_IN_SECONDS;
6162

6263
protected StatementBuilder() {
6364
// nothing to do
@@ -83,6 +84,7 @@ protected StatementBuilder(StatementT template) {
8384
this.serialConsistencyLevel = template.getSerialConsistencyLevel();
8485
this.timeout = template.getTimeout();
8586
this.node = template.getNode();
87+
this.nowInSeconds = template.getNowInSeconds();
8688
}
8789

8890
/** @see Statement#setExecutionProfileName(String) */
@@ -227,6 +229,12 @@ public SelfT setNode(@Nullable Node node) {
227229
return self;
228230
}
229231

232+
/** @see Statement#setNowInSeconds(int) */
233+
public SelfT setNowInSeconds(int nowInSeconds) {
234+
this.nowInSeconds = nowInSeconds;
235+
return self;
236+
}
237+
230238
@NonNull
231239
protected Map<String, ByteBuffer> buildCustomPayload() {
232240
return (customPayloadBuilder == null)

0 commit comments

Comments
 (0)