Apply zero TTL to modifying statements.
We now apply a zero TTL if it was set. Previously, we omitted zero TTLs and dropped these. Closes #1535
This commit is contained in:
@@ -51,7 +51,7 @@ public class DeleteOptions extends WriteOptions {
|
||||
@Nullable Boolean idempotent, @Nullable CqlIdentifier keyspace, @Nullable Integer pageSize,
|
||||
@Nullable CqlIdentifier routingKeyspace, @Nullable ByteBuffer routingKey,
|
||||
@Nullable ConsistencyLevel serialConsistencyLevel,
|
||||
Duration timeout, Duration ttl, @Nullable Long timestamp, @Nullable Boolean tracing, boolean ifExists,
|
||||
Duration timeout, @Nullable Duration ttl, @Nullable Long timestamp, @Nullable Boolean tracing, boolean ifExists,
|
||||
@Nullable Filter ifCondition) {
|
||||
|
||||
super(consistencyLevel, executionProfileResolver, idempotent, keyspace, pageSize, routingKeyspace, routingKey,
|
||||
|
||||
@@ -48,7 +48,8 @@ public class InsertOptions extends WriteOptions {
|
||||
@Nullable Boolean idempotent, @Nullable CqlIdentifier keyspace, @Nullable Integer pageSize,
|
||||
@Nullable CqlIdentifier routingKeyspace, @Nullable ByteBuffer routingKey,
|
||||
@Nullable ConsistencyLevel serialConsistencyLevel,
|
||||
Duration timeout, Duration ttl, @Nullable Long timestamp, @Nullable Boolean tracing, boolean ifNotExists,
|
||||
Duration timeout, @Nullable Duration ttl, @Nullable Long timestamp, @Nullable Boolean tracing,
|
||||
boolean ifNotExists,
|
||||
boolean insertNulls) {
|
||||
|
||||
super(consistencyLevel, executionProfileResolver, idempotent, keyspace, pageSize, routingKeyspace, routingKey,
|
||||
|
||||
@@ -51,7 +51,8 @@ public class UpdateOptions extends WriteOptions {
|
||||
private UpdateOptions(@Nullable ConsistencyLevel consistencyLevel, ExecutionProfileResolver executionProfileResolver,
|
||||
@Nullable Filter ifCondition, boolean ifExists, @Nullable Boolean idempotent, @Nullable CqlIdentifier keyspace,
|
||||
@Nullable Integer pageSize, @Nullable CqlIdentifier routingKeyspace, @Nullable ByteBuffer routingKey,
|
||||
@Nullable ConsistencyLevel serialConsistencyLevel, Duration timeout, Duration ttl, @Nullable Long timestamp,
|
||||
@Nullable ConsistencyLevel serialConsistencyLevel, Duration timeout, @Nullable Duration ttl,
|
||||
@Nullable Long timestamp,
|
||||
@Nullable Boolean tracing) {
|
||||
|
||||
super(consistencyLevel, executionProfileResolver, idempotent, keyspace, pageSize, routingKeyspace, routingKey,
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.time.Duration;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.util.Bindings;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.oss.driver.api.core.cql.BatchStatement;
|
||||
@@ -205,8 +206,8 @@ public abstract class QueryOptionsUtil {
|
||||
return Math.toIntExact(ttl.getSeconds());
|
||||
}
|
||||
|
||||
private static boolean hasTtl(Duration ttl) {
|
||||
return !ttl.isZero() && !ttl.isNegative();
|
||||
private static boolean hasTtl(@Nullable Duration ttl) {
|
||||
return ttl != null && !ttl.isNegative();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,14 +43,15 @@ public class WriteOptions extends QueryOptions {
|
||||
|
||||
private static final WriteOptions EMPTY = new WriteOptionsBuilder().build();
|
||||
|
||||
private final Duration ttl;
|
||||
private final @Nullable Duration ttl;
|
||||
|
||||
private final @Nullable Long timestamp;
|
||||
|
||||
protected WriteOptions(@Nullable ConsistencyLevel consistencyLevel, ExecutionProfileResolver executionProfileResolver,
|
||||
@Nullable Boolean idempotent, @Nullable CqlIdentifier keyspace, @Nullable Integer pageSize,
|
||||
@Nullable CqlIdentifier routingKeyspace, @Nullable ByteBuffer routingKey,
|
||||
@Nullable ConsistencyLevel serialConsistencyLevel, Duration timeout, Duration ttl, @Nullable Long timestamp,
|
||||
@Nullable ConsistencyLevel serialConsistencyLevel, Duration timeout, @Nullable Duration ttl,
|
||||
@Nullable Long timestamp,
|
||||
@Nullable Boolean tracing) {
|
||||
|
||||
super(consistencyLevel, executionProfileResolver, idempotent, keyspace, pageSize, routingKeyspace, routingKey,
|
||||
@@ -92,8 +93,9 @@ public class WriteOptions extends QueryOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time to live, if set.
|
||||
* @return the time to live, if set, otherwise {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public Duration getTtl() {
|
||||
return this.ttl;
|
||||
}
|
||||
|
||||
@@ -398,11 +398,12 @@ class StatementFactoryUnitTests {
|
||||
StatementBuilder<RegularInsert> insert = statementFactory.insert(person, queryOptions);
|
||||
|
||||
SimpleStatement statement = insert.build();
|
||||
assertThat(statement.getQuery()).isEqualTo("INSERT INTO person (id) VALUES (?)");
|
||||
assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
|
||||
assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
|
||||
}
|
||||
|
||||
@Test // GH-1401
|
||||
@Test // GH-1401, GH-1535
|
||||
void insertWithOptionsShouldRenderBindMarkers() {
|
||||
|
||||
Person person = new Person();
|
||||
@@ -417,6 +418,16 @@ class StatementFactoryUnitTests {
|
||||
|
||||
assertThat(statement.getQuery()).isEqualTo("INSERT INTO person (id) VALUES (?) USING TIMESTAMP ? AND TTL ?");
|
||||
assertThat(statement.getPositionalValues()).containsExactly("foo", 1234L, 10);
|
||||
|
||||
queryOptions = WriteOptions.builder() //
|
||||
.ttl(Duration.ZERO).timestamp(1234).build();
|
||||
|
||||
insert = statementFactory.insert(person, queryOptions);
|
||||
|
||||
statement = insert.build(ParameterHandling.BY_INDEX);
|
||||
|
||||
assertThat(statement.getQuery()).isEqualTo("INSERT INTO person (id) VALUES (?) USING TIMESTAMP ? AND TTL ?");
|
||||
assertThat(statement.getPositionalValues()).containsExactly("foo", 1234L, 0);
|
||||
}
|
||||
|
||||
@Test // DATACASS-656
|
||||
|
||||
Reference in New Issue
Block a user