protected String getExceptionStacktrace() { return ExceptionUtil.getExceptionStacktrace(exception); }
public void saveUser(User user) { try { commandExecutor.execute(new SaveUserCmd(user)); } catch (ProcessEngineException ex) { if (ExceptionUtil.checkConstraintViolationException(ex)) { throw new BadUserRequestException("The user already exists", ex); } throw ex; } }
protected void updateVariables(String executionId, Map<String, ? extends Object> modifications, Collection<String> deletions, boolean local) { try { commandExecutor.execute(new PatchExecutionVariablesCmd(executionId, modifications, deletions, local)); } catch (ProcessEngineException ex) { if (ExceptionUtil.checkValueTooLongException(ex)) { throw new BadUserRequestException("Variable value is too long", ex); } throw ex; } }
public HistoryEvent createHistoricJobLogFailedEvt(Job job, Throwable exception) { HistoricJobLogEventEntity event = (HistoricJobLogEventEntity) createHistoricJobLogEvt(job, HistoryEventTypes.JOB_FAIL); if(exception != null) { // exception message event.setJobExceptionMessage(exception.getMessage()); // stacktrace String exceptionStacktrace = getExceptionStacktrace(exception); byte[] exceptionBytes = toByteArray(exceptionStacktrace); ByteArrayEntity byteArray = createJobExceptionByteArray(exceptionBytes, ResourceTypes.HISTORY); byteArray.setRootProcessInstanceId(event.getRootProcessInstanceId()); if (isHistoryRemovalTimeStrategyStart()) { byteArray.setRemovalTime(event.getRemovalTime()); } event.setExceptionByteArrayId(byteArray.getId()); } return event; }
public static boolean checkConstraintViolationException(ProcessEngineException exception) { List<SQLException> sqlExceptionList = findRelatedSqlExceptions(exception); for (SQLException ex: sqlExceptionList) { if (ex.getMessage().contains("constraint") || ex.getMessage().contains("violat") || ex.getMessage().toLowerCase().contains("duplicate") || ex.getMessage().contains("ORA-00001") || ex.getMessage().contains("SQLCODE=-803, SQLSTATE=23505")) { 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; }
public void setExceptionStacktrace(String exception) { byte[] exceptionBytes = toByteArray(exception); ByteArrayEntity byteArray = getExceptionByteArray(); if(byteArray == null) { byteArray = createJobExceptionByteArray(exceptionBytes, ResourceTypes.RUNTIME); exceptionByteArrayId = byteArray.getId(); exceptionByteArray = byteArray; } else { byteArray.setBytes(exceptionBytes); } }
public static ByteArrayEntity createJobExceptionByteArray(byte[] byteArray, ResourceType type) { return createExceptionByteArray("job.exceptionByteArray", byteArray, type); }
/** * An OptimisticLockingException check for batch processing * * @param operationsToFlush The list of DB operations in which the Exception occurred * @param cause the Exception object * @return The DbOperation where the OptimisticLockingException has occurred * or null if no OptimisticLockingException occurred */ private DbOperation hasOptimisticLockingException(List<DbOperation> operationsToFlush, Throwable cause) { BatchExecutorException batchExecutorException = ExceptionUtil.findBatchExecutorException(cause); if (batchExecutorException != null) { int failedOperationIndex = batchExecutorException.getSuccessfulBatchResults().size(); if (failedOperationIndex < operationsToFlush.size()) { DbOperation failedOperation = operationsToFlush.get(failedOperationIndex); if (isOptimisticLockingException(failedOperation, cause)) { return failedOperation; } } } return null; }
public HistoryEvent createHistoricJobLogFailedEvt(Job job, Throwable exception) { HistoricJobLogEventEntity event = (HistoricJobLogEventEntity) createHistoricJobLogEvt(job, HistoryEventTypes.JOB_FAIL); if(exception != null) { // exception message event.setJobExceptionMessage(exception.getMessage()); // stacktrace String exceptionStacktrace = getExceptionStacktrace(exception); byte[] exceptionBytes = toByteArray(exceptionStacktrace); ByteArrayEntity byteArray = createJobExceptionByteArray(exceptionBytes, ResourceTypes.HISTORY); byteArray.setRootProcessInstanceId(event.getRootProcessInstanceId()); if (isHistoryRemovalTimeStrategyStart()) { byteArray.setRemovalTime(event.getRemovalTime()); } event.setExceptionByteArrayId(byteArray.getId()); } return event; }
public static boolean checkConstraintViolationException(ProcessEngineException exception) { List<SQLException> sqlExceptionList = findRelatedSqlExceptions(exception); for (SQLException ex: sqlExceptionList) { if (ex.getMessage().contains("constraint") || ex.getMessage().contains("violat") || ex.getMessage().toLowerCase().contains("duplicate") || ex.getMessage().contains("ORA-00001") || ex.getMessage().contains("SQLCODE=-803, SQLSTATE=23505")) { 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; }
public void setExceptionStacktrace(String exception) { byte[] exceptionBytes = toByteArray(exception); ByteArrayEntity byteArray = getExceptionByteArray(); if(byteArray == null) { byteArray = createJobExceptionByteArray(exceptionBytes, ResourceTypes.RUNTIME); exceptionByteArrayId = byteArray.getId(); exceptionByteArray = byteArray; } else { byteArray.setBytes(exceptionBytes); } }
public static ByteArrayEntity createJobExceptionByteArray(byte[] byteArray, ResourceType type) { return createExceptionByteArray("job.exceptionByteArray", byteArray, type); }
/** * An OptimisticLockingException check for batch processing * * @param operationsToFlush The list of DB operations in which the Exception occurred * @param cause the Exception object * @return The DbOperation where the OptimisticLockingException has occurred * or null if no OptimisticLockingException occurred */ private DbOperation hasOptimisticLockingException(List<DbOperation> operationsToFlush, Throwable cause) { BatchExecutorException batchExecutorException = ExceptionUtil.findBatchExecutorException(cause); if (batchExecutorException != null) { int failedOperationIndex = batchExecutorException.getSuccessfulBatchResults().size(); if (failedOperationIndex < operationsToFlush.size()) { DbOperation failedOperation = operationsToFlush.get(failedOperationIndex); if (isOptimisticLockingException(failedOperation, cause)) { return failedOperation; } } } return null; }
protected String getExceptionStacktrace() { return ExceptionUtil.getExceptionStacktrace(exception); }
public HistoryEvent createHistoricJobLogFailedEvt(Job job, Throwable exception) { HistoricJobLogEventEntity event = (HistoricJobLogEventEntity) createHistoricJobLogEvt(job, HistoryEventTypes.JOB_FAIL); if(exception != null) { // exception message event.setJobExceptionMessage(exception.getMessage()); // stacktrace String exceptionStacktrace = getExceptionStacktrace(exception); byte[] exceptionBytes = toByteArray(exceptionStacktrace); ByteArrayEntity byteArray = createJobExceptionByteArray(exceptionBytes, ResourceTypes.HISTORY); byteArray.setRootProcessInstanceId(event.getRootProcessInstanceId()); if (isHistoryRemovalTimeStrategyStart()) { byteArray.setRemovalTime(event.getRemovalTime()); } event.setExceptionByteArrayId(byteArray.getId()); } return event; }
public static boolean checkValueTooLongException(ProcessEngineException exception) { List<SQLException> sqlExceptionList = findRelatedSqlExceptions(exception); for (SQLException ex: sqlExceptionList) { if (ex.getMessage().contains("too long") || ex.getMessage().contains("too large") || ex.getMessage().contains("ORA-01461") || ex.getMessage().contains("ORA-01401") || ex.getMessage().contains("data would be truncated") || ex.getMessage().contains("SQLCODE=-302, SQLSTATE=22001")) { return true; } } return false; }
protected void updateVariables(String taskId, Map<String, ? extends Object> modifications, Collection<String> deletions, boolean local) { try { commandExecutor.execute(new PatchTaskVariablesCmd(taskId, modifications, deletions, local)); } catch (ProcessEngineException ex) { if (ExceptionUtil.checkValueTooLongException(ex)) { throw new BadUserRequestException("Variable value is too long", ex); } throw ex; } }
/** * 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; }