如何使用astyanax的静态列

时间:2014-09-03 15:41:44

标签: cassandra astyanax

有没有办法使用Astyanax创建和使用以下列族:

CREATE TABLE mytest ( id text, subid text, clustering text, static_value text static, value text, PRIMARY KEY((id, subid), clustering));

如果没有,静态列的最佳选择是什么?

1 个答案:

答案 0 :(得分:0)

Astyanax Getting Started部分包含一个部分,介绍如何通过使用"序数"来标记关键字段来确保正确的序列化。关键字:

// Annotated composite class
Class SessionEvent{
  private @Component(ordinal=0) String   sessiondId;
  private @Component(ordinal=1) UUID timestamp;

  public SessionEvent() {
  }

  public int hashCode() { ... }
  public boolean equals(Object o) { ... }
  public int compareTo(Object o) { ... }
}

否则,Astyanax回购也有an example showing how to work directly with CQL3。创建你的CF:

String CREATE_STATEMENT = "CREATE TABLE mytest ( id text, subid text, clustering text, static_value text static, value text, PRIMARY KEY((id, subid), clustering))";

try {
  @SuppressWarnings("unused")
  OperationResult<CqlResult<Integer, String>> result = keyspace
      .prepareQuery(EMP_CF)
      .withCql(CREATE_STATEMENT)
      .execute();
} catch (ConnectionException e) {
  logger.error("failed to create CF", e);
  throw new RuntimeException("failed to create CF", e);
}

上面的(CQL3)链接还包含演示读取和插入的示例方法。

相关问题