use of org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager in project camunda-bpm-platform by camunda.
the class PurgeDatabaseAndCacheCmd method purgeDatabase.
private DatabasePurgeReport purgeDatabase(CommandContext commandContext) {
DbEntityManager dbEntityManager = commandContext.getDbEntityManager();
// For MySQL and MariaDB we have to disable foreign key check,
// to delete the table data as bulk operation (execution, incident etc.)
// The flag will be reset by the DBEntityManager after flush.
dbEntityManager.setIgnoreForeignKeysForNextFlush(true);
List<String> tablesNames = dbEntityManager.getTableNamesPresentInDatabase();
String databaseTablePrefix = commandContext.getProcessEngineConfiguration().getDatabaseTablePrefix().trim();
// for each table
DatabasePurgeReport databasePurgeReport = new DatabasePurgeReport();
for (String tableName : tablesNames) {
String tableNameWithoutPrefix = tableName.replace(databaseTablePrefix, EMPTY_STRING);
if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
// Check if table contains data
Map<String, String> param = new HashMap<String, String>();
param.put(TABLE_NAME, tableName);
Long count = (Long) dbEntityManager.selectOne(SELECT_TABLE_COUNT, param);
if (count > 0) {
databasePurgeReport.addPurgeInformation(tableName, count);
// Get corresponding entity classes for the table, which contains data
List<Class<? extends DbEntity>> entities = commandContext.getTableDataManager().getEntities(tableName);
if (entities.isEmpty()) {
throw new ProcessEngineException("No mapped implementation of " + DbEntity.class.getName() + " was found for: " + tableName);
}
// Delete the table data as bulk operation with the first entity
Class<? extends DbEntity> entity = entities.get(0);
DbBulkOperation deleteBulkOp = new DbBulkOperation(DbOperationType.DELETE_BULK, entity, DELETE_TABLE_DATA, param);
dbEntityManager.getDbOperationManager().addOperation(deleteBulkOp);
}
}
}
return databasePurgeReport;
}
use of org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager in project camunda-bpm-platform by camunda.
the class CreateAttachmentCmd method execute.
@Override
public Attachment execute(CommandContext commandContext) {
if (taskId != null) {
task = commandContext.getTaskManager().findTaskById(taskId);
} else {
ensureNotNull("taskId or processInstanceId has to be provided", this.processInstanceId);
List<ExecutionEntity> executionsByProcessInstanceId = commandContext.getExecutionManager().findExecutionsByProcessInstanceId(processInstanceId);
ensureNumberOfElements("processInstances", executionsByProcessInstanceId, 1);
processInstance = executionsByProcessInstanceId.get(0);
}
AttachmentEntity attachment = new AttachmentEntity();
attachment.setName(attachmentName);
attachment.setDescription(attachmentDescription);
attachment.setType(attachmentType);
attachment.setTaskId(taskId);
attachment.setProcessInstanceId(processInstanceId);
attachment.setUrl(url);
DbEntityManager dbEntityManger = commandContext.getDbEntityManager();
dbEntityManger.insert(attachment);
if (content != null) {
byte[] bytes = IoUtil.readInputStream(content, attachmentName);
ByteArrayEntity byteArray = new ByteArrayEntity(bytes);
dbEntityManger.insert(byteArray);
attachment.setContentId(byteArray.getId());
}
PropertyChange propertyChange = new PropertyChange("name", null, attachmentName);
if (task != null) {
commandContext.getOperationLogManager().logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, task, propertyChange);
} else if (processInstance != null) {
commandContext.getOperationLogManager().logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, processInstance, propertyChange);
}
return attachment;
}
use of org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager in project camunda-bpm-platform by camunda.
the class DefaultAuthorizationProvider method updateAuthorizationBasedOnCacheEntries.
/**
* Searches through the cache, if there is already an authorization with same rights. If that's the case
* update the given authorization with the permissions and remove the old one from the cache.
*/
protected void updateAuthorizationBasedOnCacheEntries(AuthorizationEntity authorization, String userId, String groupId, Resource resource, String resourceId) {
DbEntityManager dbManager = Context.getCommandContext().getDbEntityManager();
List<AuthorizationEntity> list = dbManager.getCachedEntitiesByType(AuthorizationEntity.class);
for (AuthorizationEntity authEntity : list) {
boolean hasSameAuthRights = hasEntitySameAuthorizationRights(authEntity, userId, groupId, resource, resourceId);
if (hasSameAuthRights) {
int previousPermissions = authEntity.getPermissions();
authorization.setPermissions(previousPermissions);
dbManager.getDbEntityCache().remove(authEntity);
return;
}
}
}
use of org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager 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.db.entitymanager.DbEntityManager in project camunda-bpm-platform by camunda.
the class ExternalTaskManager method selectExternalTasksForTopics.
public List<ExternalTaskEntity> selectExternalTasksForTopics(Collection<TopicFetchInstruction> queryFilters, boolean filterByBusinessKey, int maxResults, boolean usePriority) {
if (queryFilters.isEmpty()) {
return new ArrayList<ExternalTaskEntity>();
}
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("topics", queryFilters);
parameters.put("businessKeyFilter", filterByBusinessKey);
parameters.put("now", ClockUtil.getCurrentTime());
parameters.put("applyOrdering", usePriority);
List<QueryOrderingProperty> orderingProperties = new ArrayList<QueryOrderingProperty>();
orderingProperties.add(EXT_TASK_PRIORITY_ORDERING_PROPERTY);
parameters.put("orderingProperties", orderingProperties);
ListQueryParameterObject parameter = new ListQueryParameterObject(parameters, 0, maxResults);
configureQuery(parameter);
DbEntityManager manager = getDbEntityManager();
return manager.selectList("selectExternalTasksForTopics", parameter);
}
Aggregations