2012-05-07 68 views
0

我對astyanax非常陌生,我已經使用了Google搜索功能,並且找不到插入複合列的簡單示例。誰能提供一個簡單的例子?例如複合列類型爲Long:Long:Long爲123:122:233,值爲字符串「test string」。謝謝。Astyanax:如何插入複合列?

回答

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();