SDN Controller Programming Guide

88
They cater to various conditional queries that can be issued as a read query to the database. The
caller who wants to read from the database needs to create a filter object and fill it with
appropriate values before issuing a find query.
Data Access Object - DAO
In the previous information, the business logic called the DataStoreService API to perform any
persistence operation. The API performs the operation using a DAO. The DAO is a layer that acts
as a single point of communication between the business logic and the database. The
infrastructure provides generic abstractions of the DAO. However, each table needs to have a
table or a Column family specific DAO defined. For this Alerts Demo application there is a
CassandraAlertDao. The example code is illustrated in the following listing.
CassandraAlertDao.java:
package com.hp.demo.cassandra.dao.impl;
...
public class CassandraAlertDao extends
CassAbstractDao<String, String, CassandraAlert,
CassandraStorable<String, String>, CassandraAlertFilter,
CassandraAlertSortAttribute> {
public CassandraAlertDao() throws PersistenceConnException {
cfList.add(new AlertsBySeverity());
cfList.add(new AlertsByState());
cfList.add(new AlertsByTopic());
cfList.add(new AlertsByOrigin());
cfList.add(new AlertsByTimeStamp());
cfList.add(new AlertsCount());
cfList.add(new AlertsByUidAndSysId());
}
private static class AlertColumnFamily {
private static final ColumnName<String, String> SYS_ID_NAME =
ColumnName.valueOf("sysId", BasicType.UTF8, false);
private static final ColumnName<String, Severity> SEVERITY_COL_NAME =
ColumnName.valueOf("severity", BasicType.UTF8, false);
private static final ColumnName<String, Date> TIMESTAMP_COL_NAME =
ColumnName.valueOf("timestamp", BasicType.DATE, false);
private static final ColumnName<String, String> DESC_COL_NAME =
ColumnName.valueOf("description", BasicType.UTF8, false);
private static final ColumnName<String, Boolean> STATE_COL_NAME =
ColumnName.valueOf("state", BasicType.BOOLEAN, false);
private static final ColumnName<String, String> ORIGIN_COL_NAME =
ColumnName.valueOf("origin", BasicType.UTF8, false);
private static final ColumnName<String, String> TOPIC_COL_NAME =
ColumnName.valueOf("topic", BasicType.UTF8, false);
private static ColumnFamily<String, String> COL_FAMILY =