我对 astyanax 很陌生,我用谷歌搜索过,找不到插入复合列的简单示例。谁能提供一个简单的例子?例如复合列类型为 Long:Long:Long 为 123:122:233,值为字符串“测试字符串”。提前谢谢。
问问题
2205 次
2 回答
1
我会尝试下载源代码并查看单元测试。至少有一项测试可以证明这一点。查看源代码后,您就会明白为什么我推荐该路线而不是仅发布代码片段。它涵盖了相当数量。
于 2012-05-08T23:32:17.073 回答
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();
于 2012-05-29T10:17:08.897 回答