Search in sources :

Example 1 with DbBulkOperation

use of org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation in project camunda-bpm-platform by camunda.

the class PurgeDatabaseAndCacheCmd method purgeDatabase.

private DatabasePurgeReport purgeDatabase(CommandContext commandContext) {
    DbEntityManager dbEntityManager = commandContext.getDbEntityManager();
    // For MySQL and MariaDB we have to disable foreign key check,
    // to delete the table data as bulk operation (execution, incident etc.)
    // The flag will be reset by the DBEntityManager after flush.
    dbEntityManager.setIgnoreForeignKeysForNextFlush(true);
    List<String> tablesNames = dbEntityManager.getTableNamesPresentInDatabase();
    String databaseTablePrefix = commandContext.getProcessEngineConfiguration().getDatabaseTablePrefix().trim();
    // for each table
    DatabasePurgeReport databasePurgeReport = new DatabasePurgeReport();
    for (String tableName : tablesNames) {
        String tableNameWithoutPrefix = tableName.replace(databaseTablePrefix, EMPTY_STRING);
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            // Check if table contains data
            Map<String, String> param = new HashMap<String, String>();
            param.put(TABLE_NAME, tableName);
            Long count = (Long) dbEntityManager.selectOne(SELECT_TABLE_COUNT, param);
            if (count > 0) {
                databasePurgeReport.addPurgeInformation(tableName, count);
                // Get corresponding entity classes for the table, which contains data
                List<Class<? extends DbEntity>> entities = commandContext.getTableDataManager().getEntities(tableName);
                if (entities.isEmpty()) {
                    throw new ProcessEngineException("No mapped implementation of " + DbEntity.class.getName() + " was found for: " + tableName);
                }
                // Delete the table data as bulk operation with the first entity
                Class<? extends DbEntity> entity = entities.get(0);
                DbBulkOperation deleteBulkOp = new DbBulkOperation(DbOperationType.DELETE_BULK, entity, DELETE_TABLE_DATA, param);
                dbEntityManager.getDbOperationManager().addOperation(deleteBulkOp);
            }
        }
    }
    return databasePurgeReport;
}
Also used : HashMap(java.util.HashMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager) DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) DbBulkOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with DbBulkOperation

use of org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation in project camunda-bpm-platform by camunda.

the class DbEntityManager method performBulkOperation.

protected DbBulkOperation performBulkOperation(Class<? extends DbEntity> entityType, String statement, Object parameter, DbOperationType operationType) {
    // create operation
    DbBulkOperation bulkOperation = createDbBulkOperation(entityType, statement, parameter, operationType);
    // schedule operation
    dbOperationManager.addOperation(bulkOperation);
    return bulkOperation;
}
Also used : DbBulkOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation)

Example 3 with DbBulkOperation

use of org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation in project camunda-bpm-platform by camunda.

the class DbEntityManager method performBulkOperationPreserveOrder.

protected DbBulkOperation performBulkOperationPreserveOrder(Class<? extends DbEntity> entityType, String statement, Object parameter, DbOperationType operationType) {
    DbBulkOperation bulkOperation = createDbBulkOperation(entityType, statement, parameter, operationType);
    // schedule operation
    dbOperationManager.addOperationPreserveOrder(bulkOperation);
    return bulkOperation;
}
Also used : DbBulkOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation)

Example 4 with DbBulkOperation

use of org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation in project camunda-bpm-platform by camunda.

the class DbEntityManager method createDbBulkOperation.

private DbBulkOperation createDbBulkOperation(Class<? extends DbEntity> entityType, String statement, Object parameter, DbOperationType operationType) {
    // create operation
    DbBulkOperation bulkOperation = new DbBulkOperation();
    // configure operation
    bulkOperation.setOperationType(operationType);
    bulkOperation.setEntityType(entityType);
    bulkOperation.setStatement(statement);
    bulkOperation.setParameter(parameter);
    return bulkOperation;
}
Also used : DbBulkOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation)

Aggregations

DbBulkOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation)4 HashMap (java.util.HashMap)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 DbEntity (org.camunda.bpm.engine.impl.db.DbEntity)1 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 DatabasePurgeReport (org.camunda.bpm.engine.impl.management.DatabasePurgeReport)1