Search in sources :

Example 6 with ByteArrayEntity

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

the class ModificationBatchJobHandler method execute.

@Override
public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
    ByteArrayEntity configurationEntity = commandContext.getDbEntityManager().selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId());
    ModificationBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes());
    ModificationBuilderImpl executionBuilder = (ModificationBuilderImpl) commandContext.getProcessEngineConfiguration().getRuntimeService().createModification(batchConfiguration.getProcessDefinitionId()).processInstanceIds(batchConfiguration.getIds());
    executionBuilder.setInstructions(batchConfiguration.getInstructions());
    if (batchConfiguration.isSkipCustomListeners()) {
        executionBuilder.skipCustomListeners();
    }
    if (batchConfiguration.isSkipIoMappings()) {
        executionBuilder.skipIoMappings();
    }
    executionBuilder.execute(false);
    commandContext.getByteArrayManager().delete(configurationEntity);
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)

Example 7 with ByteArrayEntity

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

the class SetUserPictureCmd method execute.

public Void execute(CommandContext commandContext) {
    ensureNotNull("userId", userId);
    IdentityInfoEntity pictureInfo = commandContext.getIdentityInfoManager().findUserInfoByUserIdAndKey(userId, "picture");
    if (pictureInfo != null) {
        String byteArrayId = pictureInfo.getValue();
        if (byteArrayId != null) {
            commandContext.getByteArrayManager().deleteByteArrayById(byteArrayId);
        }
    } else {
        pictureInfo = new IdentityInfoEntity();
        pictureInfo.setUserId(userId);
        pictureInfo.setKey("picture");
        commandContext.getDbEntityManager().insert(pictureInfo);
    }
    ByteArrayEntity byteArrayEntity = new ByteArrayEntity(picture.getMimeType(), picture.getBytes());
    commandContext.getDbEntityManager().insert(byteArrayEntity);
    pictureInfo.setValue(byteArrayEntity.getId());
    return null;
}
Also used : ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) IdentityInfoEntity(org.camunda.bpm.engine.impl.persistence.entity.IdentityInfoEntity)

Example 8 with ByteArrayEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity 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 9 with ByteArrayEntity

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

the class HistoricJobLogTest method testDeleteByteArray.

public void testDeleteByteArray() {
    final String processDefinitionId = "myProcessDefition";
    processEngineConfiguration.getCommandExecutorTxRequiresNew().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            for (int i = 0; i < 1234; i++) {
                HistoricJobLogEventEntity log = new HistoricJobLogEventEntity();
                log.setJobId(String.valueOf(i));
                log.setTimestamp(new Date());
                log.setJobDefinitionType(MessageEntity.TYPE);
                log.setProcessDefinitionId(processDefinitionId);
                byte[] aByteValue = StringUtil.toByteArray("abc");
                ByteArrayEntity byteArray = ExceptionUtil.createJobExceptionByteArray(aByteValue);
                log.setExceptionByteArrayId(byteArray.getId());
                commandContext.getHistoricJobLogManager().insert(log);
            }
            return null;
        }
    });
    assertEquals(1234, historyService.createHistoricJobLogQuery().count());
    processEngineConfiguration.getCommandExecutorTxRequiresNew().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByProcessDefinitionId(processDefinitionId);
            return null;
        }
    });
    assertEquals(0, historyService.createHistoricJobLogQuery().count());
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) Date(java.util.Date) HistoricJobLogEventEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricJobLogEventEntity)

Example 10 with ByteArrayEntity

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

the class DeleteProcessInstancesJobHandler method createJobEntities.

protected void createJobEntities(BatchEntity batch, DeleteProcessInstanceBatchConfiguration configuration, String deploymentId, List<String> processInstancesToHandle, int invocationsPerBatchJob) {
    CommandContext commandContext = Context.getCommandContext();
    ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
    JobManager jobManager = commandContext.getJobManager();
    int createdJobs = 0;
    while (!processInstancesToHandle.isEmpty()) {
        int lastIdIndex = Math.min(invocationsPerBatchJob, processInstancesToHandle.size());
        // view of process instances for this job
        List<String> idsForJob = processInstancesToHandle.subList(0, lastIdIndex);
        DeleteProcessInstanceBatchConfiguration jobConfiguration = createJobConfiguration(configuration, idsForJob);
        ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
        JobEntity job = createBatchJob(batch, configurationEntity);
        job.setDeploymentId(deploymentId);
        jobManager.insertAndHintJobExecutor(job);
        createdJobs++;
        idsForJob.clear();
    }
    // update created jobs for batch
    batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
    // update batch configuration
    batch.setConfigurationBytes(writeConfiguration(configuration));
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Aggregations

ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)24 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)3 AttachmentEntity (org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity)3 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BatchConfiguration (org.camunda.bpm.engine.impl.batch.BatchConfiguration)2 SetRetriesBatchConfiguration (org.camunda.bpm.engine.impl.batch.SetRetriesBatchConfiguration)2 ByteArrayManager (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager)2 HistoricJobLogEventEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricJobLogEventEntity)2 IdentityInfoEntity (org.camunda.bpm.engine.impl.persistence.entity.IdentityInfoEntity)2 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)2 Date (java.util.Date)1 Batch (org.camunda.bpm.engine.batch.Batch)1 Picture (org.camunda.bpm.engine.identity.Picture)1 MigrationPlanExecutionBuilderImpl (org.camunda.bpm.engine.impl.migration.MigrationPlanExecutionBuilderImpl)1 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)1 HistoricVariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity)1 PropertyChange (org.camunda.bpm.engine.impl.persistence.entity.PropertyChange)1 MigrationPlanExecutionBuilder (org.camunda.bpm.engine.migration.MigrationPlanExecutionBuilder)1