use of com.datastax.driver.core.PagingIterable in project eventapis by kloiasoft.
the class CassandraViewQuery method queryEntityInternal.
private E queryEntityInternal(String entityId, Select select) throws EventStoreException {
E initialInstance;
E result = null;
try {
initialInstance = entityType.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
log.error(e.getMessage(), e);
throw new EventStoreException(e);
}
List<Row> entityEventDatas = cassandraSession.execute(select, PagingIterable::all);
for (Row entityEventData : entityEventDatas) {
EntityEvent entityEvent = convertToEntityEvent(entityEventData);
if (entityEvent.getStatus() == EventState.CREATED) {
EntityFunctionSpec<E, ?> functionSpec = functionMap.get(entityEvent.getEventType());
if (functionSpec != null) {
EntityEventWrapper eventWrapper = new EntityEventWrapper<>(functionSpec.getQueryType(), objectMapper, entityEvent);
EntityFunction<E, ?> entityFunction = functionSpec.getEntityFunction();
result = (E) entityFunction.apply(result == null ? initialInstance : result, eventWrapper);
} else
log.trace("Function Spec is not available for " + entityEvent.getEventType() + " EntityId:" + entityId + " Table:" + tableName);
}
if (result != null) {
result.setId(entityId);
result.setVersion(entityEvent.getEventKey().getVersion());
}
}
return (result == null || result.getId() == null) ? null : result;
}
Aggregations