DATACASS-90 - added ttl & timestamp options for insert/update/delete queries
This commit is contained in:
@@ -62,8 +62,12 @@ import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.SimpleStatement;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
import com.datastax.driver.core.querybuilder.Delete;
|
||||
import com.datastax.driver.core.querybuilder.Insert;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Truncate;
|
||||
import com.datastax.driver.core.querybuilder.Update;
|
||||
import com.datastax.driver.core.querybuilder.Using;
|
||||
|
||||
/**
|
||||
* <b>This is the Central class in the Cassandra core package.</b> It simplifies the use of Cassandra and helps to avoid
|
||||
@@ -94,12 +98,45 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
return q;
|
||||
}
|
||||
|
||||
// common options
|
||||
if (options.getConsistencyLevel() != null) {
|
||||
q.setConsistencyLevel(ConsistencyLevelResolver.resolve(options.getConsistencyLevel()));
|
||||
}
|
||||
if (options.getRetryPolicy() != null) {
|
||||
q.setRetryPolicy(RetryPolicyResolver.resolve(options.getRetryPolicy()));
|
||||
}
|
||||
|
||||
Using ttl = options.getTtl() == null ? null : QueryBuilder.ttl(options.getTtl());
|
||||
Using timestamp = options.getTimestamp() == null ? null : QueryBuilder.timestamp(options.getTimestamp());
|
||||
|
||||
// options for specific query types
|
||||
|
||||
if (q instanceof Insert) {
|
||||
Insert i = (Insert) q;
|
||||
if (ttl != null) {
|
||||
i.using(ttl);
|
||||
}
|
||||
if (timestamp != null) {
|
||||
i.using(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
if (q instanceof Update) {
|
||||
Update u = ((Update) q);
|
||||
if (ttl != null) {
|
||||
u.using(ttl);
|
||||
}
|
||||
if (timestamp != null) {
|
||||
u.using(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
if (q instanceof Delete) {
|
||||
Delete d = (Delete) q;
|
||||
if (timestamp != null) {
|
||||
d.using(timestamp);
|
||||
}
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
|
||||
/**
|
||||
* Contains Query Options for Cassandra queries. This controls the Consistency Tuning and Retry Policy for a Query.
|
||||
*
|
||||
@@ -27,6 +26,7 @@ public class QueryOptions {
|
||||
private ConsistencyLevel consistencyLevel;
|
||||
private RetryPolicy retryPolicy;
|
||||
private Integer ttl;
|
||||
private Long timestamp;
|
||||
|
||||
/**
|
||||
* @return Returns the consistencyLevel.
|
||||
@@ -57,16 +57,24 @@ public class QueryOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the ttl.
|
||||
* @return Returns the ttl in seconds.
|
||||
*/
|
||||
public Integer getTtl() {
|
||||
return ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ttl The ttl to set.
|
||||
* @param ttl The ttl in seconds to set.
|
||||
*/
|
||||
public void setTtl(Integer ttl) {
|
||||
this.ttl = ttl;
|
||||
public void setTtl(Integer timeToLive) {
|
||||
this.ttl = timeToLive;
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user