com.netflix.astyanax.cql.reads.model.CqlRowImpl Maven / Gradle / Ivy
package com.netflix.astyanax.cql.reads.model;
import java.nio.ByteBuffer;
import java.util.List;
import com.datastax.driver.core.ResultSet;
import com.netflix.astyanax.cql.util.CqlTypeMapping;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.ColumnList;
import com.netflix.astyanax.model.Row;
/**
* Impl for {@link Row} that parses the {@link ResultSet} from java driver and translates back to Astyanax Row.
* Note that if your schema has a clustering key, then each individual row from the result set is a unique column,
* and all result set rows with the same partition key map to a unique Astyanax row.
*
* @author poberai
*
* @param
* @param
*/
@SuppressWarnings("unchecked")
public class CqlRowImpl implements Row {
private final K rowKey;
private final CqlColumnListImpl cqlColumnList;
private final ColumnFamily cf;
public CqlRowImpl(com.datastax.driver.core.Row resultRow, ColumnFamily cf) {
this.rowKey = (K) getRowKey(resultRow, cf);
this.cqlColumnList = new CqlColumnListImpl(resultRow, cf);
this.cf = cf;
}
public CqlRowImpl(List rows, ColumnFamily cf) {
this.rowKey = (K) getRowKey(rows.get(0), cf);
this.cqlColumnList = new CqlColumnListImpl(rows, cf);
this.cf = cf;
}
public CqlRowImpl(K rKey, CqlColumnListImpl colList, ColumnFamily columnFamily) {
this.rowKey = rKey;
this.cqlColumnList = colList;
this.cf = columnFamily;
}
@Override
public K getKey() {
return rowKey;
}
@Override
public ByteBuffer getRawKey() {
return cf.getKeySerializer().toByteBuffer(rowKey);
}
@Override
public ColumnList getColumns() {
return cqlColumnList;
}
private Object getRowKey(com.datastax.driver.core.Row row, ColumnFamily cf) {
return CqlTypeMapping.getDynamicColumn(row, cf.getKeySerializer(), 0, cf);
}
}