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);
}
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;
}
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);
}
}
}
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());
}
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));
}
Aggregations