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