Skip to content

Commit bb2fcdc

Browse files
Gor027avelanarius
authored andcommitted
Add support for BYPASS CACHE to QueryBuilder
Add support for adding BYPASS CACHE clause to the SELECT statements.
1 parent 2a3eec5 commit bb2fcdc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

driver-core/src/main/java/com/datastax/driver/core/querybuilder/Select.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class Select extends BuiltStatement {
4343
private Object limit;
4444
private Object perPartitionLimit;
4545
private boolean allowFiltering;
46+
private boolean bypassCache;
4647

4748
Select(
4849
String keyspace, String table, List<Object> columnNames, boolean isDistinct, boolean isJson) {
@@ -123,6 +124,10 @@ StringBuilder buildQueryString(List<Object> variables, CodecRegistry codecRegist
123124
builder.append(" ALLOW FILTERING");
124125
}
125126

127+
if (bypassCache) {
128+
builder.append(" BYPASS CACHE");
129+
}
130+
126131
return builder;
127132
}
128133

@@ -283,6 +288,16 @@ public Select allowFiltering() {
283288
return this;
284289
}
285290

291+
/**
292+
* Adds on {@code BYPASS CACHE} clause to this statement.
293+
*
294+
* @return this statement.
295+
*/
296+
public Select bypassCache() {
297+
bypassCache = true;
298+
return this;
299+
}
300+
286301
/** The {@code WHERE} clause of a {@code SELECT} statement. */
287302
public static class Where extends BuiltStatement.ForwardingStatement<Select> {
288303

@@ -398,6 +413,16 @@ public Select perPartitionLimit(BindMarker limit) {
398413
public Select allowFiltering() {
399414
return statement.allowFiltering();
400415
}
416+
417+
/**
418+
* Adds an {@code BYPASS CACHE} clause to the {@code SELECT} statement this {@code WHERE} clause
419+
* is part of.
420+
*
421+
* @return the {@code SELECT} statement this {@code WHERE} clause is part of.
422+
*/
423+
public Select bypassCache() {
424+
return statement.bypassCache();
425+
}
401426
}
402427

403428
/** An in-construction SELECT statement. */

driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,4 +1686,14 @@ public void should_handle_allow_filtering() {
16861686
assertThat(select().all().from("foo").where(eq("x", 42)).allowFiltering().toString())
16871687
.isEqualTo("SELECT * FROM foo WHERE x=42 ALLOW FILTERING;");
16881688
}
1689+
1690+
/** @test_category queries:builder */
1691+
@Test(groups = "unit")
1692+
public void should_handle_bypass_cache() {
1693+
assertThat(select().all().from("foo").allowFiltering().bypassCache().toString())
1694+
.isEqualTo("SELECT * FROM foo ALLOW FILTERING BYPASS CACHE;");
1695+
assertThat(
1696+
select().all().from("foo").where(eq("x", 42)).allowFiltering().bypassCache().toString())
1697+
.isEqualTo("SELECT * FROM foo WHERE x=42 ALLOW FILTERING BYPASS CACHE;");
1698+
}
16891699
}

0 commit comments

Comments
 (0)