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