2012-05-07 1 views
0

私はastyanaxにとって非常に新しいです、私はグーグルで、コンポジット列を挿入する簡単な例を見つけることができませんでした。誰かが簡単な例を提供できますか?たとえば、複合列タイプはLong:Long:Longは123:122:233、stringは "test string"です。先にありがとう。Astyanax:複合カラムを挿入する方法は?

答えて

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(); 
関連する問題