Search in sources :

Example 1 with DbEntity

use of org.camunda.bpm.engine.impl.db.DbEntity 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 DbEntity

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

the class DbEntityManager method onEntityLoaded.

public void onEntityLoaded(DbEntity entity) {
    // we get a callback when the persistence session loads an object from the database
    DbEntity cachedPersistentObject = dbEntityCache.get(entity.getClass(), entity.getId());
    if (cachedPersistentObject == null) {
        // only put into the cache if not already present
        dbEntityCache.putPersistent(entity);
        // invoke postLoad() lifecycle method
        if (entity instanceof DbEntityLifecycleAware) {
            DbEntityLifecycleAware lifecycleAware = (DbEntityLifecycleAware) entity;
            lifecycleAware.postLoad();
        }
    }
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) CachedDbEntity(org.camunda.bpm.engine.impl.db.entitymanager.cache.CachedDbEntity) DbEntityLifecycleAware(org.camunda.bpm.engine.impl.db.DbEntityLifecycleAware)

Example 3 with DbEntity

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

the class DbSqlSession method insertEntity.

// insert //////////////////////////////////////////
@Override
protected void insertEntity(DbEntityOperation operation) {
    final DbEntity dbEntity = operation.getEntity();
    // get statement
    String insertStatement = dbSqlSessionFactory.getInsertStatement(dbEntity);
    insertStatement = dbSqlSessionFactory.mapStatement(insertStatement);
    ensureNotNull("no insert statement for " + dbEntity.getClass() + " in the ibatis mapping files", "insertStatement", insertStatement);
    // execute the insert
    executeInsertEntity(insertStatement, dbEntity);
    // perform post insert actions on entity
    entityInserted(dbEntity);
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity)

Example 4 with DbEntity

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

the class DbEntityOperationComparator method compare.

public int compare(DbEntityOperation firstOperation, DbEntityOperation secondOperation) {
    if (firstOperation.equals(secondOperation)) {
        return 0;
    }
    DbEntity firstEntity = firstOperation.getEntity();
    DbEntity secondEntity = secondOperation.getEntity();
    return firstEntity.getId().compareTo(secondEntity.getId());
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity)

Example 5 with DbEntity

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

the class DbEntityCache method get.

/**
 * get an object from the cache
 *
 * @param type the type of the object
 * @param id the id of the object
 * @return the object or 'null' if the object is not in the cache
 * @throws ProcessEngineException if an object for the given id can be found but is of the wrong type.
 */
@SuppressWarnings("unchecked")
public <T extends DbEntity> T get(Class<T> type, String id) {
    Class<?> cacheKey = cacheKeyMapping.getEntityCacheKey(type);
    CachedDbEntity cachedDbEntity = getCachedEntity(cacheKey, id);
    if (cachedDbEntity != null) {
        DbEntity dbEntity = cachedDbEntity.getEntity();
        try {
            return (T) dbEntity;
        } catch (ClassCastException e) {
            throw LOG.entityCacheLookupException(type, id, dbEntity.getClass(), e);
        }
    } else {
        return null;
    }
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) DELETED_TRANSIENT(org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.DELETED_TRANSIENT) PERSISTENT(org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.PERSISTENT) TRANSIENT(org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.TRANSIENT) DELETED_PERSISTENT(org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.DELETED_PERSISTENT)

Aggregations

DbEntity (org.camunda.bpm.engine.impl.db.DbEntity)12 CachedDbEntity (org.camunda.bpm.engine.impl.db.entitymanager.cache.CachedDbEntity)4 HasDbRevision (org.camunda.bpm.engine.impl.db.HasDbRevision)3 ArrayList (java.util.ArrayList)2 ListQueryParameterObject (org.camunda.bpm.engine.impl.db.ListQueryParameterObject)2 HashMap (java.util.HashMap)1 List (java.util.List)1 BatchResult (org.apache.ibatis.executor.BatchResult)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)1 DbEntityLifecycleAware (org.camunda.bpm.engine.impl.db.DbEntityLifecycleAware)1 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 DELETED_PERSISTENT (org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.DELETED_PERSISTENT)1 DELETED_TRANSIENT (org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.DELETED_TRANSIENT)1 PERSISTENT (org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.PERSISTENT)1 TRANSIENT (org.camunda.bpm.engine.impl.db.entitymanager.cache.DbEntityState.TRANSIENT)1 DbBulkOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation)1 DbEntityOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbEntityOperation)1 DbOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperation)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1