Permalink
Browse files

Updated to latest Cassandra trunk

  • Loading branch information...
1 parent f588645 commit 72348958538114d196a76d4bc1ff7e0e62c8ec05 @johanoskarsson johanoskarsson committed May 22, 2010
Showing with 55 additions and 11 deletions.
  1. +55 −11 db/cassandra-0.7/src/com/yahoo/ycsb/db/CassandraClient7.java
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.HashSet;
@@ -140,6 +141,15 @@ public void cleanup() throws DBException
public int read(String table, String key, Set<String> fields, HashMap<String, String> result)
{
Exception errorexception = null;
+ try
+ {
+ client.set_keyspace(table);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ e.printStackTrace(System.out);
+ return Error;
+ }
for (int i = 0; i < OperationRetries; i++)
{
@@ -171,7 +181,7 @@ public int read(String table, String key, Set<String> fields, HashMap<String, St
}
ColumnParent parent = new ColumnParent("data");
- List<ColumnOrSuperColumn> results = client.get_slice(table, key.getBytes("UTF-8"), parent, predicate,
+ List<ColumnOrSuperColumn> results = client.get_slice(key.getBytes("UTF-8"), parent, predicate,
ConsistencyLevel.ONE);
if (_debug)
@@ -236,6 +246,16 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
{
Exception errorexception = null;
+ try
+ {
+ client.set_keyspace(table);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ e.printStackTrace(System.out);
+ return Error;
+ }
+
for (int i = 0; i < OperationRetries; i++)
{
@@ -261,9 +281,9 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
predicate.setColumn_names(fieldlist);
}
ColumnParent parent = new ColumnParent("data");
+ KeyRange kr = new KeyRange().setStart_key(startkey.getBytes("UTF-8")).setEnd_key(new byte[] {}).setCount(recordcount);
- List<KeySlice> results = client.get_range_slice(table, parent, predicate, startkey.getBytes("UTF-8"), new byte[] {},
- recordcount, ConsistencyLevel.ONE);
+ List<KeySlice> results = client.get_range_slices(parent, predicate, kr, ConsistencyLevel.ONE);
if (_debug)
{
@@ -345,29 +365,43 @@ public int insert(String table, String key, HashMap<String, String> values)
{
Exception errorexception = null;
+ try
+ {
+ client.set_keyspace(table);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ e.printStackTrace(System.out);
+ return Error;
+ }
+
for (int i = 0; i < OperationRetries; i++)
{
// insert data
long timestamp = System.currentTimeMillis();
- HashMap<String, List<ColumnOrSuperColumn>> batch_mutation = new HashMap<String, List<ColumnOrSuperColumn>>();
- ArrayList<ColumnOrSuperColumn> v = new ArrayList<ColumnOrSuperColumn>(values.size());
- batch_mutation.put("data", v);
-
try
{
- for (String field : values.keySet())
+ Map<byte[], Map<String, List<Mutation>>> batch_mutation = new HashMap<byte[], Map<String, List<Mutation>>>();
+ ArrayList<Mutation> v = new ArrayList<Mutation>(values.size());
+ Map<String, List<Mutation>> cfMutationMap = new HashMap<String, List<Mutation>>();
+ cfMutationMap.put("data", v);
+ batch_mutation.put(key.getBytes("UTF-8"), cfMutationMap);
+
+ for (String field : values.keySet())
{
String val = values.get(field);
Column col = new Column(field.getBytes("UTF-8"), val.getBytes("UTF-8"), timestamp);
ColumnOrSuperColumn c = new ColumnOrSuperColumn();
c.setColumn(col);
c.unsetSuper_column();
- v.add(c);
+ Mutation m = new Mutation();
+ m.setColumn_or_supercolumn(c);
+ v.add(m);
}
- client.batch_insert(table, key.getBytes("UTF-8"), batch_mutation, ConsistencyLevel.ONE);
+ client.batch_mutate(batch_mutation, ConsistencyLevel.ONE);
if (_debug)
{
@@ -405,11 +439,21 @@ public int delete(String table, String key)
{
Exception errorexception = null;
+ try
+ {
+ client.set_keyspace(table);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ e.printStackTrace(System.out);
+ return Error;
+ }
+
for (int i = 0; i < OperationRetries; i++)
{
try
{
- client.remove(table, key.getBytes("UTF-8"), new ColumnPath("data"), System.currentTimeMillis(),
+ client.remove(key.getBytes("UTF-8"), new ColumnPath("data"), System.currentTimeMillis(),
ConsistencyLevel.ONE);
if (_debug)

0 comments on commit 7234895

Please sign in to comment.