}
/** customized insert behavior for HistoricVariableUpdateEventEntity */
protected void insertHistoricVariableUpdateEntity(HistoricVariableUpdateEventEntity historyEvent) {
DbEntityManager dbEntityManager = getDbEntityManager();
// insert update only if history level = FULL
if(Context.getProcessEngineConfiguration().getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
// insert byte array entity (if applicable)
byte[] byteValue = historyEvent.getByteValue();
if(byteValue != null) {
ByteArrayEntity byteArrayEntity = new ByteArrayEntity(historyEvent.getVariableName(), byteValue);
Context
.getCommandContext()
.getDbEntityManager()
.insert(byteArrayEntity);
historyEvent.setByteArrayId(byteArrayEntity.getId());
}
dbEntityManager.insert(historyEvent);
}
// always insert/update HistoricProcessVariableInstance
if(HistoryEventTypes.VARIABLE_INSTANCE_CREATE.getEventName().equals(historyEvent.getEventType())) {
HistoricVariableInstanceEntity persistentObject = new HistoricVariableInstanceEntity(historyEvent);
dbEntityManager.insert(persistentObject);
} else if(HistoryEventTypes.VARIABLE_INSTANCE_UPDATE.getEventName().equals(historyEvent.getEventType())) {
HistoricVariableInstanceEntity historicVariableInstanceEntity = dbEntityManager.selectById(HistoricVariableInstanceEntity.class, historyEvent.getVariableInstanceId());
if(historicVariableInstanceEntity != null) {
historicVariableInstanceEntity.updateFromEvent(historyEvent);
} else {
// #CAM-1344 / #SUPPORT-688
// this is a FIX for process instances which were started in camunda fox 6.1 and migrated to camunda BPM 7.0.
// in fox 6.1 the HistoricVariable instances were flushed to the DB when the process instance completed.
// Since fox 6.2 we populate the HistoricVariable table as we go.
HistoricVariableInstanceEntity persistentObject = new HistoricVariableInstanceEntity(historyEvent);
dbEntityManager.insert(persistentObject);
}
} else if(HistoryEventTypes.VARIABLE_INSTANCE_DELETE.getEventName().equals(historyEvent.getEventType())) {
HistoricVariableInstanceEntity historicVariableInstanceEntity = dbEntityManager.selectById(HistoricVariableInstanceEntity.class, historyEvent.getVariableInstanceId());
if(historicVariableInstanceEntity != null) {
historicVariableInstanceEntity.delete();
}
}