Search in sources :

Example 11 with DbSqlSession

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

the class ModelEntityManager method updateModel.

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

Example 12 with DbSqlSession

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

the class UserEntityManager method updateUser.

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

Example 13 with DbSqlSession

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

the class TimerEventCompatibilityTest method changeConfigurationToPlainText.

protected void changeConfigurationToPlainText(JobEntity job) {
    String activityId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
    final JobEntity 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.getSession(DbSqlSession.class);
            session.delete(finalJob);
            session.flush();
            session.commit();
            return null;
        }
    });
    commandExecutor.execute(config, new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            DbSqlSession session = commandContext.getSession(DbSqlSession.class);
            finalJob.setJobHandlerConfiguration(finalActivityId);
            finalJob.setId(null);
            session.insert(finalJob);
            session.flush();
            session.commit();
            return null;
        }
    });
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) 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 14 with DbSqlSession

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

the class AbstractActivitiTestCase 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("  ").append(tableName).append(": ").append(count).append(" 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.getDbSqlSession();
                session.dbSchemaDrop();
                session.dbSchemaCreate();
                return null;
            }
        });
        if (exception != null) {
            throw exception;
        } else {
            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 15 with DbSqlSession

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

the class AbstractDataManager method getListFromCache.

protected List<EntityImpl> getListFromCache(CachedEntityMatcher<EntityImpl> entityMatcher, Object parameter) {
    Collection<CachedEntity> cachedObjects = getEntityCache().findInCacheAsCachedObjects(getManagedEntityClass());
    DbSqlSession dbSqlSession = getDbSqlSession();
    List<EntityImpl> result = new ArrayList<EntityImpl>(cachedObjects.size());
    if (cachedObjects != null && entityMatcher != null) {
        for (CachedEntity cachedObject : cachedObjects) {
            EntityImpl cachedEntity = (EntityImpl) cachedObject.getEntity();
            if (entityMatcher.isRetained(null, cachedObjects, cachedEntity, parameter) && !dbSqlSession.isEntityToBeDeleted(cachedEntity)) {
                result.add(cachedEntity);
            }
        }
    }
    if (getManagedEntitySubClasses() != null && entityMatcher != null) {
        for (Class<? extends EntityImpl> entitySubClass : getManagedEntitySubClasses()) {
            Collection<CachedEntity> subclassCachedObjects = getEntityCache().findInCacheAsCachedObjects(entitySubClass);
            if (subclassCachedObjects != null) {
                for (CachedEntity subclassCachedObject : subclassCachedObjects) {
                    EntityImpl cachedSubclassEntity = (EntityImpl) subclassCachedObject.getEntity();
                    if (entityMatcher.isRetained(null, cachedObjects, cachedSubclassEntity, parameter) && !dbSqlSession.isEntityToBeDeleted(cachedSubclassEntity)) {
                        result.add(cachedSubclassEntity);
                    }
                }
            }
        }
    }
    return result;
}
Also used : CachedEntity(org.activiti.engine.impl.persistence.cache.CachedEntity) ArrayList(java.util.ArrayList) 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