Skip to content

Commit

Permalink
updated to lastest API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zznate committed Sep 28, 2010
1 parent 57c7fa8 commit f95d060
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,14 +28,14 @@ public class InsertSingleColumn {
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'] ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand All @@ -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'] ");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand All @@ -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();


Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -29,7 +30,7 @@ public class ResultDetailsDemo {
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
Expand All @@ -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());
Expand Down
Loading

0 comments on commit f95d060

Please sign in to comment.