Skip to content
Browse files

updated to lastest API changes

  • Loading branch information...
1 parent 57c7fa8 commit f95d060f6e3204c95bed004402efc5927cee9063 zznate committed Sep 28, 2010
View
7 src/main/java/com/riptano/cassandra/hector/example/DeleteBatchMutate.java
@@ -6,9 +6,10 @@
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.BatchMutation;
import me.prettyprint.cassandra.service.CassandraClient;
-import me.prettyprint.cassandra.service.Cluster;
-import me.prettyprint.cassandra.service.Keyspace;
+import me.prettyprint.cassandra.service.KeyspaceService;
import me.prettyprint.cassandra.utils.StringUtils;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.factory.HFactory;
import org.apache.cassandra.thrift.Clock;
@@ -34,7 +35,7 @@ public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
CassandraClient client = cluster.borrowClient();
- Keyspace keyspace = client.getKeyspace("Keyspace1");
+ KeyspaceService keyspace = client.getKeyspace("Keyspace1");
try {
Clock clock = new Clock(keyspace.createClock());
Column columnFirst = new Column(StringUtils.bytes("first"),
View
4 src/main/java/com/riptano/cassandra/hector/example/DeleteSingleColumn.java
@@ -3,7 +3,7 @@
import me.prettyprint.cassandra.service.CassandraClient;
import me.prettyprint.cassandra.service.CassandraClientPool;
import me.prettyprint.cassandra.service.CassandraClientPoolFactory;
-import me.prettyprint.cassandra.service.Keyspace;
+import me.prettyprint.cassandra.service.KeyspaceService;
import me.prettyprint.cassandra.utils.StringUtils;
import org.apache.cassandra.thrift.ColumnPath;
@@ -22,7 +22,7 @@ public static void main(String[] args) throws Exception {
CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
CassandraClient client = pool.borrowClient("localhost", 9160);
- Keyspace keyspace = null;
+ KeyspaceService keyspace = null;
try {
keyspace = client.getKeyspace("Keyspace1");
ColumnPath columnPath = new ColumnPath("Standard1");
View
18 src/main/java/com/riptano/cassandra/hector/example/GetIndexedSlices.java
@@ -1,15 +1,15 @@
package com.riptano.cassandra.hector.example;
import me.prettyprint.cassandra.model.IndexedSlicesQuery;
-import me.prettyprint.cassandra.model.KeyspaceOperator;
-import me.prettyprint.cassandra.model.Mutator;
-import me.prettyprint.cassandra.model.OrderedRows;
-import me.prettyprint.cassandra.model.Result;
import me.prettyprint.cassandra.serializers.LongSerializer;
import me.prettyprint.cassandra.serializers.StringSerializer;
-import me.prettyprint.cassandra.service.Cluster;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.OrderedRows;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
/**
* Shows off the usage of the shiny new Column indexing feature via
@@ -29,10 +29,10 @@ public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspace = HFactory.createKeyspace("Keyspace1", cluster);
try {
- Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
+ Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
for (int i = 0; i < 20; i++) {
mutator.addInsertion("fake_key_" + i, "Indexed1", HFactory.createStringColumn("fake_column_0", "fake_value_0_" + i))
@@ -43,13 +43,13 @@ public static void main(String[] args) throws Exception {
mutator.execute();
IndexedSlicesQuery<String, String, Long> indexedSlicesQuery =
- HFactory.createIndexedSlicesQuery(keyspaceOperator, stringSerializer, stringSerializer, LongSerializer.get());
+ HFactory.createIndexedSlicesQuery(keyspace, stringSerializer, stringSerializer, LongSerializer.get());
indexedSlicesQuery.addEqualsExpression("birthdate", 4L);
indexedSlicesQuery.setColumnNames("birthdate","fake_column_0");
indexedSlicesQuery.setColumnFamily("Indexed1");
indexedSlicesQuery.setStartKey("");
- Result<OrderedRows<String, String, Long>> result = indexedSlicesQuery.execute();
+ QueryResult<OrderedRows<String, String, Long>> result = indexedSlicesQuery.execute();
System.out.println("The results should only have 4 entries: " + result.get());
View
21 src/main/java/com/riptano/cassandra/hector/example/GetRangeSlicesKeysOnly.java
@@ -1,15 +1,16 @@
package com.riptano.cassandra.hector.example;
-import me.prettyprint.cassandra.model.KeyspaceOperator;
-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.serializers.StringSerializer;
-import me.prettyprint.cassandra.service.Cluster;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.OrderedRows;
+import me.prettyprint.hector.api.beans.Row;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.RangeSlicesQuery;
/**
* Use get_range_slices to retrieve the keys without deserializing the columns.
@@ -29,7 +30,7 @@ public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);
try {
Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
@@ -45,10 +46,10 @@ public static void main(String[] args) throws Exception {
HFactory.createRangeSlicesQuery(keyspaceOperator, stringSerializer, stringSerializer, stringSerializer);
rangeSlicesQuery.setColumnFamily("Standard1");
rangeSlicesQuery.setKeys("fake_key_", "");
- rangeSlicesQuery.setReturnKeysOnly();
+ //rangeSlicesQuery.setReturnKeysOnly();
rangeSlicesQuery.setRowCount(5);
- Result<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
+ QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
OrderedRows<String, String, String> orderedRows = result.get();
Row<String,String,String> lastRow = orderedRows.peekLast();
View
15 src/main/java/com/riptano/cassandra/hector/example/InsertSingleColumn.java
@@ -1,14 +1,15 @@
package com.riptano.cassandra.hector.example;
-import me.prettyprint.cassandra.model.HColumn;
-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.Cluster;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
+import me.prettyprint.hector.api.query.QueryResult;
/**
* Inserts the value "John" under the Column "first" for the
@@ -27,14 +28,14 @@
public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);
try {
Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
mutator.insert("jsmith", "Standard1", HFactory.createStringColumn("first", "John"));
ColumnQuery<String, String, String> columnQuery = HFactory.createStringColumnQuery(keyspaceOperator);
columnQuery.setColumnFamily("Standard1").setKey("jsmith").setName("first");
- Result<HColumn<String, String>> result = columnQuery.execute();
+ QueryResult<HColumn<String, String>> result = columnQuery.execute();
System.out.println("Read HColumn from cassandra: " + result.get());
System.out.println("Verify on CLI with: get Keyspace1.Standard1['jsmith'] ");
View
17 src/main/java/com/riptano/cassandra/hector/example/InsertSuperColumn.java
@@ -3,21 +3,20 @@
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.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.HSuperColumn;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
+import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.SuperColumnQuery;
import org.apache.cassandra.thrift.Column;
@@ -41,7 +40,7 @@ public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);
try {
Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
mutator.insert("billing", "Super1", HFactory.createSuperColumn("jsmith",
@@ -53,7 +52,7 @@ public static void main(String[] args) throws Exception {
stringSerializer, stringSerializer);
superColumnQuery.setColumnFamily("Super1").setKey("billing").setSuperName("jsmith");
- Result<HSuperColumn<String, String, String>> result = superColumnQuery.execute();
+ QueryResult<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'] ");
View
19 src/main/java/com/riptano/cassandra/hector/example/MultigetSliceRetrieval.java
@@ -1,15 +1,16 @@
package com.riptano.cassandra.hector.example;
-import me.prettyprint.cassandra.model.KeyspaceOperator;
-import me.prettyprint.cassandra.model.MultigetSliceQuery;
-import me.prettyprint.cassandra.model.Mutator;
-import me.prettyprint.cassandra.model.Result;
-import me.prettyprint.cassandra.model.Row;
-import me.prettyprint.cassandra.model.Rows;
+
import me.prettyprint.cassandra.serializers.StringSerializer;
-import me.prettyprint.cassandra.service.Cluster;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.Row;
+import me.prettyprint.hector.api.beans.Rows;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.MultigetSliceQuery;
+import me.prettyprint.hector.api.query.QueryResult;
/**
* Use MultigetSliceQuery when you want to get the same columns from a known set of keys
@@ -28,7 +29,7 @@ public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);
try {
Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
@@ -48,7 +49,7 @@ public static void main(String[] args) throws Exception {
multigetSliceQuery.setRange(null, null, false, 3);
System.out.println(multigetSliceQuery);
- Result<Rows<String, String, String>> result = multigetSliceQuery.execute();
+ QueryResult<Rows<String, String, String>> result = multigetSliceQuery.execute();
Rows<String, String, String> orderedRows = result.get();
System.out.println("Contents of rows: \n");
View
19 src/main/java/com/riptano/cassandra/hector/example/PaginateGetRangeSlices.java
@@ -1,15 +1,16 @@
package com.riptano.cassandra.hector.example;
-import me.prettyprint.cassandra.model.KeyspaceOperator;
-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.serializers.StringSerializer;
-import me.prettyprint.cassandra.service.Cluster;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.OrderedRows;
+import me.prettyprint.hector.api.beans.Row;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.RangeSlicesQuery;
/**
* A simple example showing what it takes to page over results using
@@ -29,7 +30,7 @@ public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);
try {
Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
@@ -48,7 +49,7 @@ public static void main(String[] args) throws Exception {
rangeSlicesQuery.setRange("", "", false, 3);
rangeSlicesQuery.setRowCount(11);
- Result<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
+ QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
OrderedRows<String, String, String> orderedRows = result.get();
View
23 src/main/java/com/riptano/cassandra/hector/example/ResultDetailsDemo.java
@@ -1,17 +1,18 @@
package com.riptano.cassandra.hector.example;
-import me.prettyprint.cassandra.model.HColumn;
-import me.prettyprint.cassandra.model.KeyspaceOperator;
-import me.prettyprint.cassandra.model.MutationResult;
-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.serializers.StringSerializer;
-import me.prettyprint.cassandra.service.Cluster;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.beans.OrderedRows;
import me.prettyprint.hector.api.exceptions.HectorException;
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.ColumnQuery;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.RangeSlicesQuery;
/**
* Shows off the new ExecutionResult hierarchy
@@ -29,7 +30,7 @@
public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);
try {
Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
// add 10 rows
@@ -48,12 +49,12 @@ public static void main(String[] args) throws Exception {
rangeSlicesQuery.setRange("", "", false, 3);
rangeSlicesQuery.setRowCount(10);
- Result<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
+ QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
System.out.println("Result from rangeSlices query: " + result.toString());
ColumnQuery<String, String, String> columnQuery = HFactory.createStringColumnQuery(keyspaceOperator);
columnQuery.setColumnFamily("Standard1").setKey("fake_key_0").setName("fake_column_0");
- Result<HColumn<String, String>> colResult = columnQuery.execute();
+ QueryResult<HColumn<String, String>> colResult = columnQuery.execute();
System.out.println("Execution time: " + colResult.getExecutionTimeMicro());
System.out.println("CassandraHost used: " + colResult.getHostUsed());
System.out.println("Query Execute: " + colResult.getQuery());
View
25 src/main/java/com/riptano/cassandra/hector/example/TombstonedGetRangeSlices.java
@@ -1,17 +1,18 @@
package com.riptano.cassandra.hector.example;
-import me.prettyprint.cassandra.model.ColumnSlice;
-import me.prettyprint.cassandra.model.KeyspaceOperator;
-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.SliceQuery;
import me.prettyprint.cassandra.serializers.StringSerializer;
-import me.prettyprint.cassandra.service.Cluster;
+
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.ColumnSlice;
+import me.prettyprint.hector.api.beans.OrderedRows;
+import me.prettyprint.hector.api.beans.Row;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.Mutator;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.RangeSlicesQuery;
+import me.prettyprint.hector.api.query.SliceQuery;
/**
* Shows what tombstoned data looks like in the result sets of
@@ -33,7 +34,7 @@
public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
- KeyspaceOperator keyspaceOperator = HFactory.createKeyspaceOperator("Keyspace1", cluster);
+ Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);
try {
Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
// add 10 rows
@@ -58,7 +59,7 @@ public static void main(String[] args) throws Exception {
rangeSlicesQuery.setRange("", "", false, 3);
rangeSlicesQuery.setRowCount(10);
- Result<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
+ QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
OrderedRows<String, String, String> orderedRows = result.get();
for (Row<String, String, String> row : orderedRows) {
int keyNum = Integer.valueOf(row.getKey().substring(9));
@@ -73,7 +74,7 @@ public static void main(String[] args) throws Exception {
q.setRange("", "", false, 3);
q.setKey(row.getKey());
- Result<ColumnSlice<String, String>> r = q.execute();
+ QueryResult<ColumnSlice<String, String>> r = q.execute();
System.out.println("|-- called directly via get_slice, the value is: " +r);
// For a tombstone, you just get a null back from ColumnQuery
System.out.println("|-- try the first column via getColumn: " + HFactory.createColumnQuery(keyspaceOperator,

0 comments on commit f95d060

Please sign in to comment.
Something went wrong with that request. Please try again.