Mercurial > hg > Members > tatsuki > bbs
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/CassandraBulletinBoard.java @ 4:5acde010c6db
add jungle browsing system
author | tatsuki |
---|---|
date | Tue, 28 Jun 2016 19:45:55 +0900 |
parents | 64a72a7a0491 |
children |
comparison
equal
deleted
inserted
replaced
3:f3d30646c863 | 4:5acde010c6db |
---|---|
35 private final ConfigurableConsistencyLevel configurableConsistencyLevel = new ConfigurableConsistencyLevel(); | 35 private final ConfigurableConsistencyLevel configurableConsistencyLevel = new ConfigurableConsistencyLevel(); |
36 | 36 |
37 private static final String COLUMN_FAMILY_BOARD = "boards"; | 37 private static final String COLUMN_FAMILY_BOARD = "boards"; |
38 private final int REP_FACTOR; | 38 private final int REP_FACTOR; |
39 | 39 |
40 public CassandraBulletinBoard(String _clusterName,String _address,String _keyspaceName, HConsistencyLevel cLevel,int rep_factor ) | 40 public CassandraBulletinBoard(String _clusterName, String _address, String _keyspaceName, HConsistencyLevel cLevel, int rep_factor ) |
41 { | 41 { |
42 address = _address; | 42 address = _address; |
43 clusterName = _clusterName; | 43 clusterName = _clusterName; |
44 keyspace = _keyspaceName; | 44 keyspace = _keyspaceName; |
45 cluster = HFactory.getOrCreateCluster(clusterName,address); | 45 cluster = HFactory.getOrCreateCluster(clusterName,address); |
49 configurableConsistencyLevel.setWriteCfConsistencyLevels(clmap); | 49 configurableConsistencyLevel.setWriteCfConsistencyLevels(clmap); |
50 REP_FACTOR = rep_factor; | 50 REP_FACTOR = rep_factor; |
51 initialize(); | 51 initialize(); |
52 } | 52 } |
53 | 53 |
54 public CassandraBulletinBoard(String _clusterName,String _address,String _keyspaceName, HConsistencyLevel cLevel) | 54 public CassandraBulletinBoard(String _clusterName, String _address, String _keyspaceName, HConsistencyLevel cLevel) |
55 { | 55 { |
56 this(_clusterName, _address, _keyspaceName, cLevel, 1); | 56 this(_clusterName, _address, _keyspaceName, cLevel, 1); |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 | 60 |
61 private void initialize() | 61 private void initialize() |
62 { | 62 { |
63 if(cluster.describeKeyspace(keyspace) == null){ | 63 if(cluster.describeKeyspace(keyspace) == null){ |
64 KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition(keyspace, | 64 KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition(keyspace, |
65 SimpleStrategy.class.getName(),REP_FACTOR, Collections.<ColumnFamilyDefinition> emptyList()); | 65 SimpleStrategy.class.getName(),REP_FACTOR,Collections.<ColumnFamilyDefinition> emptyList()); |
66 cluster.addKeyspace(keyspaceDefinition,false); | 66 cluster.addKeyspace(keyspaceDefinition,false); |
67 ColumnFamilyDefinition columnFamilyDefinition = HFactory.createColumnFamilyDefinition(keyspace,COLUMN_FAMILY_BOARD,ComparatorType.UUIDTYPE); | 67 ColumnFamilyDefinition columnFamilyDefinition = HFactory.createColumnFamilyDefinition(keyspace,COLUMN_FAMILY_BOARD,ComparatorType.UUIDTYPE); |
68 columnFamilyDefinition.setColumnType(ColumnType.SUPER); | 68 columnFamilyDefinition.setColumnType(ColumnType.SUPER); |
69 cluster.addColumnFamily(columnFamilyDefinition); | 69 cluster.addColumnFamily(columnFamilyDefinition); |
70 } | 70 } |
96 private static final String COLUMN_MESSAGE_EDIT_KEY = "edit"; | 96 private static final String COLUMN_MESSAGE_EDIT_KEY = "edit"; |
97 | 97 |
98 public void createBoardMessage(UUID _time,String _name,String _author,String _message,String _editKey) | 98 public void createBoardMessage(UUID _time,String _name,String _author,String _message,String _editKey) |
99 { | 99 { |
100 Keyspace ksp = HFactory.createKeyspace(keyspace, cluster, configurableConsistencyLevel); | 100 Keyspace ksp = HFactory.createKeyspace(keyspace, cluster, configurableConsistencyLevel); |
101 ThriftSuperCfTemplate<String,UUID,String> template = | 101 ThriftSuperCfTemplate<String,UUID,String> template = |
102 new ThriftSuperCfTemplate<String,UUID,String>(ksp,COLUMN_FAMILY_BOARD,StringSerializer.get(), | 102 new ThriftSuperCfTemplate<String,UUID,String>(ksp,COLUMN_FAMILY_BOARD,StringSerializer.get(), |
103 UUIDSerializer.get(),StringSerializer.get()); | 103 UUIDSerializer.get(),StringSerializer.get()); |
104 | 104 |
105 SuperCfUpdater<String,UUID,String> updater = template.createUpdater(_name,_time); | 105 SuperCfUpdater<String,UUID,String> updater = template.createUpdater(_name,_time); |
106 updater.setString(COLUMN_MESSAGE_AUTHOR,_author); | 106 updater.setString(COLUMN_MESSAGE_AUTHOR,_author); |
180 | 180 |
181 public void editMessage(String _board,String _uuid,String _author,String _message,String _editKey) | 181 public void editMessage(String _board,String _uuid,String _author,String _message,String _editKey) |
182 { | 182 { |
183 Keyspace ksp = HFactory.createKeyspace(keyspace, cluster, configurableConsistencyLevel); | 183 Keyspace ksp = HFactory.createKeyspace(keyspace, cluster, configurableConsistencyLevel); |
184 UUID time = UUID.fromString(_uuid); | 184 UUID time = UUID.fromString(_uuid); |
185 ThriftSuperCfTemplate<String,UUID,String> template = | 185 ThriftSuperCfTemplate<String,UUID,String> template = |
186 new ThriftSuperCfTemplate<String,UUID,String>(ksp,COLUMN_FAMILY_BOARD,StringSerializer.get(), | 186 new ThriftSuperCfTemplate<String,UUID,String>(ksp,COLUMN_FAMILY_BOARD,StringSerializer.get(), |
187 UUIDSerializer.get(),StringSerializer.get()); | 187 UUIDSerializer.get(),StringSerializer.get()); |
188 | 188 |
189 SuperCfResult<String,UUID,String> result = template.querySuperColumn(_board,time); | 189 SuperCfResult<String,UUID,String> result = template.querySuperColumn(_board,time); |
190 String editKey = result.getString(COLUMN_MESSAGE_EDIT_KEY); | 190 String editKey = result.getString(COLUMN_MESSAGE_EDIT_KEY); |