41
|
1 package treecms.proto.cassandra.test;
|
|
2
|
|
3 import java.util.List;
|
|
4
|
|
5 import org.apache.cassandra.thrift.Cassandra;
|
|
6 import org.apache.cassandra.thrift.ColumnOrSuperColumn;
|
|
7 import org.apache.cassandra.thrift.ColumnParent;
|
|
8 import org.apache.cassandra.thrift.ColumnPath;
|
|
9 import org.apache.cassandra.thrift.ConsistencyLevel;
|
|
10 import org.apache.cassandra.thrift.InvalidRequestException;
|
|
11 import org.apache.cassandra.thrift.KeySlice;
|
|
12 import org.apache.cassandra.thrift.NotFoundException;
|
|
13 import org.apache.cassandra.thrift.SlicePredicate;
|
|
14 import org.apache.cassandra.thrift.SliceRange;
|
|
15 import org.apache.cassandra.thrift.TimedOutException;
|
|
16 import org.apache.cassandra.thrift.UnavailableException;
|
|
17 import org.apache.thrift.TException;
|
|
18 import org.apache.thrift.protocol.TBinaryProtocol;
|
|
19 import org.apache.thrift.protocol.TProtocol;
|
|
20 import org.apache.thrift.transport.TSocket;
|
|
21 import org.apache.thrift.transport.TTransport;
|
|
22
|
|
23 public class CassGetSliceTest
|
|
24 {
|
|
25 public static void main(String _args[])throws Exception
|
|
26 {
|
|
27 Cassandra.Client client;
|
|
28
|
|
29 String host = "localhost";
|
|
30 int port = 9160;
|
|
31
|
|
32 TTransport tr = new TSocket(host,port);
|
|
33 TProtocol proto = new TBinaryProtocol(tr);
|
|
34 client = new Cassandra.Client(proto);
|
|
35
|
|
36 tr.open();
|
|
37
|
|
38 System.out.println("ClusterName = "+client.describe_cluster_name());
|
|
39 testGetRangeSlice(client);
|
|
40
|
|
41 tr.close();
|
|
42 }
|
|
43
|
|
44 public static void testGet(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException
|
|
45 {
|
|
46 ColumnPath path = new ColumnPath();
|
|
47 path.column_family = "TreeCMSCF01";
|
|
48 path.column = "value".getBytes();
|
|
49
|
|
50 ColumnOrSuperColumn value = _client.get("TreeCMSKS","uuid@01",path,ConsistencyLevel.ONE);
|
|
51
|
|
52 System.out.println(new String(value.column.getValue()));
|
|
53 }
|
|
54
|
|
55 public static void testGetSlice(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException
|
|
56 {
|
|
57 SliceRange sliceRange = new SliceRange();
|
|
58 sliceRange.setStart(new byte[0]);
|
|
59 sliceRange.setFinish(new byte[0]);
|
|
60
|
|
61 SlicePredicate slicePredicate = new SlicePredicate();
|
|
62 slicePredicate.setSlice_range(sliceRange);
|
|
63
|
|
64 List<ColumnOrSuperColumn> values = _client.get_slice("TreeCMSKS","uuid@01",new ColumnParent("TreeCMSCF01"),slicePredicate,ConsistencyLevel.ONE);
|
|
65
|
|
66 for(ColumnOrSuperColumn value : values){
|
|
67 System.out.println(new String(value.column.getName())+":"+new String(value.column.getValue()));
|
|
68 }
|
|
69 }
|
|
70
|
|
71 public static void testGetRangeSlice(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException
|
|
72 {
|
|
73 SliceRange sliceRange = new SliceRange();
|
|
74 sliceRange.setStart(new byte[0]);
|
|
75 sliceRange.setFinish(new byte[0]);
|
|
76
|
|
77 SlicePredicate slicePredicate = new SlicePredicate();
|
|
78 slicePredicate.setSlice_range(sliceRange);
|
|
79
|
|
80 List<KeySlice> values = _client.get_range_slice("TreeCMSKS",new ColumnParent("TreeCMSCF02"),slicePredicate,"hogehoge","hogehogea",100,ConsistencyLevel.ONE);
|
|
81
|
|
82 for(KeySlice key : values){
|
|
83 System.out.println(new String(key.getKey()));
|
|
84 for(ColumnOrSuperColumn column : key.getColumns()){
|
|
85 System.out.println("\t"+new String(column.column.getName())+":"+new String(column.column.getValue()));
|
|
86 }
|
|
87 }
|
|
88 }
|
|
89 }
|