Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update package names from hector api changes, update supercol example

  • Loading branch information...
commit 43d6577da99492a175c273934e472294acf4ef7a 1 parent 90670a7
zznate authored
View
4 src/main/java/com/riptano/cassandra/hector/example/DeleteBatchMutate.java
@@ -3,12 +3,9 @@
import java.util.Arrays;
import java.util.List;
-import me.prettyprint.cassandra.model.KeyspaceOperator;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.BatchMutation;
import me.prettyprint.cassandra.service.CassandraClient;
-import me.prettyprint.cassandra.service.CassandraClientPool;
-import me.prettyprint.cassandra.service.CassandraClientPoolFactory;
import me.prettyprint.cassandra.service.Cluster;
import me.prettyprint.cassandra.service.Keyspace;
import me.prettyprint.cassandra.utils.StringUtils;
@@ -17,7 +14,6 @@
import org.apache.cassandra.thrift.Clock;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnParent;
-import org.apache.cassandra.thrift.ColumnPath;
import org.apache.cassandra.thrift.Deletion;
import org.apache.cassandra.thrift.SlicePredicate;
View
55 src/main/java/com/riptano/cassandra/hector/example/InsertSuperColumn.java
@@ -1,12 +1,24 @@
package com.riptano.cassandra.hector.example;
+import java.util.Arrays;
import java.util.Iterator;
+import me.prettyprint.cassandra.model.HColumn;
+import me.prettyprint.cassandra.model.HSuperColumn;
+import me.prettyprint.cassandra.model.KeyspaceOperator;
+import me.prettyprint.cassandra.model.Mutator;
+import me.prettyprint.cassandra.model.Result;
+import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.CassandraClient;
import me.prettyprint.cassandra.service.CassandraClientPool;
import me.prettyprint.cassandra.service.CassandraClientPoolFactory;
+import me.prettyprint.cassandra.service.Cluster;
import me.prettyprint.cassandra.service.Keyspace;
import me.prettyprint.cassandra.utils.StringUtils;
+import me.prettyprint.hector.api.exceptions.HectorException;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.query.ColumnQuery;
+import me.prettyprint.hector.api.query.SuperColumnQuery;
import org.apache.cassandra.thrift.Column;
import org.apache.cassandra.thrift.ColumnPath;
@@ -22,34 +34,31 @@
*
*/
public class InsertSuperColumn {
+
+ private static StringSerializer stringSerializer = StringSerializer.get();
+
public static void main(String[] args) throws Exception {
- CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
- CassandraClient client = pool.borrowClient("localhost", 9160);
- Keyspace keyspace = null;
+ Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
+
+ KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
try {
- keyspace = client.getKeyspace("Keyspace1");
-
- ColumnPath columnPath = new ColumnPath("Super1");
- columnPath.setColumn(StringUtils.bytes("first"));
- columnPath.setSuper_column(StringUtils.bytes("jsmith"));
- keyspace.insert("billing", columnPath, StringUtils.bytes("John"));
-
- SuperColumn sc = keyspace.getSuperColumn("billing", columnPath);
- Iterator<Column> columnIterator = sc.getColumnsIterator();
+ Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
+ mutator.insert("billing", "Super1", HFactory.createSuperColumn("jsmith", Arrays.asList(HFactory.createStringColumn("first", "John")),
+ stringSerializer, stringSerializer, stringSerializer));
- while(columnIterator.hasNext()) {
- Column column = columnIterator.next();
- System.out.println("Read from cassandra: sc: "
- + StringUtils.string(sc.getName())
- + " col:"
- + StringUtils.string(column.getName())
- + " val:" + StringUtils.string(column.getValue()));
- }
+ SuperColumnQuery<String, String, String, String> superColumnQuery =
+ HFactory.createSuperColumnQuery(keyspaceOperator, stringSerializer, stringSerializer, stringSerializer, stringSerializer);
+ superColumnQuery.setColumnFamily("Super1").setKey("billing").setSuperName("jsmith");
+
+ Result<HSuperColumn<String, String, String>> result = superColumnQuery.execute();
+
+ System.out.println("Read HSuperColumn from cassandra: " + result.get());
System.out.println("Verify on CLI with: get Keyspace1.Super1['billing']['jsmith'] ");
+
+ } catch (HectorException e) {
+ e.printStackTrace();
+ }
- } finally {
- pool.releaseClient(keyspace.getClient());
- }
}
}
View
3  src/main/java/com/riptano/cassandra/hector/example/MultigetSliceRetrieval.java
@@ -3,8 +3,6 @@
import me.prettyprint.cassandra.model.KeyspaceOperator;
import me.prettyprint.cassandra.model.MultigetSliceQuery;
import me.prettyprint.cassandra.model.Mutator;
-import me.prettyprint.cassandra.model.OrderedRows;
-import me.prettyprint.cassandra.model.RangeSlicesQuery;
import me.prettyprint.cassandra.model.Result;
import me.prettyprint.cassandra.model.Row;
import me.prettyprint.cassandra.model.Rows;
@@ -46,7 +44,6 @@ public static void main(String[] args) throws Exception {
HFactory.createMultigetSliceQuery(keyspaceOperator, stringSerializer, stringSerializer, stringSerializer);
multigetSliceQuery.setColumnFamily("Standard1");
multigetSliceQuery.setKeys("fake_key_0", "fake_key_1","fake_key_2", "fake_key_3", "fake_key_4");
- //multigetSliceQuery.setColumnNames("fake_column_0");
multigetSliceQuery.setRange("", "", false, 3);
System.out.println(multigetSliceQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.