Search in sources :

Example 1 with HistoricVariableInstanceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project camunda-bpm-platform by camunda.

the class HistoricVariableInstanceQueryImpl method executeList.

public List<HistoricVariableInstance> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    ensureVariablesInitialized();
    List<HistoricVariableInstance> historicVariableInstances = commandContext.getHistoricVariableInstanceManager().findHistoricVariableInstancesByQueryCriteria(this, page);
    if (historicVariableInstances != null) {
        for (HistoricVariableInstance historicVariableInstance : historicVariableInstances) {
            HistoricVariableInstanceEntity variableInstanceEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
            if (shouldFetchValue(variableInstanceEntity)) {
                try {
                    variableInstanceEntity.getTypedValue(isCustomObjectDeserializationEnabled);
                } catch (Exception t) {
                    // do not fail if one of the variables fails to load
                    LOG.exceptionWhileGettingValueForVariable(t);
                }
            }
        }
    }
    return historicVariableInstances;
}
Also used : HistoricVariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance)

Example 2 with HistoricVariableInstanceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project camunda-bpm-platform by camunda.

the class DbHistoryEventHandler method insertHistoricVariableUpdateEntity.

/**
 * customized insert behavior for HistoricVariableUpdateEventEntity
 */
protected void insertHistoricVariableUpdateEntity(HistoricVariableUpdateEventEntity historyEvent) {
    DbEntityManager dbEntityManager = getDbEntityManager();
    // insert update only if history level = FULL
    if (shouldWriteHistoricDetail(historyEvent)) {
        // 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 (historyEvent.isEventOfType(HistoryEventTypes.VARIABLE_INSTANCE_CREATE)) {
        HistoricVariableInstanceEntity persistentObject = new HistoricVariableInstanceEntity(historyEvent);
        dbEntityManager.insert(persistentObject);
    } else if (historyEvent.isEventOfType(HistoryEventTypes.VARIABLE_INSTANCE_UPDATE) || historyEvent.isEventOfType(HistoryEventTypes.VARIABLE_INSTANCE_MIGRATE)) {
        HistoricVariableInstanceEntity historicVariableInstanceEntity = dbEntityManager.selectById(HistoricVariableInstanceEntity.class, historyEvent.getVariableInstanceId());
        if (historicVariableInstanceEntity != null) {
            historicVariableInstanceEntity.updateFromEvent(historyEvent);
            historicVariableInstanceEntity.setState(HistoricVariableInstance.STATE_CREATED);
        } 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 (historyEvent.isEventOfType(HistoryEventTypes.VARIABLE_INSTANCE_DELETE)) {
        HistoricVariableInstanceEntity historicVariableInstanceEntity = dbEntityManager.selectById(HistoricVariableInstanceEntity.class, historyEvent.getVariableInstanceId());
        if (historicVariableInstanceEntity != null) {
            historicVariableInstanceEntity.setState(HistoricVariableInstance.STATE_DELETED);
        }
    }
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) HistoricVariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)

Example 3 with HistoricVariableInstanceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project camunda-bpm-platform by camunda.

the class DeserializableVariableTest method testVariableDeserializationOnProcessApplicationRestart.

@Test
@OperateOnDeployment("clientDeployment")
public void testVariableDeserializationOnProcessApplicationRestart() {
    // given
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testDeserializeVariable");
    // when
    Assert.assertNull(runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult());
    runtimeService.restartProcessInstances(pi.getProcessDefinitionId()).startAfterActivity("servicetask1").processInstanceIds(pi.getId()).execute();
    // then
    // Since the variable retrieval is done outside the Process Application Context as well,
    // custom object deserialization is disabled and a null check is performed
    List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery().disableCustomObjectDeserialization().list();
    for (HistoricVariableInstance variable : variableInstances) {
        if (variable.getProcessInstanceId() != pi.getId() && variable instanceof HistoricVariableInstanceEntity) {
            Assert.assertNotNull(((HistoricVariableInstanceEntity) variable).getByteArrayValue());
        }
    }
}
Also used : HistoricVariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 4 with HistoricVariableInstanceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project camunda-bpm-platform by camunda.

the class HistoricVariableInstanceTest method testHistoricVariableInstanceRevision.

@Deployment
public void testHistoricVariableInstanceRevision() {
    // given:
    // a finished process instance
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    assertProcessEnded(processInstance.getId());
    // when
    // then
    HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().singleResult();
    assertNotNull(variable);
    HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) variable;
    // the revision has to be 0
    assertEquals(0, variableEntity.getRevision());
    if (isFullHistoryEnabled()) {
        List<HistoricDetail> details = historyService.createHistoricDetailQuery().orderByVariableRevision().asc().list();
        for (HistoricDetail detail : details) {
            HistoricVariableUpdate variableDetail = (HistoricVariableUpdate) detail;
            assertEquals(0, variableDetail.getRevision());
        }
    }
}
Also used : HistoricVariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with HistoricVariableInstanceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity in project camunda-bpm-platform by camunda.

the class HistoricVariableInstanceTest method testParallelNoWaitState.

@Deployment
public void testParallelNoWaitState() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    assertProcessEnded(processInstance.getId());
    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variables.size());
    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());
    assertEquals(7, historyService.createHistoricActivityInstanceQuery().count());
    if (isFullHistoryEnabled()) {
        assertEquals(2, historyService.createHistoricDetailQuery().count());
    }
}
Also used : HistoricVariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricVariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity)10 Deployment (org.camunda.bpm.engine.test.Deployment)7 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)2 Task (org.camunda.bpm.engine.task.Task)2 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)2 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)1 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)1 Test (org.junit.Test)1