Search in sources :

Example 1 with PersistenceSession

use of org.camunda.bpm.engine.impl.db.PersistenceSession in project camunda-bpm-platform by camunda.

the class SchemaOperationsProcessEngineBuild method execute.

public Void execute(CommandContext commandContext) {
    String databaseSchemaUpdate = Context.getProcessEngineConfiguration().getDatabaseSchemaUpdate();
    PersistenceSession persistenceSession = commandContext.getSession(PersistenceSession.class);
    if (ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) {
        try {
            persistenceSession.dbSchemaDrop();
        } catch (RuntimeException e) {
        // ignore
        }
    }
    if (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP.equals(databaseSchemaUpdate) || ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate) || ProcessEngineConfigurationImpl.DB_SCHEMA_UPDATE_CREATE.equals(databaseSchemaUpdate)) {
        persistenceSession.dbSchemaCreate();
    } else if (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) {
        persistenceSession.dbSchemaCheckVersion();
    } else if (ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) {
        persistenceSession.dbSchemaUpdate();
    }
    checkDeploymentLockExists(commandContext);
    checkHistoryCleanupLockExists(commandContext);
    // create history cleanup job
    if (Context.getProcessEngineConfiguration().getManagementService().getTableMetaData("ACT_RU_JOB") != null) {
        Context.getProcessEngineConfiguration().getHistoryService().cleanUpHistoryAsync();
    }
    return null;
}
Also used : PersistenceSession(org.camunda.bpm.engine.impl.db.PersistenceSession)

Example 2 with PersistenceSession

use of org.camunda.bpm.engine.impl.db.PersistenceSession in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method assertAndEnsureCleanDb.

/**
 * Ensures that the database is clean after the test. This means the test has to remove
 * all resources it entered to the database.
 * If the DB is not clean, it is cleaned by performing a create a drop.
 *
 * @param processEngine the {@link ProcessEngine} to check
 * @param fail if true the method will throw an {@link AssertionError} if the database is not clean
 * @return the database summary if fail is set to false or null if database was clean
 * @throws AssertionError if the database was not clean and fail is set to true
 */
public static void assertAndEnsureCleanDb(ProcessEngine processEngine) {
    ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
    String databaseTablePrefix = processEngineConfiguration.getDatabaseTablePrefix().trim();
    Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
        String tableNameWithoutPrefix = tableName.replace(databaseTablePrefix, "");
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            Long count = tableCounts.get(tableName);
            if (count != 0L) {
                outputMessage.append("\t").append(tableName).append(": ").append(count).append(" record(s)\n");
            }
        }
    }
    if (outputMessage.length() > 0) {
        outputMessage.insert(0, "DB NOT CLEAN: \n");
        /**
         * skip drop and recreate if a table prefix is used
         */
        if (databaseTablePrefix.isEmpty()) {
            processEngineConfiguration.getCommandExecutorSchemaOperations().execute(new Command<Object>() {

                public Object execute(CommandContext commandContext) {
                    PersistenceSession persistenceSession = commandContext.getSession(PersistenceSession.class);
                    persistenceSession.dbSchemaDrop();
                    persistenceSession.dbSchemaCreate();
                    HistoryLevelSetupCommand.dbCreateHistoryLevel(commandContext);
                    return null;
                }
            });
        }
        Assert.fail(outputMessage.toString());
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) PersistenceSession(org.camunda.bpm.engine.impl.db.PersistenceSession) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl)

Aggregations

PersistenceSession (org.camunda.bpm.engine.impl.db.PersistenceSession)2 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1