SDN Controller Programming Guide

102
case EQUAL:
range = AlertsByState.serializer.buildRange()
.withPrefix(filter.getStateCondition().getValue())
.greaterThan(" ").lessThan("~");
break;
case UNEQUAL:
range = AlertsByState.serializer.buildRange()
.withPrefix(!filter.getStateCondition()
.getValue()).greaterThan(" ").lessThanEquals("~");
break;
default:
range = null;
break;
}
// Find Rows for this filter
Procedure<CassandraStorable<String, StateComposite>> procedure =
new Procedure<CassandraStorable<String, StateComposite>>() {
@Override
public CassandraStorable<String, StateComposite>
execute()
throws Exception {
return context.getContext()
.get(AlertsByState.COL_FAMILY,
AlertsByState.ROW_KEY, range,
AlertsByState.STATE_DECODER);
}
};
// Start the transaction
context.getTransactionContext()
.prepareTransaction(AlertsByState.COL_FAMILY.getName(),
AlertsByState.ROW_KEY);
CassandraStorable<String, StateComposite> rows = context
.getTransactionContext().executeCriticalSection(procedure);
// Add the rows to the row set
Collection<String> id = new ArrayList<String>();
for (Column<StateComposite, ?> state : rows.getColumns()) {
id.add(state.getName().getValue().getId());
}
// Add row Id's to the final Id set
if (rowsSet.isEmpty()) {
rowsSet.addAll(id);
} else {
rowsSet.retainAll(id);