Search in sources :

Example 6 with DbEntity

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

the class JobQueryTest method deleteJobInDatabase.

private void deleteJobInDatabase() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            timerEntity.delete();
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(timerEntity.getId());
            List<HistoricIncident> historicIncidents = Context.getProcessEngineConfiguration().getHistoryService().createHistoricIncidentQuery().list();
            for (HistoricIncident historicIncident : historicIncidents) {
                commandContext.getDbEntityManager().delete((DbEntity) historicIncident);
            }
            return null;
        }
    });
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) List(java.util.List)

Example 7 with DbEntity

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

the class DbSqlSession method deleteEntity.

// delete ///////////////////////////////////////////
@Override
protected void deleteEntity(DbEntityOperation operation) {
    final DbEntity dbEntity = operation.getEntity();
    // get statement
    String deleteStatement = dbSqlSessionFactory.getDeleteStatement(dbEntity.getClass());
    ensureNotNull("no delete statement for " + dbEntity.getClass() + " in the ibatis mapping files", "deleteStatement", deleteStatement);
    LOG.executeDatabaseOperation("DELETE", dbEntity);
    // execute the delete
    int nrOfRowsDeleted = executeDelete(deleteStatement, dbEntity);
    // It only makes sense to check for optimistic locking exceptions for objects that actually have a revision
    if (dbEntity instanceof HasDbRevision && nrOfRowsDeleted == 0) {
        operation.setFailed(true);
        return;
    }
    // perform post delete action
    entityDeleted(dbEntity);
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) HasDbRevision(org.camunda.bpm.engine.impl.db.HasDbRevision)

Example 8 with DbEntity

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

the class DbSqlSession method updateEntity.

// update ////////////////////////////////////////
@Override
protected void updateEntity(DbEntityOperation operation) {
    final DbEntity dbEntity = operation.getEntity();
    String updateStatement = dbSqlSessionFactory.getUpdateStatement(dbEntity);
    ensureNotNull("no update statement for " + dbEntity.getClass() + " in the ibatis mapping files", "updateStatement", updateStatement);
    LOG.executeDatabaseOperation("UPDATE", dbEntity);
    if (Context.getProcessEngineConfiguration().isJdbcBatchProcessing()) {
        // execute update
        executeUpdate(updateStatement, dbEntity);
    } else {
        // execute update
        int numOfRowsUpdated = executeUpdate(updateStatement, dbEntity);
        if (dbEntity instanceof HasDbRevision) {
            if (numOfRowsUpdated != 1) {
                // failed with optimistic locking
                operation.setFailed(true);
                return;
            } else {
                // increment revision of our copy
                HasDbRevision versionedObject = (HasDbRevision) dbEntity;
                versionedObject.setRevision(versionedObject.getRevisionNext());
            }
        }
    }
    // perform post update action
    entityUpdated(dbEntity);
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) HasDbRevision(org.camunda.bpm.engine.impl.db.HasDbRevision)

Example 9 with DbEntity

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

the class DbOperationManager method sortByReferences.

/**
 * Assumptions:
 * a) all operations in the set work on entities such that the entities implement {@link HasDbReferences}.
 * b) all operations in the set work on the same type (ie. all operations are INSERTs or DELETEs).
 */
protected List<DbEntityOperation> sortByReferences(SortedSet<DbEntityOperation> preSorted) {
    // copy the pre-sorted set and apply final sorting to list
    List<DbEntityOperation> opList = new ArrayList<DbEntityOperation>(preSorted);
    for (int i = 0; i < opList.size(); i++) {
        DbEntityOperation currentOperation = opList.get(i);
        DbEntity currentEntity = currentOperation.getEntity();
        Set<String> currentReferences = currentOperation.getFlushRelevantEntityReferences();
        // check whether this operation must be placed after another operation
        int moveTo = i;
        for (int k = i + 1; k < opList.size(); k++) {
            DbEntityOperation otherOperation = opList.get(k);
            DbEntity otherEntity = otherOperation.getEntity();
            Set<String> otherReferences = otherOperation.getFlushRelevantEntityReferences();
            if (currentOperation.getOperationType() == INSERT) {
                // if we reference the other entity, we need to be inserted after that entity
                if (currentReferences != null && currentReferences.contains(otherEntity.getId())) {
                    moveTo = k;
                    // we can only reference a single entity
                    break;
                }
            } else {
                // if the other entity has a reference to us, we must be placed after the other entity
                if (otherReferences != null && otherReferences.contains(currentEntity.getId())) {
                    moveTo = k;
                // cannot break, there may be another entity further to the right which also references us
                }
            }
        }
        if (moveTo > i) {
            opList.remove(i);
            opList.add(moveTo, currentOperation);
            i--;
        }
    }
    return opList;
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) ArrayList(java.util.ArrayList)

Example 10 with DbEntity

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

the class DbEntityManager method selectOne.

public Object selectOne(String statement, Object parameter) {
    Object result = persistenceSession.selectOne(statement, parameter);
    if (result instanceof DbEntity) {
        DbEntity loadedObject = (DbEntity) result;
        result = cacheFilter(loadedObject);
    }
    return result;
}
Also used : DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) CachedDbEntity(org.camunda.bpm.engine.impl.db.entitymanager.cache.CachedDbEntity) ListQueryParameterObject(org.camunda.bpm.engine.impl.db.ListQueryParameterObject)

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