Search in sources :

Example 1 with HasDbRevision

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

the class DbSqlSession method executeInsertEntity.

protected void executeInsertEntity(String insertStatement, Object parameter) {
    LOG.executeDatabaseOperation("INSERT", parameter);
    sqlSession.insert(insertStatement, parameter);
    // set revision of our copy to 1
    if (parameter instanceof HasDbRevision) {
        HasDbRevision versionedObject = (HasDbRevision) parameter;
        versionedObject.setRevision(1);
    }
}
Also used : HasDbRevision(org.camunda.bpm.engine.impl.db.HasDbRevision)

Example 2 with HasDbRevision

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

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

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

the class DbEntityManager method checkFlushResults.

protected void checkFlushResults(List<DbOperation> operationsToFlush, List<BatchResult> flushResult) {
    int flushResultSize = 0;
    if (flushResult != null && flushResult.size() > 0) {
        LOG.printBatchResults(flushResult);
        // process the batch results to handle Optimistic Lock Exceptions
        Iterator<DbOperation> operationIt = operationsToFlush.iterator();
        for (BatchResult batchResult : flushResult) {
            for (int statementResult : batchResult.getUpdateCounts()) {
                flushResultSize++;
                DbOperation thisOperation = operationIt.next();
                if (thisOperation instanceof DbEntityOperation && ((DbEntityOperation) thisOperation).getEntity() instanceof HasDbRevision && !thisOperation.getOperationType().equals(DbOperationType.INSERT)) {
                    final DbEntity dbEntity = ((DbEntityOperation) thisOperation).getEntity();
                    if (statementResult != 1) {
                        ((DbEntityOperation) thisOperation).setFailed(true);
                        handleOptimisticLockingException(thisOperation);
                    } else {
                        // update revision number in cache
                        if (thisOperation.getOperationType().equals(DbOperationType.UPDATE)) {
                            HasDbRevision versionedObject = (HasDbRevision) dbEntity;
                            versionedObject.setRevision(versionedObject.getRevisionNext());
                        }
                    }
                }
            }
        }
        // this must not happen, but worth checking
        if (operationsToFlush.size() != flushResultSize) {
            LOG.wrongBatchResultsSizeException(operationsToFlush);
        }
    }
}
Also used : DbOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperation) DbEntityOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbEntityOperation) DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) CachedDbEntity(org.camunda.bpm.engine.impl.db.entitymanager.cache.CachedDbEntity) HasDbRevision(org.camunda.bpm.engine.impl.db.HasDbRevision) BatchResult(org.apache.ibatis.executor.BatchResult)

Aggregations

HasDbRevision (org.camunda.bpm.engine.impl.db.HasDbRevision)4 DbEntity (org.camunda.bpm.engine.impl.db.DbEntity)3 BatchResult (org.apache.ibatis.executor.BatchResult)1 CachedDbEntity (org.camunda.bpm.engine.impl.db.entitymanager.cache.CachedDbEntity)1 DbEntityOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbEntityOperation)1 DbOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperation)1