Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package me.prettyprint.cassandra.model;
  
  import java.util.List;
  import java.util.Map;
  
 
Uses new secondary indexes. Your CF must be configured for such to use this. The following creates an Indexed CF with the "birthday" column indexed (where birthdate represents a timestamp as it is validated by the LongType):
         - name: Indexed1
           column_metadata:
             - name: birthdate
               validator_class: LongType
               index_type: KEYS

Author(s):
zznate (nate@riptano.com)
 
 public class IndexedSlicesQuery<K,N,V> extends AbstractSliceQuery<K,N,V,OrderedRows<K,N,V>> {
 
   private final IndexClause indexClause;
 
   public IndexedSlicesQuery(Keyspace kSerializer<K> keySerializer,
       Serializer<N> nameSerializerSerializer<V> valueSerializer) {
     super(kkeySerializernameSerializervalueSerializer);
      = new IndexClause();
   }
 
   public IndexedSlicesQuery<K,N,V> addEqualsExpression(N columnName, V columnValue) {
         .,
         .toByteBuffer(columnValue)));
     return this;
   }
 
   public IndexedSlicesQuery<K,N,V> addLteExpression(N columnName, V columnValue) {
         .,
         .toByteBuffer(columnValue)));
     return this;
   }
 
   public IndexedSlicesQuery<K,N,V> addGteExpression(N columnName, V columnValue) {
         .,
         .toByteBuffer(columnValue)));
     return this;
   }
 
   public IndexedSlicesQuery<K,N,V> addLtExpression(N columnName, V columnValue) {
         .,
         .toByteBuffer(columnValue)));
     return this;
   }
 
   public IndexedSlicesQuery<K,N,V> addGtExpression(N columnName, V columnValue) {
         .,
         .toByteBuffer(columnValue)));
     return this;
   }
 
   @Override
   public IndexedSlicesQuery<K, N, V> setColumnNames(Collection<N> columnNames) {
     super.setColumnNames(columnNames);
     return this;
   }
 
   @Override
   public IndexedSlicesQuery<K, N, V> setColumnNames(N... columnNames) {
     super.setColumnNames(columnNames);
     return this;
   }
 
   @Override
  public IndexedSlicesQuery<K, N, V> setRange(N start, N finish,
      boolean reversedint count) {
    super.setRange(startfinishreversedcount);
    return this;
  }
  public IndexedSlicesQuery<K, N, V> setReturnKeysOnly() {
    super.setReturnKeysOnly();
    return this;
  }
  public IndexedSlicesQuery<K,N,V> setStartKey(K startKey) {
    return this;
  }
  public IndexedSlicesQuery<K,N,V> setColumnFamily(String cf) {
    super.setColumnFamily(cf);
    return this;
  }
  
  public IndexedSlicesQuery<K,N,V> setRowCount(int rowCount) {
    .setCount(rowCount);
    return this;
  }
  public QueryResult<OrderedRows<K,N, V>> execute() {
        new Operation <OrderedRows<K,N,V>>(.) {
          @Override
          public OrderedRows<K,N,V> execute(Cassandra.Client clientthrows HectorException {
            LinkedHashMap<ByteBufferList<Column>> ret = null;
            try {
              if (!.isSetStart_key()) {
                .setStart_key(new byte[0]);
              }
              ColumnParent columnParent = new ColumnParent();
              List<KeySlicekeySlices = client.get_indexed_slices(columnParent,
                  getPredicate(), ThriftConverter.consistencyLevel(.get()));
              ret = (keySlices == null || keySlices.isEmpty() ) ? new LinkedHashMap<ByteBufferList<Column>>(0) : 
                new LinkedHashMap<ByteBufferList<Column>>(
                    keySlices.size());
              for (KeySlice keySlice : keySlices) {
                ret.put(ByteBuffer.wrap(keySlice.getKey()), ThriftConverter.getColumnList(keySlice.getColumns()));
              }
            } catch (Exception e) {
              HectorException he = .getExceptionsTranslator().translate(e);
              setException(he);
              throw he;
            }
            Map<K, List<Column>> thriftRet = .fromBytesMap(ret);
            return new OrderedRowsImpl<K,N,V>((LinkedHashMap<K, List<Column>>) thriftRet);
          }
        }), this);
  }
  
  
New to GrepCode? Check out our FAQ X