Astyanax:如何插入复合柱?

时间:2012-05-07 04:15:23

标签: cassandra

我对astyanax很新,我用google搜索,找不到插入复合列的简单示例。有谁可以提供一个简单的例子?例如,复合列类型为Long:Long:Long为123:122:233,值为字符串“test string”。谢谢你。

2 个答案:

答案 0 :(得分:1)

我会尝试下载源代码并查看单元测试。至少有一个测试证明了它。一旦你查看了源代码,你就会明白为什么我推荐这条路线而不只是发布一个代码片段。它涵盖了相当数量。

答案 1 :(得分:0)

试试这个:

//First you need an object.

// Annotated composite class
public class SessionEvent{
  @Component(ordinal=0) long sessiondId;
  @Component(ordinal=1) long timestamp;
  @Component(ordinal=2) long userId;

  // Must have public default constructor
  public SessionEvent() {
  }
  // ...
  // Don't forget to implement hashcode and equals and a constructor that accepts (long, long, long)

}

//... 
static AnnotatedCompositeSerializer<SessionEvent> eventSerializer
      = new AnnotatedCompositeSerializer<SessionEvent>(SessionEvent.class);
static ColumnFamily<String, SessionEvent> CF_SESSION_EVENTS
      = new ColumnFamily<String, SessionEvent>("SessionEvents",
            StringSerializer.get(), eventSerializer);

//...           
CompositeColumn cc = new SessionEvent("123","456","789"); // Column values  
keyspace.prepareColumnMutation(CF_SESSION_EVENTS, "row key goes here", cc)
    .putValue("this is the value", null)
    .execute();