public List<HistoricDetail> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    List<HistoricDetail> historicDetails =
        commandContext
            .getHistoricDetailEntityManager()
            .findHistoricDetailsByQueryCriteria(this, page);

    HistoricDetailVariableInstanceUpdateEntity varUpdate = null;
    if (historicDetails != null) {
      for (HistoricDetail historicDetail : historicDetails) {
        if (historicDetail instanceof HistoricDetailVariableInstanceUpdateEntity) {
          varUpdate = (HistoricDetailVariableInstanceUpdateEntity) historicDetail;

          // Touch byte-array to ensure initialized inside context
          varUpdate.getByteArrayValue();

          // ACT-863: EntityManagerFactorySession instance needed for fetching value, touch while
          // inside context to store
          // cached value
          if (varUpdate.getVariableType() instanceof JPAEntityVariableType) {
            // Use HistoricJPAEntityVariableType to force caching of value to return from query
            varUpdate.setVariableType(HistoricJPAEntityVariableType.getSharedInstance());
            varUpdate.getValue();
          }
        }
      }
    }
    return historicDetails;
  }
  @SuppressWarnings("unchecked")
  public void deleteHistoricProcessInstanceById(String historicProcessInstanceId) {
    if (getHistoryManager().isHistoryEnabled()) {
      CommandContext commandContext = Context.getCommandContext();
      HistoricProcessInstanceEntity historicProcessInstance =
          findHistoricProcessInstance(historicProcessInstanceId);

      commandContext
          .getHistoricDetailEntityManager()
          .deleteHistoricDetailsByProcessInstanceId(historicProcessInstanceId);

      commandContext
          .getHistoricVariableInstanceEntityManager()
          .deleteHistoricVariableInstanceByProcessInstanceId(historicProcessInstanceId);

      commandContext
          .getHistoricActivityInstanceEntityManager()
          .deleteHistoricActivityInstancesByProcessInstanceId(historicProcessInstanceId);

      commandContext
          .getHistoricTaskInstanceEntityManager()
          .deleteHistoricTaskInstancesByProcessInstanceId(historicProcessInstanceId);

      commandContext
          .getHistoricIdentityLinkEntityManager()
          .deleteHistoricIdentityLinksByProcInstance(historicProcessInstanceId);

      commandContext
          .getCommentEntityManager()
          .deleteCommentsByProcessInstanceId(historicProcessInstanceId);

      getDbSqlSession().delete(historicProcessInstance);

      // Also delete any sub-processes that may be active (ACT-821)
      HistoricProcessInstanceQueryImpl subProcessesQueryImpl =
          new HistoricProcessInstanceQueryImpl();
      subProcessesQueryImpl.superProcessInstanceId(historicProcessInstanceId);

      List<HistoricProcessInstance> selectList =
          getDbSqlSession()
              .selectList("selectHistoricProcessInstancesByQueryCriteria", subProcessesQueryImpl);
      for (HistoricProcessInstance child : selectList) {
        deleteHistoricProcessInstanceById(child.getId());
      }
    }
  }
 public long executeCount(CommandContext commandContext) {
   checkQueryOk();
   return commandContext
       .getHistoricDetailEntityManager()
       .findHistoricDetailCountByQueryCriteria(this);
 }