forked from hector-client/hector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThriftSuperSliceQuery.java
executable file
·91 lines (78 loc) · 3.1 KB
/
ThriftSuperSliceQuery.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package me.prettyprint.cassandra.model.thrift;
import java.util.List;
import me.prettyprint.cassandra.model.AbstractSliceQuery;
import me.prettyprint.cassandra.model.KeyspaceOperationCallback;
import me.prettyprint.cassandra.model.QueryResultImpl;
import me.prettyprint.cassandra.model.SuperSliceImpl;
import me.prettyprint.cassandra.service.KeyspaceService;
import me.prettyprint.cassandra.utils.Assert;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hector.api.beans.SuperSlice;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.SuperSliceQuery;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.SuperColumn;
/**
* A query for the thrift call get_slice.
* <p>
* Get a slice of super columns from a super column family.
*
* @author Ran Tavory
*
* @param <N>
* @param <V>
*/
public final class ThriftSuperSliceQuery<K, SN, N, V> extends
AbstractSliceQuery<K, SN, V, SuperSlice<SN, N, V>> implements SuperSliceQuery<K, SN, N, V> {
private K key;
private final Serializer<N> nameSerializer;
public ThriftSuperSliceQuery(Keyspace keyspace,
Serializer<K> keySerializer,
Serializer<SN> sNameSerializer,
Serializer<N> nameSerializer,
Serializer<V> valueSerializer) {
super(keyspace, keySerializer, sNameSerializer, valueSerializer);
Assert.notNull(sNameSerializer, "sNameSerializer cannot be null");
this.nameSerializer = nameSerializer;
}
@Override
public SuperSliceQuery<K, SN, N, V> setKey(K key) {
this.key = key;
return this;
}
@Override
public QueryResult<SuperSlice<SN, N, V>> execute() {
return new QueryResultImpl<SuperSlice<SN,N,V>>(keyspace.doExecute(
new KeyspaceOperationCallback<SuperSlice<SN,N,V>>() {
@Override
public SuperSlice<SN, N, V> doInKeyspace(KeyspaceService ks) throws HectorException {
ColumnParent columnParent = new ColumnParent(columnFamilyName);
List<SuperColumn> thriftRet = ks.getSuperSlice(keySerializer.toByteBuffer(key),
columnParent, getPredicate());
return new SuperSliceImpl<SN, N, V>(thriftRet, columnNameSerializer, nameSerializer,
valueSerializer);
}
}), this);
}
@Override
public String toString() {
return "SuperSliceQuery(" + key + "," + toStringInternal() + ")";
}
@SuppressWarnings("unchecked")
@Override
public SuperSliceQuery<K, SN, N, V> setColumnNames(SN... columnNames) {
return (SuperSliceQuery<K, SN, N, V>) super.setColumnNames(columnNames);
}
@SuppressWarnings("unchecked")
@Override
public SuperSliceQuery<K, SN, N, V> setRange(SN start, SN finish, boolean reversed, int count) {
return (SuperSliceQuery<K, SN, N, V>) super.setRange(start, finish, reversed, count);
}
@SuppressWarnings("unchecked")
@Override
public SuperSliceQuery<K, SN, N, V> setColumnFamily(String cf) {
return (SuperSliceQuery<K, SN, N, V>) super.setColumnFamily(cf);
}
}