Search in sources :

Example 1 with DbEntityManager

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;
}
Also used : HashMap(java.util.HashMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager) DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) DbBulkOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with DbEntityManager

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;
}
Also used : PropertyChange(org.camunda.bpm.engine.impl.persistence.entity.PropertyChange) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) AttachmentEntity(org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)

Example 3 with DbEntityManager

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;
        }
    }
}
Also used : AuthorizationEntity(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)

Example 4 with DbEntityManager

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);
        }
    }
}
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 5 with DbEntityManager

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);
}
Also used : ListQueryParameterObject(org.camunda.bpm.engine.impl.db.ListQueryParameterObject) ListQueryParameterObject(org.camunda.bpm.engine.impl.db.ListQueryParameterObject) QueryOrderingProperty(org.camunda.bpm.engine.impl.QueryOrderingProperty) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)

Aggregations

DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)11 ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)2 AttachmentEntity (org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 QueryOrderingProperty (org.camunda.bpm.engine.impl.QueryOrderingProperty)1 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)1 CoreVariableInstance (org.camunda.bpm.engine.impl.core.variable.CoreVariableInstance)1 DbEntity (org.camunda.bpm.engine.impl.db.DbEntity)1 ListQueryParameterObject (org.camunda.bpm.engine.impl.db.ListQueryParameterObject)1 DbBulkOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation)1 HistoricScopeInstanceEvent (org.camunda.bpm.engine.impl.history.event.HistoricScopeInstanceEvent)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1 DatabasePurgeReport (org.camunda.bpm.engine.impl.management.DatabasePurgeReport)1 AuthorizationEntity (org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity)1 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)1 HistoricVariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity)1 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)1