public void failedOperation(DbOperation operation) { if (operation instanceof DbEntityOperation) { DbEntityOperation entityOperation = (DbEntityOperation) operation; if(JobEntity.class.isAssignableFrom(entityOperation.getEntityType())) { // could not lock the job -> remove it from list of acquired jobs acquiredJobs.removeJobId(entityOperation.getEntity().getId()); } } }
protected void performEntityOperation(CachedDbEntity cachedDbEntity, DbOperationType type) { DbEntityOperation dbOperation = new DbEntityOperation(); dbOperation.setEntity(cachedDbEntity.getEntity()); dbOperation.setFlushRelevantEntityReferences(cachedDbEntity.getFlushRelevantEntityReferences()); dbOperation.setOperationType(type); dbOperationManager.addOperation(dbOperation); }
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()); }
public boolean addOperation(DbEntityOperation newOperation) { if(newOperation.getOperationType() == INSERT) { return getInsertsForType(newOperation.getEntityType(), true) .add(newOperation); } else if(newOperation.getOperationType() == DELETE) { return getDeletesByType(newOperation.getEntityType(), true) .add(newOperation); } else { // UPDATE return getUpdatesByType(newOperation.getEntityType(), true) .add(newOperation); } }
protected int indexOfEntity(DbEntity entity, List<DbOperation> operations) { for (int i = 0; i < operations.size(); i++) { if(entity == ((DbEntityOperation) operations.get(i)).getEntity()) { return i; } } return -1; }
DbOperation thisOperation = operationIt.next(); thisOperation.setRowsAffected(statementResult); 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 {
@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); operation.setRowsAffected(nrOfRowsDeleted); // 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); }
DbEntity currentEntity = currentOperation.getEntity(); Set<String> currentReferences = currentOperation.getFlushRelevantEntityReferences(); 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) {
public void execute(DelegateExecution execution) throws Exception { String existingId = execution.getId(); // insert an execution referencing the current execution ExecutionEntity newExecution = new ExecutionEntity(); newExecution.setId("someId"); newExecution.setParentId(existingId); DbEntityOperation insertOperation = new DbEntityOperation(); insertOperation.setOperationType(DbOperationType.INSERT); insertOperation.setEntity(newExecution); Context.getCommandContext() .getDbSqlSession() .executeDbOperation(insertOperation); }
public void failedOperation(DbOperation operation) { if (operation instanceof DbEntityOperation) { DbEntityOperation dbEntityOperation = (DbEntityOperation) operation; DbEntity dbEntity = dbEntityOperation.getEntity(); boolean failedOperationEntityInList = false; Iterator<LockedExternalTask> it = tasks.iterator(); while (it.hasNext()) { LockedExternalTask resultTask = it.next(); if (resultTask.getId().equals(dbEntity.getId())) { it.remove(); failedOperationEntityInList = true; break; } } if (!failedOperationEntityInList) { throw LOG.concurrentUpdateDbEntityException(operation); } } } });
DbOperation thisOperation = operationIt.next(); thisOperation.setRowsAffected(statementResult); 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 {
@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); operation.setRowsAffected(nrOfRowsDeleted); // 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); }
DbEntity currentEntity = currentOperation.getEntity(); Set<String> currentReferences = currentOperation.getFlushRelevantEntityReferences(); 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) {
public void execute(DelegateExecution execution) throws Exception { String existingId = execution.getId(); // insert an execution referencing the current execution ExecutionEntity newExecution = new ExecutionEntity(); newExecution.setId("someId"); newExecution.setParentId(existingId); DbEntityOperation insertOperation = new DbEntityOperation(); insertOperation.setOperationType(DbOperationType.INSERT); insertOperation.setEntity(newExecution); Context.getCommandContext() .getDbSqlSession() .executeDbOperation(insertOperation); }
public boolean addOperation(DbEntityOperation newOperation) { if(newOperation.getOperationType() == INSERT) { return getInsertsForType(newOperation.getEntityType(), true) .add(newOperation); } else if(newOperation.getOperationType() == DELETE) { return getDeletesByType(newOperation.getEntityType(), true) .add(newOperation); } else { // UPDATE return getUpdatesByType(newOperation.getEntityType(), true) .add(newOperation); } }
protected void performEntityOperation(CachedDbEntity cachedDbEntity, DbOperationType type) { DbEntityOperation dbOperation = new DbEntityOperation(); dbOperation.setEntity(cachedDbEntity.getEntity()); dbOperation.setFlushRelevantEntityReferences(cachedDbEntity.getFlushRelevantEntityReferences()); dbOperation.setOperationType(type); dbOperationManager.addOperation(dbOperation); }
public void failedOperation(DbOperation operation) { if (operation instanceof DbEntityOperation) { DbEntityOperation entityOperation = (DbEntityOperation) operation; if(JobEntity.class.isAssignableFrom(entityOperation.getEntityType())) { // could not lock the job -> remove it from list of acquired jobs acquiredJobs.removeJobId(entityOperation.getEntity().getId()); } } }
public void failedOperation(DbOperation operation) { if (operation instanceof DbEntityOperation) { DbEntityOperation dbEntityOperation = (DbEntityOperation) operation; DbEntity dbEntity = dbEntityOperation.getEntity(); boolean failedOperationEntityInList = false; Iterator<LockedExternalTask> it = tasks.iterator(); while (it.hasNext()) { LockedExternalTask resultTask = it.next(); if (resultTask.getId().equals(dbEntity.getId())) { it.remove(); failedOperationEntityInList = true; break; } } if (!failedOperationEntityInList) { throw LOG.concurrentUpdateDbEntityException(operation); } } } });
@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); }
@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); operation.setRowsAffected(nrOfRowsDeleted); // 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); }