2015-02-06 118 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