Retrieving data from a Composite column

48 views
Skip to first unread message

Shane Perry

unread,
Aug 15, 2011, 3:04:09 PM8/15/11
to hector...@googlegroups.com
Using the below code it appears I can not use the instantiated
Composite object "column" to retrieve the value from a query.
Instead, I have to iterate over the columns to find the one I am
after. This is a simplified example, but my CF defines some columns
with multiple components while other columns only have one component.
Using a debugger, I can see that the "column" object contains one
element of type String while the query result returns a Composite with
an element of type HeapByteBuffer. Is there a simple conversion I
should be doing to retrieve the value?

Any help or direction would be appreciated. I also have a complete
unit test if that would be more helpful.

=================== Code snippet =====================

Composite column = new Composite("column"); // Debugger shows the
Composite as containing one element: type String
ColumnFamilyTemplate<String, Composite> template = ...

ColumnFamilyUpdater<String, Composite> updater = template.createUpdater("key");
updater.setString(column, "value");
template.update(updater);

ColumnFamilyResult<String, Composite> result = template.queryColumns("key");
if (result.hasResults()) {
String value = result.getString(column);
if(value != null) {
// value is null, so this block is unreachable
System.out.println("Found: " + value);
} else {
for(Composite c : result.getColumnNames()) {
// Debugger shows the Composite as containing one element: type
HeapByteBuffer
System.out.println("Lookup: " + result.getString(c));
}
}
}

Reply all
Reply to author
Forward
0 new messages