2015-02-06 119 views
1

我正在研究使用spring-data-cassandra的CassandraOperations更新cassandra表内集合的示例。 请分享,因为我很难找到正确的。此外,它无法通过网络。如何使用CassandraOperations更新集合

感谢

UPDATE

我看着弹簧数据Cassandra的code.Currently它们只提供选件可以通过它们的更新操作替换集合。我将着眼于扩展并提供用于收集升级的API

回答

0

这是一个使用CQL3的自包含示例。使用java cassandra驱动程序将其移植到Spring应该不复杂。

cqlsh> CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1 }; 
cqlsh> CREATE COLUMNFAMILY test.example (name text PRIMARY KEY, emails list<text>); 
cqlsh> UPDATE test.example SET emails = ['[email protected]'] where name='lyuben'; 
cqlsh> SELECT * FROM test.example; 

name | emails 
--------+------------------- 
lyuben | ['[email protected]'] 

(1 rows) 
cqlsh> UPDATE test.example SET emails = ['[email protected]'] + emails where name='lyuben'; 
cqlsh> SELECT * FROM test.example;            
name | emails 
--------+----------------------------------- 
lyuben | ['[email protected]', '[email protected]'] 

(1 rows) 
cqlsh> UPDATE test.example SET emails = emails + ['[email protected]'] where name='lyuben'; 
cqlsh> SELECT * FROM test.example;            
name | emails 
--------+----------------------------------------------------- 
lyuben | ['[email protected]', '[email protected]', '[email protected]'] 

(1 rows) 

DOCS here这里有一些在other collections

唯一要注意的一点是,它的确与众不同无论你在声明的开头或末尾添加新集合元素:

// post-append 
['[email protected]'] + emails 
['[email protected]', '[email protected]'] 
// pre-append 
emails = emails + ['[email protected]'] 
['[email protected]', '[email protected]', '[email protected]'] 
+0

感谢Lyuben,我懂得了通过datastax的Java实现驱动程序以及cql,但我正在寻找spring-data-cassandra内的东西。原来支持还没有。 – 2015-02-07 10:36:16