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;
}
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());
}
}
Aggregations