Java Code Examples for com.netflix.astyanax.util.RangeBuilder#setReversed()

The following examples show how to use com.netflix.astyanax.util.RangeBuilder#setReversed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AstyanaxThriftDataTableResource.java    From staash with Apache License 2.0 4 votes vote down vote up
@Override
public QueryResult readRow(String key, Integer columnCount, String startColumn, String endColumn, Boolean reversed) throws PaasException {
    invariant();
    
    try {
        // Construct the query
        RowQuery<ByteBuffer, ByteBuffer> query = keyspace
                .prepareQuery(this.columnFamily)
                .getRow(serializers.keyAsByteBuffer(key));
                
        RangeBuilder range = new RangeBuilder();
        if (columnCount != null && columnCount > 0) {
            range.setLimit(columnCount);
        }
        if (startColumn != null && !startColumn.isEmpty()) {
            range.setStart(serializers.columnAsByteBuffer(startColumn));
        }
        if (endColumn != null && !endColumn.isEmpty()) {
            range.setEnd(serializers.columnAsByteBuffer(endColumn));
        }
        range.setReversed(reversed);
        query.withColumnRange(range.build());

        // Execute the query
        ColumnList<ByteBuffer> result = query.execute().getResult();
        
        // Convert raw data into a simple sparse tree
        SchemalessRows.Builder builder = SchemalessRows.builder();
        Map<String, String> columns = Maps.newHashMap();
        if (!result.isEmpty()) {
            for (Column<ByteBuffer> column : result) { 
                columns.put(serializers.columnAsString(column.getRawName()), serializers.valueAsString(column.getRawName(), column.getByteBufferValue()));
            }
            builder.addRow(key, columns);
        }

        QueryResult dr = new QueryResult();
        dr.setSrows(builder.build());
        return dr;
    } catch (ConnectionException e) {
        throw new PaasException(
                String.format("Failed to read row '%s' in column family '%s.%s'" , 
                              key, this.keyspace.getKeyspaceName(), this.columnFamily.getName()),
                e);
    }
}
 
Example 2
Source File: EdgeSearcher.java    From usergrid with Apache License 2.0 3 votes vote down vote up
private void setRangeOptions(final RangeBuilder rangeBuilder){

        //if we're ascending, this is opposite what cassandra sorts, so set the reversed flag
        final boolean reversed = order == SearchByEdgeType.Order.ASCENDING;

        rangeBuilder.setReversed( reversed );

    }