use of io.siddhi.core.exception.DatabaseRuntimeException in project siddhi by wso2.
the class AbstractRecordTable method updateOrAdd.
@Override
public void updateOrAdd(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
List<Object[]> addingRecords = new ArrayList<>();
updateOrAddingEventChunk.reset();
long timestamp = 0L;
while (updateOrAddingEventChunk.hasNext()) {
StateEvent stateEvent = updateOrAddingEventChunk.next();
Map<String, Object> variableMap = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
}
updateConditionParameterMaps.add(variableMap);
Map<String, Object> variableMapForUpdateSet = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
}
updateSetParameterMaps.add(variableMapForUpdateSet);
addingRecords.add(stateEvent.getStreamEvent(0).getOutputData());
timestamp = stateEvent.getTimestamp();
}
try {
if (recordTableHandler != null) {
recordTableHandler.updateOrAdd(timestamp, recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
} else {
updateOrAdd(recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
}
} catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
onUpdateOrAddError(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor, e);
}
}
use of io.siddhi.core.exception.DatabaseRuntimeException in project siddhi by wso2.
the class Table method onDeleteError.
protected void onDeleteError(ComplexEventChunk<StateEvent> deletingEventChunk, CompiledCondition compiledCondition, Exception e) {
OnErrorAction errorAction = onErrorAction;
if (e instanceof ConnectionUnavailableException) {
isConnected.set(false);
if (errorAction == OnErrorAction.STORE) {
deletingEventChunk.reset();
ErroneousEvent erroneousEvent = new ErroneousEvent(new ReplayableTableRecord(deletingEventChunk, compiledCondition), e, e.getMessage());
erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(deletingEventChunk, isObjectColumnPresent, tableDefinition, e));
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_DELETE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing delete for events at '" + tableDefinition.getId() + "'. Events saved '" + deletingEventChunk.toString() + "'");
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
if (!isTryingToConnect.get()) {
connectWithRetry();
}
} else {
if (isTryingToConnect.get()) {
LOG.warn("Error on '" + siddhiAppContext.getName() + "' while performing delete for events '" + deletingEventChunk + "', operation busy waiting at Table '" + tableDefinition.getId() + "' as its trying to reconnect!");
waitWhileConnect();
LOG.info("SiddhiApp '" + siddhiAppContext.getName() + "' table '" + tableDefinition.getId() + "' has become available for delete operation for events '" + deletingEventChunk + "'");
delete(deletingEventChunk, compiledCondition);
} else {
connectWithRetry();
delete(deletingEventChunk, compiledCondition);
}
}
} else if (e instanceof DatabaseRuntimeException) {
if (errorAction == OnErrorAction.STORE) {
deletingEventChunk.reset();
ReplayableTableRecord record = new ReplayableTableRecord(deletingEventChunk, compiledCondition);
record.setFromConnectionUnavailableException(false);
ErroneousEvent erroneousEvent = new ErroneousEvent(record, e, e.getMessage());
erroneousEvent.setOriginalPayload(ErrorHandlerUtils.constructErrorRecordString(deletingEventChunk, isObjectColumnPresent, tableDefinition, e));
ErrorStoreHelper.storeErroneousEvent(siddhiAppContext.getSiddhiContext().getErrorStore(), ErrorOccurrence.STORE_ON_TABLE_DELETE, siddhiAppContext.getName(), erroneousEvent, tableDefinition.getId());
LOG.error("Error on '" + siddhiAppContext.getName() + "' while performing delete for events at '" + tableDefinition.getId() + "'. Events saved '" + deletingEventChunk.toString() + "'");
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
}
}
}
Aggregations