Permalink
Browse files

added deletion and insertion via batch mutate

  • Loading branch information...
1 parent 99d4d9e commit b7892d651edb0f2367be2a8cbe65dd75dccd500c zznate committed Jan 29, 2011
@@ -0,0 +1,37 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.MutationResult;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
+
+/**
+ * Uses batch_mutate to delete the rows created by {@link InsertRowsForColumnFamilies}
+ *
+ * This shows an example of range ghosts post deletion. For more information, see:
+ * http://wiki.apache.org/cassandra/FAQ#range_ghosts
+ * http://wiki.apache.org/cassandra/DistributedDeletes
+ *
+ * @author zznate
+ */
+public class DeleteRowsForColumnFamily extends TutorialCommand {
+
+ public DeleteRowsForColumnFamily(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<?> execute() {
+ Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
+
+ mutator.addDeletion("CA Burlingame", "StateCity", null, stringSerializer);
+ mutator.addDeletion("650", "AreaCode", null, stringSerializer);
+ mutator.addDeletion("650222", "Npanxx", null, stringSerializer);
+
+ MutationResult mr = mutator.execute();
+ return null;
+
+ }
+
+}
@@ -0,0 +1,37 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.MutationResult;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
+
+
+/**
+ * Uses batch_mutate to insert several rows into mutliple column families in
+ * one execution.
+ *
+ * @author zznate
+ */
+public class InsertRowsForColumnFamilies extends TutorialCommand {
+
+ public InsertRowsForColumnFamilies(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<?> execute() {
+ Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
+
+ mutator.addInsertion("CA Burlingame", "StateCity", HFactory.createColumn(650L, "37.57x122.34",longSerializer,stringSerializer));
+ mutator.addInsertion("650", "AreaCode", HFactory.createColumn("Burlingame__650", "37.57x122.34",stringSerializer,stringSerializer));
+ mutator.addInsertion("650222", "Npanxx", HFactory.createColumn("lat", "37.57",stringSerializer,stringSerializer));
+ mutator.addInsertion("650222", "Npanxx", HFactory.createColumn("lng", "122.34",stringSerializer,stringSerializer));
+ mutator.addInsertion("650222", "Npanxx", HFactory.createColumn("city", "Burlingame",stringSerializer,stringSerializer));
+ mutator.addInsertion("650222", "Npanxx", HFactory.createColumn("state", "CA",stringSerializer,stringSerializer));
+
+ MutationResult mr = mutator.execute();
+ return null;
+ }
+
+}
@@ -49,8 +49,8 @@ public static void main(String[] args) {
try {
QueryResult<?> result = command.execute();
-
- printResults(result);
+ if ( result != null)
+ printResults(result);
} catch (Exception e) {
// Cow catcher. Feel free to explore exception types here.
@@ -102,6 +102,10 @@ private static TutorialCommand loadCommand(String cmd) {
return new MultigetSliceForNpanxx(tutorialKeyspace);
} else if ( cmd.equalsIgnoreCase("get_indexed_slices")) {
return new GetIndexedSlicesForCityState(tutorialKeyspace);
+ } else if ( cmd.equalsIgnoreCase("insert")) {
+ return new InsertRowsForColumnFamilies(tutorialKeyspace);
+ } else if ( cmd.equalsIgnoreCase("delete")) {
+ return new DeleteRowsForColumnFamily(tutorialKeyspace);
}
log.error(" ***OOPS! No match found for {}.", cmd);
return null;

0 comments on commit b7892d6

Please sign in to comment.