Search in sources :

Example 1 with ByteBufferRange

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);
    }
}
Also used : Keyspace(com.netflix.astyanax.Keyspace) ByteBufferRange(com.netflix.astyanax.model.ByteBufferRange) Partitioner(com.netflix.astyanax.partitioner.Partitioner) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) Rows(com.netflix.astyanax.model.Rows)

Aggregations

Keyspace (com.netflix.astyanax.Keyspace)1 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)1 ByteBufferRange (com.netflix.astyanax.model.ByteBufferRange)1 Rows (com.netflix.astyanax.model.Rows)1 Partitioner (com.netflix.astyanax.partitioner.Partitioner)1