/
GetSliceForAreaCodeCity.java
35 lines (28 loc) · 1.08 KB
/
GetSliceForAreaCodeCity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.datastax.tutorial;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.ColumnSlice;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.SliceQuery;
/**
* A get_slice query showing off 'limit' of columns for a given key.
*
* @author zznate
*
*/
public class GetSliceForAreaCodeCity extends TutorialCommand {
public GetSliceForAreaCodeCity(Keyspace keyspace) {
super(keyspace);
}
@Override
public QueryResult<ColumnSlice<String,String>> execute() {
SliceQuery<String, String, String> sliceQuery =
HFactory.createSliceQuery(keyspace, stringSerializer, stringSerializer, stringSerializer);
sliceQuery.setColumnFamily("AreaCode");
sliceQuery.setKey("512");
// change the order argument to 'true' to get the last 2 columns in descending order
sliceQuery.setRange("", "", false, 2);
QueryResult<ColumnSlice<String, String>> result = sliceQuery.execute();
return result;
}
}