Search in sources :

Example 1 with DbSqlSession

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

the class AbstractMuleTest 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(ProcessEngine processEngine) throws Exception {
    log.debug("verifying that db is clean after test");
    Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
        String tableNameWithoutPrefix = tableName.replace(processEngine.getProcessEngineConfiguration().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();
        CommandConfig config = new CommandConfig().transactionNotSupported();
        commandExecutor.execute(config, new Command<Object>() {

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

Example 2 with DbSqlSession

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

the class HistoricDetailEntity method delete.

public void delete() {
    DbSqlSession dbSqlSession = Context.getCommandContext().getDbSqlSession();
    dbSqlSession.delete(this);
}
Also used : DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 3 with DbSqlSession

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

the class ProcessDefinitionInfoEntityManager method updateProcessDefinitionInfo.

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

Example 4 with DbSqlSession

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

the class TaskEntity method update.

public void update() {
    // Needed to make history work: the setter will also update the historic task
    setOwner(this.getOwner());
    setAssignee(this.getAssignee(), true, false);
    setDelegationState(this.getDelegationState());
    setName(this.getName());
    setDescription(this.getDescription());
    setPriority(this.getPriority());
    setCategory(this.getCategory());
    setCreateTime(this.getCreateTime());
    setDueDate(this.getDueDate());
    setParentTaskId(this.getParentTaskId());
    setFormKey(formKey);
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update(this);
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, this));
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 5 with DbSqlSession

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

the class TaskEntity method insert.

public void insert(ExecutionEntity execution) {
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(this);
    // Inherit tenant id (if applicable)
    if (execution != null && execution.getTenantId() != null) {
        setTenantId(execution.getTenantId());
    }
    if (execution != null) {
        execution.addTask(this);
    }
    commandContext.getHistoryManager().recordTaskCreated(this, execution);
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, this));
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, this));
    }
}
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