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 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 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 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 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; }
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); } } } });
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); } } } });
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();
@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); }
@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); }
/** * Checks if the reason for a persistence exception was the foreign-key referencing of a (currently) * non-existing entity. This might happen with concurrent transactions, leading to an * OptimisticLockingException. * * @param failedOperation * @return */ private boolean isOptimisticLockingException(DbOperation failedOperation, Throwable cause) { boolean isConstraintViolation = ExceptionUtil.checkForeignKeyConstraintViolation(cause); boolean isVariableIntegrityViolation = ExceptionUtil.checkVariableIntegrityViolation(cause); if (isVariableIntegrityViolation) { return true; } else if ( isConstraintViolation && failedOperation instanceof DbEntityOperation && ((DbEntityOperation) failedOperation).getEntity() instanceof HasDbReferences && (failedOperation.getOperationType().equals(DbOperationType.INSERT) || failedOperation.getOperationType().equals(DbOperationType.UPDATE)) ) { DbEntity entity = ((DbEntityOperation) failedOperation).getEntity(); for (Map.Entry<String, Class> reference : ((HasDbReferences)entity).getReferencedEntitiesIdAndClass().entrySet()) { DbEntity referencedEntity = this.persistenceSession.selectById(reference.getValue(), reference.getKey()); if (referencedEntity == null) { return true; } } } return false; }
/** * Checks if the reason for a persistence exception was the foreign-key referencing of a (currently) * non-existing entity. This might happen with concurrent transactions, leading to an * OptimisticLockingException. * * @param failedOperation * @return */ private boolean isOptimisticLockingException(DbOperation failedOperation, Throwable cause) { boolean isConstraintViolation = ExceptionUtil.checkForeignKeyConstraintViolation(cause); boolean isVariableIntegrityViolation = ExceptionUtil.checkVariableIntegrityViolation(cause); if (isVariableIntegrityViolation) { return true; } else if ( isConstraintViolation && failedOperation instanceof DbEntityOperation && ((DbEntityOperation) failedOperation).getEntity() instanceof HasDbReferences && (failedOperation.getOperationType().equals(DbOperationType.INSERT) || failedOperation.getOperationType().equals(DbOperationType.UPDATE)) ) { DbEntity entity = ((DbEntityOperation) failedOperation).getEntity(); for (Map.Entry<String, Class> reference : ((HasDbReferences)entity).getReferencedEntitiesIdAndClass().entrySet()) { DbEntity referencedEntity = this.persistenceSession.selectById(reference.getValue(), reference.getKey()); if (referencedEntity == null) { return true; } } } return false; }
@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); }
@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); }
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);
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);
protected void handleOptimisticLockingException(DbOperation dbOperation) { boolean isHandled = false; if(optimisticLockingListeners != null) { for (OptimisticLockingListener optimisticLockingListener : optimisticLockingListeners) { if(optimisticLockingListener.getEntityType() == null || optimisticLockingListener.getEntityType().isAssignableFrom(dbOperation.getEntityType())) { optimisticLockingListener.failedOperation(dbOperation); isHandled = true; } } } if (!isHandled && Context.getProcessEngineConfiguration().isSkipHistoryOptimisticLockingExceptions()) { DbEntity dbEntity = ((DbEntityOperation) dbOperation).getEntity(); if (dbEntity instanceof HistoricEntity || isHistoricByteArray(dbEntity)) { isHandled = true; } } if(!isHandled) { throw LOG.concurrentUpdateDbEntityException(dbOperation); } }
protected void handleOptimisticLockingException(DbOperation dbOperation) { boolean isHandled = false; if(optimisticLockingListeners != null) { for (OptimisticLockingListener optimisticLockingListener : optimisticLockingListeners) { if(optimisticLockingListener.getEntityType() == null || optimisticLockingListener.getEntityType().isAssignableFrom(dbOperation.getEntityType())) { optimisticLockingListener.failedOperation(dbOperation); isHandled = true; } } } if (!isHandled && Context.getProcessEngineConfiguration().isSkipHistoryOptimisticLockingExceptions()) { DbEntity dbEntity = ((DbEntityOperation) dbOperation).getEntity(); if (dbEntity instanceof HistoricEntity || isHistoricByteArray(dbEntity)) { isHandled = true; } } if(!isHandled) { throw LOG.concurrentUpdateDbEntityException(dbOperation); } }
@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 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); }