/** customized insert behavior for HistoricVariableUpdateEventEntity */
  protected void insertHistoricVariableUpdateEntity(
      HistoricVariableUpdateEventEntity historyEvent) {
    DbSqlSession dbSqlSession = getDbSqlSession();

    // insert update only if history level = FULL
    int historyLevel = Context.getProcessEngineConfiguration().getHistoryLevel();
    if (historyLevel == ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL) {

      // insert byte array entity (if applicable)
      byte[] byteValue = historyEvent.getByteValue();
      if (byteValue != null) {
        ByteArrayEntity byteArrayEntity =
            new ByteArrayEntity(historyEvent.getVariableName(), byteValue);
        Context.getCommandContext().getDbSqlSession().insert(byteArrayEntity);
        historyEvent.setByteArrayId(byteArrayEntity.getId());
      }
      dbSqlSession.insert(historyEvent);
    }

    // always insert/update HistoricProcessVariableInstance
    if (HistoryEvent.VARIABLE_EVENT_TYPE_CREATE.equals(historyEvent.getEventType())) {
      HistoricVariableInstanceEntity persistentObject =
          new HistoricVariableInstanceEntity(historyEvent);
      dbSqlSession.insert(persistentObject);

    } else if (HistoryEvent.VARIABLE_EVENT_TYPE_UPDATE.equals(historyEvent.getEventType())) {
      HistoricVariableInstanceEntity historicVariableInstanceEntity =
          dbSqlSession.selectById(
              HistoricVariableInstanceEntity.class, historyEvent.getVariableInstanceId());
      historicVariableInstanceEntity.updateFromEvent(historyEvent);

    } else if (HistoryEvent.VARIABLE_EVENT_TYPE_DELETE.equals(historyEvent.getEventType())) {
      HistoricVariableInstanceEntity historicVariableInstanceEntity =
          dbSqlSession.selectById(
              HistoricVariableInstanceEntity.class, historyEvent.getVariableInstanceId());
      if (historicVariableInstanceEntity != null) {
        historicVariableInstanceEntity.delete();
      }
    }
  }
  public void updateFromEvent(HistoricVariableUpdateEventEntity historyEvent) {
    this.id = historyEvent.getVariableInstanceId();
    this.processDefinitionKey = historyEvent.getProcessDefinitionKey();
    this.processDefinitionId = historyEvent.getProcessDefinitionId();
    this.processInstanceId = historyEvent.getProcessInstanceId();
    this.taskId = historyEvent.getTaskId();
    this.executionId = historyEvent.getExecutionId();
    this.activityInstanceId = historyEvent.getScopeActivityInstanceId();
    this.caseDefinitionKey = historyEvent.getCaseDefinitionKey();
    this.caseDefinitionId = historyEvent.getCaseDefinitionId();
    this.caseInstanceId = historyEvent.getCaseInstanceId();
    this.caseExecutionId = historyEvent.getCaseExecutionId();
    this.name = historyEvent.getVariableName();
    this.longValue = historyEvent.getLongValue();
    this.doubleValue = historyEvent.getDoubleValue();
    this.textValue = historyEvent.getTextValue();
    this.textValue2 = historyEvent.getTextValue2();

    setSerializerName(historyEvent.getSerializerName());

    byteArrayField.deleteByteArrayValue();

    if (historyEvent.getByteValue() != null) {
      setByteArrayValue(historyEvent.getByteValue());
    }
  }