Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/main/java/jungle/app/bbs/HectorSample.java @ 105:f9e29a52efd3
Move some files
author | one |
---|---|
date | Tue, 26 Nov 2013 06:43:10 +0900 |
parents | src/jungle/app/bbs/HectorSample.java@29127ac788a6 |
children |
comparison
equal
deleted
inserted
replaced
104:03bf62bb699e | 105:f9e29a52efd3 |
---|---|
1 package jungle.app.bbs; | |
2 | |
3 import java.util.List; | |
4 import java.util.UUID; | |
5 import me.prettyprint.cassandra.serializers.StringSerializer; | |
6 import me.prettyprint.cassandra.serializers.UUIDSerializer; | |
7 import me.prettyprint.cassandra.service.template.SuperCfUpdater; | |
8 import me.prettyprint.cassandra.service.template.ThriftSuperCfTemplate; | |
9 import me.prettyprint.cassandra.utils.TimeUUIDUtils; | |
10 import me.prettyprint.hector.api.*; | |
11 import me.prettyprint.hector.api.beans.HColumn; | |
12 import me.prettyprint.hector.api.beans.HSuperColumn; | |
13 import me.prettyprint.hector.api.beans.OrderedSuperRows; | |
14 import me.prettyprint.hector.api.beans.SuperRow; | |
15 import me.prettyprint.hector.api.beans.SuperSlice; | |
16 import me.prettyprint.hector.api.factory.HFactory; | |
17 import me.prettyprint.hector.api.query.QueryResult; | |
18 import me.prettyprint.hector.api.query.RangeSuperSlicesQuery; | |
19 import me.prettyprint.hector.api.query.SuperSliceQuery; | |
20 | |
21 public class HectorSample | |
22 { | |
23 public static void main(String _args[]) | |
24 { | |
25 Cluster myCluster = HFactory.getOrCreateCluster("test-cluster","localhost:9160"); | |
26 | |
27 Keyspace ksp = HFactory.createKeyspace("cassaBBS",myCluster); | |
28 /* | |
29 ColumnFamilyDefinition newCF = HFactory.createColumnFamilyDefinition("DEMO","ccc",ComparatorType.UUIDTYPE); | |
30 newCF.setColumnType(ColumnType.SUPER); | |
31 myCluster.addColumnFamily(newCF); | |
32 */ | |
33 | |
34 ThriftSuperCfTemplate<String,UUID,String> template = | |
35 new ThriftSuperCfTemplate<String,UUID,String>(ksp,"boards",StringSerializer.get(), | |
36 UUIDSerializer.get(),StringSerializer.get()); | |
37 UUID time = TimeUUIDUtils.getUniqueTimeUUIDinMillis(); | |
38 SuperCfUpdater<String,UUID,String> updater = template.createUpdater("board1",TimeUUIDUtils.getTimeUUID(0)); | |
39 updater.setString("name","peter"); | |
40 updater.setString("message",time.toString()); | |
41 | |
42 template.update(updater); | |
43 | |
44 UUID start = TimeUUIDUtils.getTimeUUID(0); | |
45 | |
46 SuperSliceQuery<String, UUID, String, String> sq = HFactory.createSuperSliceQuery(ksp, StringSerializer.get(), UUIDSerializer.get(), StringSerializer.get(), StringSerializer.get()); | |
47 sq.setKey("board1").setColumnFamily("ccc").setRange(start,null,false,100); | |
48 | |
49 QueryResult<SuperSlice<UUID,String,String>> results = sq.execute(); | |
50 | |
51 SuperSlice<UUID,String,String> ss = results.get(); | |
52 List<HSuperColumn<UUID,String,String>> list = ss.getSuperColumns(); | |
53 for(HSuperColumn<UUID,String,String> sc : list){ | |
54 HColumn<String,String> sub = sc.getSubColumnByName("name"); | |
55 System.out.println(sub.getValue()); | |
56 sub = sc.getSubColumnByName("message"); | |
57 System.out.println(sub.getValue()); | |
58 } | |
59 | |
60 RangeSuperSlicesQuery<String,UUID,String,String> rsq = HFactory.createRangeSuperSlicesQuery(ksp,StringSerializer.get(), | |
61 UUIDSerializer.get(),StringSerializer.get(),StringSerializer.get()); | |
62 rsq.setKeys(null,null).setRange(null,null,false,0).setColumnFamily("ccc"); | |
63 | |
64 QueryResult<OrderedSuperRows<String,UUID,String,String>> rsqResult = rsq.execute(); | |
65 OrderedSuperRows<String, UUID, String, String> rows = rsqResult.get(); | |
66 for(SuperRow<String, UUID, String, String> row : rows.getList()){ | |
67 System.out.println(row.getKey()); | |
68 } | |
69 } | |
70 } |