Search in sources :

Example 1 with DbOperation

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

the class DbEntityManager method flushDbOperations.

protected void flushDbOperations(List<DbOperation> operationsToFlush) {
    // execute the flush
    for (DbOperation dbOperation : operationsToFlush) {
        boolean doOptimisticLockingException = false;
        try {
            persistenceSession.executeDbOperation(dbOperation);
        } catch (Exception e) {
            // some of the exceptions are considered to be optimistic locking exception
            doOptimisticLockingException = isOptimisticLockingException(dbOperation, e);
            if (!doOptimisticLockingException) {
                throw LOG.flushDbOperationException(operationsToFlush, dbOperation, e);
            }
        }
        if (dbOperation.isFailed() || doOptimisticLockingException) {
            handleOptimisticLockingException(dbOperation);
        }
    }
    if (Context.getProcessEngineConfiguration().isJdbcBatchProcessing()) {
        List<BatchResult> flushResult = new ArrayList<BatchResult>();
        try {
            flushResult = persistenceSession.flushOperations();
        } catch (Exception e) {
            // some of the exceptions are considered to be optimistic locking exception
            DbOperation failedOperation = hasOptimisticLockingException(operationsToFlush, e);
            if (failedOperation == null) {
                throw LOG.flushDbOperationsException(operationsToFlush, e);
            } else {
                handleOptimisticLockingException(failedOperation);
            }
        }
        checkFlushResults(operationsToFlush, flushResult);
    }
}
Also used : DbOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperation) ArrayList(java.util.ArrayList) BatchResult(org.apache.ibatis.executor.BatchResult) BatchExecutorException(org.apache.ibatis.executor.BatchExecutorException)

Example 2 with DbOperation

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

BatchResult (org.apache.ibatis.executor.BatchResult)2 DbOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbOperation)2 ArrayList (java.util.ArrayList)1 BatchExecutorException (org.apache.ibatis.executor.BatchExecutorException)1 DbEntity (org.camunda.bpm.engine.impl.db.DbEntity)1 HasDbRevision (org.camunda.bpm.engine.impl.db.HasDbRevision)1 CachedDbEntity (org.camunda.bpm.engine.impl.db.entitymanager.cache.CachedDbEntity)1 DbEntityOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbEntityOperation)1