SDN Controller Programming Guide
93
CassandraStorable<String, SeverityComposite> storable = new
CassandraStorable<String, SeverityComposite>(ROW_KEY);
storable.setColumn(new ValuelessColumn<SeverityComposite>(
ColumnName.<SeverityComposite, Void> valueOf(
new SeverityComposite(transportable.getSeverity(),
transportable.getId().getValue()))));
context.getContext().prepareMutation(COL_FAMILY, storable);
}
@Override
public void prepareTransaction(CassandraAlert transportable,
DataStoreContext context) throws Exception {
context.getTransactionContext()
.prepareTransaction(COL_FAMILY.getName(), ROW_KEY);
}
@Override
public void prepareDelete(CassandraAlert transportable,
DataStoreContext context) throws Exception {
SeverityComposite deleteColumn =
new SeverityComposite(transportable.getSeverity(),
transportable.getId().getValue());
context.getContext().delete(COL_FAMILY, ROW_KEY,
ColumnName
.<SeverityComposite, Void>
valueOf(deleteColumn));
}
@Override
public void prepareUpdate(CassandraAlert oldT, CassandraAlert newT,
DataStoreContext context) throws Exception {
...
}
}
In this code, SeverityComposite is the object that represents a composite column for
AlertsBySeverity. AlertsBySeverity implements CfQueryOperations interface. This interface contains
following methods.
1. prepareTransaction–prepares a secondaryColumn family row write transaction.
2. prepareMutation–prepares a secondary Column family row write.
3. prepareDelete–prepares a delete of a secondary index column.
4. prepareUpdate–prepares an update operation on AlertsBySeverity.
When a write query is issued from business logic, a new row is created or an existing row is
updated in the main column family.