Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
better chaining support for IndexedSlicesQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
zznate committed Nov 4, 2010
1 parent 3b63e40 commit 51129d5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
@@ -1,5 +1,6 @@
package me.prettyprint.cassandra.model;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -9,6 +10,7 @@
import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hector.api.beans.OrderedRows;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.query.Query;
import me.prettyprint.hector.api.query.QueryResult;

import org.apache.cassandra.thrift.Column;
Expand Down Expand Up @@ -74,13 +76,46 @@ public IndexedSlicesQuery<K,N,V> addGtExpression(N columnName, V columnValue) {
IndexOperator.GT,
valueSerializer.toByteBuffer(columnValue)));
return this;
}

@SuppressWarnings("unchecked")
@Override
public IndexedSlicesQuery<K, N, V> setColumnNames(Collection<N> columnNames) {
super.setColumnNames(columnNames);
return this;
}

@SuppressWarnings("unchecked")
@Override
public IndexedSlicesQuery<K, N, V> setColumnNames(N... columnNames) {
super.setColumnNames(columnNames);
return this;
}

@SuppressWarnings("unchecked")
@Override
public IndexedSlicesQuery<K, N, V> setRange(N start, N finish,
boolean reversed, int count) {
super.setRange(start, finish, reversed, count);
return this;
}

@SuppressWarnings("unchecked")
@Override
public IndexedSlicesQuery<K, N, V> setReturnKeysOnly() {
super.setReturnKeysOnly();
return this;
}

public IndexedSlicesQuery<K,N,V> setStartKey(K startKey) {
indexClause.setStart_key(keySerializer.toByteBuffer(startKey));
return this;
}

@Override
public IndexedSlicesQuery<K,N,V> setColumnFamily(String cf) {
super.setColumnFamily(cf);
return this;
}

@Override
Expand Down
Expand Up @@ -70,14 +70,15 @@ public void testInsertGetRemove() {
@Test
public void testMultiClause() {

IndexedSlicesQuery<String, String, Long> indexedSlicesQuery = new IndexedSlicesQuery<String, String, Long>(keyspace, se, se, le);
indexedSlicesQuery.addEqualsExpression("birthyear", 1975L);
indexedSlicesQuery.addGteExpression("birthmonth", 4L);
indexedSlicesQuery.addLteExpression("birthmonth", 6L);
indexedSlicesQuery.setColumnNames("birthyear");
indexedSlicesQuery.setColumnFamily(cf);
indexedSlicesQuery.setStartKey("");
QueryResult<OrderedRows<String, String, Long>> result = indexedSlicesQuery.execute();
QueryResult<OrderedRows<String, String, Long>> result =
new IndexedSlicesQuery<String, String, Long>(keyspace, se, se, le)
.addEqualsExpression("birthyear", 1975L)
.addGteExpression("birthmonth", 4L)
.addLteExpression("birthmonth", 6L)
.setColumnNames("birthyear")
.setColumnFamily(cf)
.setStartKey("")
.execute();
assertEquals(3, result.get().getList().size());


Expand Down

0 comments on commit 51129d5

Please sign in to comment.