Reference Guide

Table Of Contents
return alert;
}
The method from the previous listing posts a new Alert into the database. It is a write query that
creates a new row for every alert posted. The post method is called from other components
whenever they want to log an alert message in the database. In this method, the call flow is as
follows:
1. Create a transport object (DTO) for the incoming alert
2. Call the Distributed Query Service API (getAddAlertQuery) to get an object of type
AddQuery. Please see the implementation above for details. The DTO is an input to this
method.
3. Call the Distributed DataStoreService API (execute) to execute the query and pass the
postAlertQuery as an argument.
4. Return the stored Alert on success or throw a PersistenceException on a failure.
This sequence is followed for every write query to the persistence layer from business logic.
The following listing illustrates another example of business logic using persistence layer services
using a query service. This is a read operation and the example code is as follows.
CassandraAlertManager.java Reading from the Database:
@Override
public List<CassandraAlert> find(CassandraAlertFilter alertFilter,
SortSpecification<CassandraAlertSortAttribute> sortSpec) {
try {
ReadQuery<List<CassandraAlert>, DataStoreContext> query =
queryService.getFindAlertsQuery(alertFilter, sortSpec);
return dataStoreService.execute(query);
} catch (Exception e) {
...
}
}
@Override
public MarkPage<CassandraAlert> find(CassandraAlertFilter alertFilter,
SortSpecification<CassandraAlertSortAttribute> sortSpec,
MarkPageRequest<CassandraAlert> pageRequest) {
ReadQuery<MarkPage<CassandraAlert>, DataStoreContext> query =
queryService.getPageAlertsQuery(
alertFilter, sortSpec, pageRequest);
try {
return dataStoreService.execute(query);
} catch (Exception e) {
...
93