Mercurial > hg > Members > tatsuki > bbs
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/HectorSample.java @ 1:64a72a7a0491
add local bbs
author | tatsuki |
---|---|
date | Mon, 27 Jun 2016 04:24:25 +0900 |
parents | |
children | 5acde010c6db |
comparison
equal
deleted
inserted
replaced
0:d04e3e9069aa | 1:64a72a7a0491 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.bbs.local; | |
2 | |
3 import me.prettyprint.cassandra.serializers.StringSerializer; | |
4 import me.prettyprint.cassandra.serializers.UUIDSerializer; | |
5 import me.prettyprint.cassandra.service.template.SuperCfUpdater; | |
6 import me.prettyprint.cassandra.service.template.ThriftSuperCfTemplate; | |
7 import me.prettyprint.cassandra.utils.TimeUUIDUtils; | |
8 import me.prettyprint.hector.api.*; | |
9 import me.prettyprint.hector.api.beans.*; | |
10 import me.prettyprint.hector.api.factory.HFactory; | |
11 import me.prettyprint.hector.api.query.QueryResult; | |
12 import me.prettyprint.hector.api.query.RangeSuperSlicesQuery; | |
13 import me.prettyprint.hector.api.query.SuperSliceQuery; | |
14 | |
15 import java.util.List; | |
16 import java.util.UUID; | |
17 | |
18 public class HectorSample | |
19 { | |
20 public static void main(String _args[]) | |
21 { | |
22 Cluster myCluster = HFactory.getOrCreateCluster("test-cluster","localhost:9160"); | |
23 | |
24 Keyspace ksp = HFactory.createKeyspace("cassaBBS",myCluster); | |
25 | |
26 ThriftSuperCfTemplate<String,UUID,String> template = | |
27 new ThriftSuperCfTemplate<String,UUID,String>(ksp,"boards",StringSerializer.get(), | |
28 UUIDSerializer.get(),StringSerializer.get()); | |
29 UUID time = TimeUUIDUtils.getUniqueTimeUUIDinMillis(); | |
30 SuperCfUpdater<String,UUID,String> updater = template.createUpdater("board1",TimeUUIDUtils.getTimeUUID(0)); | |
31 updater.setString("name","peter"); | |
32 updater.setString("message",time.toString()); | |
33 | |
34 template.update(updater); | |
35 | |
36 UUID start = TimeUUIDUtils.getTimeUUID(0); | |
37 | |
38 SuperSliceQuery<String, UUID, String, String> sq = HFactory.createSuperSliceQuery(ksp, StringSerializer.get(), UUIDSerializer.get(), StringSerializer.get(), StringSerializer.get()); | |
39 sq.setKey("board1").setColumnFamily("ccc").setRange(start,null,false,100); | |
40 | |
41 QueryResult<SuperSlice<UUID,String,String>> results = sq.execute(); | |
42 | |
43 SuperSlice<UUID,String,String> ss = results.get(); | |
44 List<HSuperColumn<UUID,String,String>> list = ss.getSuperColumns(); | |
45 for(HSuperColumn<UUID,String,String> sc : list){ | |
46 HColumn<String,String> sub = sc.getSubColumnByName("name"); | |
47 System.out.println(sub.getValue()); | |
48 sub = sc.getSubColumnByName("message"); | |
49 System.out.println(sub.getValue()); | |
50 } | |
51 | |
52 RangeSuperSlicesQuery<String,UUID,String,String> rsq = HFactory.createRangeSuperSlicesQuery(ksp,StringSerializer.get(), | |
53 UUIDSerializer.get(),StringSerializer.get(),StringSerializer.get()); | |
54 rsq.setKeys(null,null).setRange(null,null,false,0).setColumnFamily("ccc"); | |
55 | |
56 QueryResult<OrderedSuperRows<String,UUID,String,String>> rsqResult = rsq.execute(); | |
57 OrderedSuperRows<String, UUID, String, String> rows = rsqResult.get(); | |
58 for(SuperRow<String, UUID, String, String> row : rows.getList()){ | |
59 System.out.println(row.getKey()); | |
60 } | |
61 } | |
62 } |