final Object[] values = new Object[propertyNames.length];
for (EventBean insertBean : newData) {
for (int i = 0; i < propertyNames.length; ++i) {
values[i] = insertBean.get(propertyNames[i]);
}
BoundStatement boundStatement = null;
synchronized (_insertStatement) {
boundStatement = _insertStatement.bind(values);
}
synchronized (_session) {
_session.execute(boundStatement);
}
}
_log.debug("Finished insert...");
}
// Delete events from window
else if (newData == null) {
}
// Update events in window
else {
if (newData.length > 0) {
_log.debug("Starting update...");
EventBean newDataFirst = newData[0];
List<String> propertiesToUpdateList = new ArrayList<String>();
for (String propertyName : propertyNames) {
if (newDataFirst.get(propertyName) != null) {
propertiesToUpdateList.add(propertyName);
}
}
String propertiesToUpdate[] = propertiesToUpdateList
.toArray(new String[propertiesToUpdateList.size()]);
final String query = QueryStringBuilder.createUpdateQuery(
_context, propertiesToUpdate);
PreparedStatement _updateStatement = _session.prepare(query);
Object primaryKeyValue = null;
for (EventBean updateBean : newData) {
final List<Object> values = new ArrayList<Object>();
for (int i = 0; i < propertiesToUpdate.length; ++i) {
if (QueryStringBuilder.TABLE_ID
.equals(propertiesToUpdate[i])) {
primaryKeyValue = updateBean
.get(propertiesToUpdate[i]);
} else {
values.add(updateBean.get(propertiesToUpdate[i]));
}
}
values.add(primaryKeyValue);
BoundStatement boundStatement = null;
synchronized (_updateStatement) {
boundStatement = _updateStatement
.bind(values.toArray());
}
synchronized (_session) {