Skip to content

Commit d2c1513

Browse files
avelanariusshawjef3
andcommitted
Add support for USING TIMEOUT to QueryBuilder
Add support for adding USING TIMEOUT clause to SELECT, INSERT, UPDATE queries. The value of the clause (the timeout) can be passed either as a literal value (CqlDuration) or a BindMarker filled at a time of execution. Co-authored-by: Jeff Shaw <[email protected]>
1 parent 08a7a87 commit d2c1513

File tree

11 files changed

+597
-43
lines changed

11 files changed

+597
-43
lines changed

core/src/main/java/com/datastax/oss/driver/api/core/data/CqlDuration.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
/*
18+
* Copyright (C) 2022 ScyllaDB
19+
*
20+
* Modified by ScyllaDB
21+
*/
1622
package com.datastax.oss.driver.api.core.data;
1723

1824
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
@@ -365,15 +371,7 @@ public boolean equals(Object other) {
365371
}
366372
}
367373

368-
@Override
369-
public int hashCode() {
370-
return Objects.hashCode(days, months, nanoseconds);
371-
}
372-
373-
@Override
374-
public String toString() {
375-
StringBuilder builder = new StringBuilder();
376-
374+
public void appendTo(@NonNull final StringBuilder builder) {
377375
if (months < 0 || days < 0 || nanoseconds < 0) {
378376
builder.append('-');
379377
}
@@ -390,6 +388,17 @@ public String toString() {
390388
remainder = append(builder, remainder, NANOS_PER_MICRO, "us");
391389
append(builder, remainder, 1, "ns");
392390
}
391+
}
392+
393+
@Override
394+
public int hashCode() {
395+
return Objects.hashCode(days, months, nanoseconds);
396+
}
397+
398+
@Override
399+
public String toString() {
400+
StringBuilder builder = new StringBuilder();
401+
appendTo(builder);
393402
return builder.toString();
394403
}
395404

query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/insert/Insert.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
/*
18+
* Copyright (C) 2022 ScyllaDB
19+
*
20+
* Modified by ScyllaDB
21+
*/
1622
package com.datastax.oss.driver.api.querybuilder.insert;
1723

24+
import com.datastax.oss.driver.api.core.data.CqlDuration;
1825
import com.datastax.oss.driver.api.querybuilder.BindMarker;
1926
import com.datastax.oss.driver.api.querybuilder.BuildableQuery;
2027
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -72,4 +79,29 @@ public interface Insert extends BuildableQuery {
7279
*/
7380
@NonNull
7481
Insert usingTtl(@Nullable BindMarker bindMarker);
82+
83+
/**
84+
* Adds a {@code USING TIMEOUT} clause to this statement with a literal value. Setting a value of
85+
* {@code null} will remove the {@code USING TIMEOUT} clause on this statement.
86+
*
87+
* <p>If this method or {@link #usingTimeout(BindMarker) } is called multiple times, the value
88+
* from the last invocation is used.
89+
*
90+
* @param timeout A timeout value controlling server-side query timeout.
91+
*/
92+
@NonNull
93+
Insert usingTimeout(@NonNull CqlDuration timeout);
94+
95+
/**
96+
* Adds a {@code USING TIMEOUT} clause to this statement with a bind marker. Setting a value of
97+
* {@code null} will remove the {@code USING TIMEOUT} clause on this statement.
98+
*
99+
* <p>If this method or {@link #usingTimeout(CqlDuration) } is called multiple times, the value
100+
* from the last invocation is used.
101+
*
102+
* @param timeout A bind marker understood as {@link CqlDuration} controlling server-side query
103+
* timeout.
104+
*/
105+
@NonNull
106+
Insert usingTimeout(@NonNull BindMarker timeout);
75107
}

query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/select/Select.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
/*
18+
* Copyright (C) 2022 ScyllaDB
19+
*
20+
* Modified by ScyllaDB
21+
*/
1622
package com.datastax.oss.driver.api.querybuilder.select;
1723

1824
import com.datastax.oss.driver.api.core.CqlIdentifier;
25+
import com.datastax.oss.driver.api.core.data.CqlDuration;
1926
import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder;
2027
import com.datastax.oss.driver.api.querybuilder.BindMarker;
2128
import com.datastax.oss.driver.api.querybuilder.BuildableQuery;
@@ -193,4 +200,29 @@ default Select orderBy(@NonNull String columnName, @NonNull ClusteringOrder orde
193200
*/
194201
@NonNull
195202
Select allowFiltering();
203+
204+
/**
205+
* Adds a {@code USING TIMEOUT} clause to this statement with a literal value. Setting a value of
206+
* {@code null} will remove the {@code USING TIMEOUT} clause on this statement.
207+
*
208+
* <p>If this method or {@link #usingTimeout(BindMarker) } is called multiple times, the value
209+
* from the last invocation is used.
210+
*
211+
* @param timeout A timeout value controlling server-side query timeout.
212+
*/
213+
@NonNull
214+
Select usingTimeout(@NonNull CqlDuration timeout);
215+
216+
/**
217+
* Adds a {@code USING TIMEOUT} clause to this statement with a bind marker. Setting a value of
218+
* {@code null} will remove the {@code USING TIMEOUT} clause on this statement.
219+
*
220+
* <p>If this method or {@link #usingTimeout(CqlDuration) } is called multiple times, the value
221+
* from the last invocation is used.
222+
*
223+
* @param timeout A bind marker understood as {@link CqlDuration} controlling server-side query
224+
* timeout.
225+
*/
226+
@NonNull
227+
Select usingTimeout(@NonNull BindMarker timeout);
196228
}

query-builder/src/main/java/com/datastax/oss/driver/api/querybuilder/update/UpdateStart.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
/*
18+
* Copyright (C) 2022 ScyllaDB
19+
*
20+
* Modified by ScyllaDB
21+
*/
1622
package com.datastax.oss.driver.api.querybuilder.update;
1723

24+
import com.datastax.oss.driver.api.core.data.CqlDuration;
1825
import com.datastax.oss.driver.api.querybuilder.BindMarker;
1926
import edu.umd.cs.findbugs.annotations.NonNull;
2027

@@ -69,4 +76,29 @@ public interface UpdateStart extends OngoingAssignment {
6976
*/
7077
@NonNull
7178
UpdateStart usingTtl(@NonNull BindMarker bindMarker);
79+
80+
/**
81+
* Adds a {@code USING TIMEOUT} clause to this statement with a literal value. Setting a value of
82+
* {@code null} will remove the {@code USING TIMEOUT} clause on this statement.
83+
*
84+
* <p>If this method or {@link #usingTimeout(BindMarker) } is called multiple times, the value
85+
* from the last invocation is used.
86+
*
87+
* @param timeout A timeout value controlling server-side query timeout.
88+
*/
89+
@NonNull
90+
UpdateStart usingTimeout(@NonNull CqlDuration timeout);
91+
92+
/**
93+
* Adds a {@code USING TIMEOUT} clause to this statement with a bind marker. Setting a value of
94+
* {@code null} will remove the {@code USING TIMEOUT} clause on this statement.
95+
*
96+
* <p>If this method or {@link #usingTimeout(CqlDuration) } is called multiple times, the value
97+
* from the last invocation is used.
98+
*
99+
* @param timeout A bind marker understood as {@link CqlDuration} controlling server-side query
100+
* timeout.
101+
*/
102+
@NonNull
103+
UpdateStart usingTimeout(@NonNull BindMarker timeout);
72104
}

0 commit comments

Comments
 (0)