use of com.netflix.astyanax.model.ByteBufferRange in project coprhd-controller by CoprHD.
the class DbClientImpl method scanRowsByType.
private <T extends DataObject> Iterable<Row<String, CompositeColumnName>> scanRowsByType(Class<T> clazz, Boolean inactiveValue, URI startId, int count) {
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
try {
ColumnFamily<String, CompositeColumnName> cf = doType.getCF();
Keyspace ks = getKeyspace(clazz);
ColumnFamilyQuery<String, CompositeColumnName> query = ks.prepareQuery(cf);
// Column filter, get only last .inactive column, or get any column
ByteBufferRange columnRange = inactiveValue == null ? CompositeColumnNameSerializer.get().buildRange().limit(1).build() : CompositeColumnNameSerializer.get().buildRange().greaterThanEquals(DataObject.INACTIVE_FIELD_NAME).lessThanEquals(DataObject.INACTIVE_FIELD_NAME).reverse().limit(1).build();
Execution<Rows<String, CompositeColumnName>> exec;
if (count == Integer.MAX_VALUE) {
exec = query.getAllRows().withColumnRange(columnRange);
} else {
Partitioner partitioner = ks.getPartitioner();
String strKey = startId != null ? startId.toString() : null;
String startToken = strKey != null ? partitioner.getTokenForKey(cf.getKeySerializer().toByteBuffer(strKey)) : partitioner.getMinToken();
exec = query.getRowRange(strKey, null, startToken, partitioner.getMaxToken(), count).withColumnRange(columnRange);
}
return exec.execute().getResult();
} catch (ConnectionException e) {
throw DatabaseException.retryables.connectionFailed(e);
}
}
Aggregations