Search in sources :

Example 6 with DbSqlSession

use of org.activiti.engine.impl.db.DbSqlSession in project Activiti by Activiti.

the class BaseSpringRestTestCase method assertAndEnsureCleanDb.

/** Each test is assumed to clean up all DB content it entered.
   * After a test method executed, this method scans all tables to see if the DB is completely clean. 
   * It throws AssertionFailed in case the DB is not clean.
   * If the DB is not clean, it is cleaned by performing a create a drop. */
protected void assertAndEnsureCleanDb() throws Throwable {
    log.debug("verifying that db is clean after test");
    Map<String, Long> tableCounts = managementService.getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
        String tableNameWithoutPrefix = tableName.replace(processEngineConfiguration.getDatabaseTablePrefix(), "");
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            Long count = tableCounts.get(tableName);
            if (count != 0L) {
                outputMessage.append("  " + tableName + ": " + count + " record(s) ");
            }
        }
    }
    if (outputMessage.length() > 0) {
        outputMessage.insert(0, "DB NOT CLEAN: \n");
        log.error(EMPTY_LINE);
        log.error(outputMessage.toString());
        log.info("dropping and recreating db");
        CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
        commandExecutor.execute(new Command<Object>() {

            public Object execute(CommandContext commandContext) {
                DbSqlSession session = commandContext.getSession(DbSqlSession.class);
                session.dbSchemaDrop();
                session.dbSchemaCreate();
                return null;
            }
        });
        if (exception != null) {
            throw exception;
        } else {
            Assert.fail(outputMessage.toString());
        }
    } else {
        log.info("database was clean");
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 7 with DbSqlSession

use of org.activiti.engine.impl.db.DbSqlSession in project Activiti by Activiti.

the class BaseJPARestTestCase method assertAndEnsureCleanDb.

/** Each test is assumed to clean up all DB content it entered.
   * After a test method executed, this method scans all tables to see if the DB is completely clean. 
   * It throws AssertionFailed in case the DB is not clean.
   * If the DB is not clean, it is cleaned by performing a create a drop. */
protected void assertAndEnsureCleanDb() throws Throwable {
    log.debug("verifying that db is clean after test");
    Map<String, Long> tableCounts = managementService.getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
        String tableNameWithoutPrefix = tableName.replace(processEngineConfiguration.getDatabaseTablePrefix(), "");
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            Long count = tableCounts.get(tableName);
            if (count != 0L) {
                outputMessage.append("  " + tableName + ": " + count + " record(s) ");
            }
        }
    }
    if (outputMessage.length() > 0) {
        outputMessage.insert(0, "DB NOT CLEAN: \n");
        log.error(EMPTY_LINE);
        log.error(outputMessage.toString());
        log.info("dropping and recreating db");
        CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
        commandExecutor.execute(new Command<Object>() {

            public Object execute(CommandContext commandContext) {
                DbSqlSession session = commandContext.getSession(DbSqlSession.class);
                session.dbSchemaDrop();
                session.dbSchemaCreate();
                return null;
            }
        });
        if (exception != null) {
            throw exception;
        } else {
            Assert.fail(outputMessage.toString());
        }
    } else {
        log.info("database was clean");
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 8 with DbSqlSession

use of org.activiti.engine.impl.db.DbSqlSession in project Activiti by Activiti.

the class TimerEventCompatibilityTest method changeConfigurationToPlainText.

protected void changeConfigurationToPlainText(TimerJobEntity job) {
    String activityId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
    final TimerJobEntity finalJob = job;
    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    final String finalActivityId = activityId;
    commandExecutor.execute(config, new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            DbSqlSession session = commandContext.getDbSqlSession();
            session.delete(finalJob);
            session.flush();
            session.commit();
            return null;
        }
    });
    commandExecutor.execute(config, new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            DbSqlSession session = commandContext.getDbSqlSession();
            finalJob.setJobHandlerConfiguration(finalActivityId);
            finalJob.setId(null);
            session.insert(finalJob);
            session.flush();
            session.commit();
            return null;
        }
    });
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 9 with DbSqlSession

use of org.activiti.engine.impl.db.DbSqlSession in project Activiti by Activiti.

the class ExecutionEntity method setReplacedBy.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void setReplacedBy(InterpretableExecution replacedBy) {
    this.replacedBy = (ExecutionEntity) replacedBy;
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    // update the related tasks
    List<TaskEntity> allTasks = new ArrayList<TaskEntity>();
    allTasks.addAll(getTasks());
    List<TaskEntity> cachedTasks = dbSqlSession.findInCache(TaskEntity.class);
    for (TaskEntity cachedTask : cachedTasks) {
        if (cachedTask.getExecutionId().equals(this.getId())) {
            allTasks.add(cachedTask);
        }
    }
    for (TaskEntity task : allTasks) {
        task.setExecutionId(replacedBy.getId());
        task.setExecution(this.replacedBy);
        // update the related local task variables
        List<VariableInstanceEntity> variables = (List) commandContext.getVariableInstanceEntityManager().findVariableInstancesByTaskId(task.getId());
        for (VariableInstanceEntity variable : variables) {
            variable.setExecution(this.replacedBy);
        }
        this.replacedBy.addTask(task);
    }
    // All tasks have been moved to 'replacedBy', safe to clear the list 
    this.tasks.clear();
    tasks = dbSqlSession.findInCache(TaskEntity.class);
    for (TaskEntity task : tasks) {
        if (id.equals(task.getExecutionId())) {
            task.setExecutionId(replacedBy.getId());
        }
    }
    // update the related jobs
    List<JobEntity> jobs = getJobs();
    for (JobEntity job : jobs) {
        job.setExecution((ExecutionEntity) replacedBy);
    }
    // update the related event subscriptions
    List<EventSubscriptionEntity> eventSubscriptions = getEventSubscriptions();
    for (EventSubscriptionEntity subscriptionEntity : eventSubscriptions) {
        subscriptionEntity.setExecution((ExecutionEntity) replacedBy);
    }
    // update the related process variables
    List<VariableInstanceEntity> variables = (List) commandContext.getVariableInstanceEntityManager().findVariableInstancesByExecutionId(id);
    for (VariableInstanceEntity variable : variables) {
        variable.setExecutionId(replacedBy.getId());
    }
    variables = dbSqlSession.findInCache(VariableInstanceEntity.class);
    for (VariableInstanceEntity variable : variables) {
        if (id.equals(variable.getExecutionId())) {
            variable.setExecutionId(replacedBy.getId());
        }
    }
    commandContext.getHistoryManager().recordExecutionReplacedBy(this, replacedBy);
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 10 with DbSqlSession

use of org.activiti.engine.impl.db.DbSqlSession in project Activiti by Activiti.

the class GroupEntityManager method updateGroup.

public void updateGroup(Group updatedGroup) {
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update((GroupEntity) updatedGroup);
    if (getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedGroup));
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Aggregations

DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)15 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)13 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)6 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)4 ArrayList (java.util.ArrayList)2 List (java.util.List)1 CachedEntity (org.activiti.engine.impl.persistence.cache.CachedEntity)1 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1 TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)1