From 3e167a9f2470f09671d5685fdb2127ff15f1f6dc Mon Sep 17 00:00:00 2001 From: Christian Spriegel Date: Thu, 10 Apr 2014 17:30:33 +0200 Subject: [PATCH] added range deletes to hector --- .../cassandra/model/MutatorImpl.java | 22 +++++++++++++++ .../hector/api/mutation/Mutator.java | 27 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/core/src/main/java/me/prettyprint/cassandra/model/MutatorImpl.java b/core/src/main/java/me/prettyprint/cassandra/model/MutatorImpl.java index 345a0bbd4..90c93074c 100644 --- a/core/src/main/java/me/prettyprint/cassandra/model/MutatorImpl.java +++ b/core/src/main/java/me/prettyprint/cassandra/model/MutatorImpl.java @@ -1,5 +1,6 @@ package me.prettyprint.cassandra.model; +import java.nio.ByteBuffer; import java.util.Arrays; import me.prettyprint.cassandra.model.thrift.ThriftConverter; @@ -18,6 +19,7 @@ import org.apache.cassandra.thrift.Cassandra; import org.apache.cassandra.thrift.Deletion; import org.apache.cassandra.thrift.SlicePredicate; +import org.apache.cassandra.thrift.SliceRange; @@ -228,6 +230,26 @@ public Mutator addDeletion(K key, String cf, N columnName, Serializer return this; } + /** + * {@inheritDoc} + */ + @Override + public Mutator addDeletion(K key, String cf, N columnNameStart, N columnNameFinish, Serializer nameSerializer) { + return addDeletion(key, cf, columnNameStart, columnNameFinish, nameSerializer, keyspace.createClock()); + } + + /** + * {@inheritDoc} + */ + @Override + public Mutator addDeletion(K key, String cf, N columnNameStart, N columnNameFinish, Serializer nameSerializer, long clock) { + SlicePredicate sp = new SlicePredicate(); + sp.setSlice_range(new SliceRange(nameSerializer.toByteBuffer(columnNameStart), nameSerializer.toByteBuffer(columnNameFinish), false, Integer.MAX_VALUE)); + Deletion d = new Deletion().setTimestamp(clock).setPredicate(sp); + getPendingMutations().addDeletion(key, Arrays.asList(cf), d); + return this; + } + /** * Batch executes all mutations scheduled to this Mutator instance by addInsertion, addDeletion etc. * May throw a HectorException which is a RuntimeException. diff --git a/core/src/main/java/me/prettyprint/hector/api/mutation/Mutator.java b/core/src/main/java/me/prettyprint/hector/api/mutation/Mutator.java index 2b791ab69..aa9be09cc 100644 --- a/core/src/main/java/me/prettyprint/hector/api/mutation/Mutator.java +++ b/core/src/main/java/me/prettyprint/hector/api/mutation/Mutator.java @@ -134,6 +134,33 @@ MutationResult superDelete(K key, String cf, SN supercolumnName, */ Mutator addDeletion(K key, String cf, N columnName, Serializer nameSerializer, long clock); + /** + * Adds a Range-Deletion to the underlying batch_mutate call. + * + * @param column name type + * @param key row key + * @param cf column family + * @param columnNameStart starting column name. Cannot be null. + * @param columnNameFinish end column name. Cannot be null. + * @param nameSerializer a name serializer + * @return a mutator + */ + Mutator addDeletion(K key, String cf, N columnNameStart, N columnNameFinish, Serializer nameSerializer); + + /** + * Adds a Range-Deletion to the underlying batch_mutate call. + * + * @param column name type + * @param key row key + * @param cf column family + * @param columnNameStart starting column name. Cannot be null. + * @param columnNameFinish end column name. Cannot be null. + * @param nameSerializer a name serializer + * @param clock custom clock to use in the deletion + * @return a mutator + */ + Mutator addDeletion(K key, String cf, N columnNameStart, N columnNameFinish, Serializer nameSerializer, long clock); + Mutator addSubDelete(K key, String cf, HSuperColumn sc);