@SuppressWarnings({ "unchecked", "rawtypes" })
public void setReplacedBy(InterpretableExecution replacedBy) {
this.replacedBy = (ExecutionEntity) replacedBy;
CommandContext commandContext = Context.getCommandContext();
DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
// update the related tasks
for (TaskEntity task: getTasks()) {
task.setExecutionId(replacedBy.getId());
task.setExecution(this.replacedBy);
this.replacedBy.addTask(task);
}
// All tasks have been moved to 'replacedBy', safe to clear the list
this.tasks.clear();
tasks = dbSqlSession.findInCache(TaskEntity.class);
for (TaskEntity task: tasks) {
if (id.equals(task.getExecutionId())) {
task.setExecutionId(replacedBy.getId());
}
}
// update the related jobs
List<JobEntity> jobs = getJobs();
for (JobEntity job: jobs) {
job.setExecution((ExecutionEntity) replacedBy);
}
// update the related event subscriptions
List<EventSubscriptionEntity> eventSubscriptions = getEventSubscriptions();
for (EventSubscriptionEntity subscriptionEntity: eventSubscriptions) {
subscriptionEntity.setExecution((ExecutionEntity) replacedBy);
}
// update the related process variables
List<VariableInstanceEntity> variables = (List) commandContext
.getVariableInstanceManager()
.findVariableInstancesByExecutionId(id);
for (VariableInstanceEntity variable: variables) {
variable.setExecutionId(replacedBy.getId());
}
variables = dbSqlSession.findInCache(VariableInstanceEntity.class);
for (VariableInstanceEntity variable: variables) {
if (id.equals(variable.getExecutionId())) {
variable.setExecutionId(replacedBy.getId());
}
}
commandContext.getHistoryManager()
.recordExecutionReplacedBy(this, replacedBy);
}