use of org.apache.cassandra.thrift.SlicePredicate in project scale7-pelops by s7.
the class Selector method getPageOfSuperColumnsFromRow.
/**
* Retrieve a page of super columns composed from a segment of the sequence of super columns in a row.
* @param columnFamily The name of the column family containing the super columns
* @param rowKey The key of the row
* @param startBeyondName The sequence of super columns must begin with the smallest super column name greater than this value. Pass <code>null</code> to start at the beginning of the sequence.
* @param reversed Whether the scan should proceed in descending super column name order
* @param count The maximum number of super columns that can be retrieved by the scan
* @param cLevel The Cassandra consistency level with which to perform the operation
* @return A page of super columns
* @throws PelopsException if an error occurs
*/
public List<SuperColumn> getPageOfSuperColumnsFromRow(String columnFamily, Bytes rowKey, Bytes startBeyondName, boolean reversed, int count, ConsistencyLevel cLevel) throws PelopsException {
if (Bytes.nullSafeGet(startBeyondName) == null) {
SlicePredicate predicate = Selector.newColumnsPredicateAll(reversed, count);
return getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
} else {
// cassandra will return the start row but the user is expecting a page of results beyond that point
int incrementedCount = count + 1;
SlicePredicate predicate = Selector.newColumnsPredicate(startBeyondName, Bytes.EMPTY, reversed, incrementedCount);
List<SuperColumn> columns = getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
if (columns.size() > 0) {
SuperColumn first = columns.get(0);
if (first.name.equals(startBeyondName.getBytes()))
return columns.subList(1, columns.size());
else if (columns.size() == incrementedCount)
return columns.subList(0, columns.size() - 1);
}
return columns;
}
}
use of org.apache.cassandra.thrift.SlicePredicate in project scale7-pelops by s7.
the class Selector method newColumnsPredicate.
/**
* Create a new <code>SlicePredicate</code> instance.
* @param startName The inclusive column start name of the range to select in the slice
* @param finishName The inclusive column end name of the range to select in the slice
* @param reversed Whether the results should be returned in reverse order
* @param maxColCount The maximum number of columns to return
* @return The new <code>SlicePredicate</code>
*/
public static SlicePredicate newColumnsPredicate(Bytes startName, Bytes finishName, boolean reversed, int maxColCount) {
SlicePredicate predicate = new SlicePredicate();
predicate.setSlice_range(new SliceRange(nullSafeGet(startName), nullSafeGet(finishName), reversed, maxColCount));
return predicate;
}
use of org.apache.cassandra.thrift.SlicePredicate in project scale7-pelops by s7.
the class Selector method newColumnsPredicate.
/**
* Create a new <code>SlicePredicate</code> instance.
* @param colNames The specific columns names to select in the slice
* @return The new <code>SlicePredicate</code>
*/
public static SlicePredicate newColumnsPredicate(Bytes... colNames) {
List<ByteBuffer> asList = new ArrayList<ByteBuffer>(32);
for (Bytes colName : colNames) asList.add(nullSafeGet(colName));
SlicePredicate predicate = new SlicePredicate();
predicate.setColumn_names(asList);
return predicate;
}
use of org.apache.cassandra.thrift.SlicePredicate in project scale7-pelops by s7.
the class Mutator method deleteColumns.
/**
* Delete a list of columns or super columns.
* @param colFamily The column family
* @param rowKey The key of the row to modify
* @param colNames The column and/or super column names to delete
*/
public Mutator deleteColumns(String colFamily, Bytes rowKey, List<Bytes> colNames) {
safeGetRowKey(rowKey);
validateColumnNames(colNames);
SlicePredicate pred = new SlicePredicate();
pred.setColumn_names(Bytes.transformBytesToList(colNames));
Deletion deletion = new Deletion();
deletion.setTimestamp(timestamp);
deletion.setPredicate(pred);
Mutation mutation = new Mutation();
mutation.setDeletion(deletion);
getMutationList(colFamily, rowKey).add(mutation);
return this;
}
use of org.apache.cassandra.thrift.SlicePredicate in project scale7-pelops by s7.
the class Mutator method deleteSubColumns.
/**
* Delete a list of sub-columns
* @param colFamily The column family
* @param rowKey The key of the row to modify
* @param colName The name of the super column to modify
* @param subColNames The sub-column names to delete
*/
public Mutator deleteSubColumns(String colFamily, Bytes rowKey, Bytes colName, List<Bytes> subColNames) {
safeGetRowKey(rowKey);
validateColumnName(colName);
validateColumnNames(subColNames);
Deletion deletion = new Deletion();
deletion.setTimestamp(timestamp);
deletion.setSuper_column(nullSafeGet(colName));
// CASSANDRA-1027 allows for a null predicate
deletion.setPredicate(subColNames != null && !subColNames.isEmpty() ? new SlicePredicate().setColumn_names(Bytes.transformBytesToList(subColNames)) : null);
Mutation mutation = new Mutation();
mutation.setDeletion(deletion);
getMutationList(colFamily, rowKey).add(mutation);
return this;
}
Aggregations