forked from hector-client/hector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractSubColumnQuery.java
executable file
·69 lines (58 loc) · 2.2 KB
/
AbstractSubColumnQuery.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
package me.prettyprint.cassandra.model;
import java.util.List;
import me.prettyprint.cassandra.utils.Assert;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hector.api.beans.ColumnSlice;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.SubColumnQuery;
import me.prettyprint.hector.api.query.SubSliceQuery;
public class AbstractSubColumnQuery<K, SN, N, V> implements SubColumnQuery<K, SN, N, V>{
protected final SubSliceQuery<K, SN,N,V> subSliceQuery;
public AbstractSubColumnQuery(Keyspace keyspace,
Serializer<K> keySerializer,
Serializer<SN> sNameSerializer,
Serializer<N> nameSerializer,
Serializer<V> valueSerializer) {
subSliceQuery = HFactory.createSubSliceQuery(keyspace, keySerializer, sNameSerializer, nameSerializer,
valueSerializer);
}
@Override
public SubColumnQuery<K, SN, N, V> setKey(K key) {
subSliceQuery.setKey(key);
return this;
}
@Override
public SubColumnQuery<K, SN, N, V> setSuperColumn(SN superName) {
subSliceQuery.setSuperColumn(superName);
return this;
}
@Override
@SuppressWarnings("unchecked")
public SubColumnQuery<K, SN, N, V> setColumn(N columnName) {
subSliceQuery.setColumnNames(columnName);
return this;
}
@Override
public String toString() {
return "SubColumnQuery(" + subSliceQuery + ")";
}
@Override
public SubColumnQuery<K, SN, N, V> setColumnFamily(String cf) {
subSliceQuery.setColumnFamily(cf);
return this;
}
@Override
public QueryResult<HColumn<N, V>> execute() {
Assert.isTrue(subSliceQuery.getColumnNames().size() == 1,
"There should be exactly one column name set. Call setColumn");
QueryResult<ColumnSlice<N, V>> r = subSliceQuery.execute();
ColumnSlice<N, V> slice = r.get();
List<HColumn<N,V>> columns = slice.getColumns();
HColumn<N, V> column = columns.size() == 0 ? null : columns.get(0);
return new QueryResultImpl<HColumn<N,V>>(
new ExecutionResult<HColumn<N,V>>(column, r.getExecutionTimeNano(), r.getHostUsed()), this);
}
}