Search in sources :

Example 1 with BatchExecutorException

use of org.apache.ibatis.executor.BatchExecutorException in project JavaForFun by gumartinm.

the class ReuseBatchExecutor method doFlushStatements.

@Override
public List<BatchResult> doFlushStatements(boolean isRollback) throws SQLException {
    try {
        final List<BatchResult> results = new ArrayList<>();
        if (isRollback) {
            return Collections.emptyList();
        } else {
            long count = 0;
            for (Map.Entry<String, Statement> entry : statementMap.entrySet()) {
                final Statement stmt = entry.getValue();
                final String sql = entry.getKey();
                final BatchResult batchResult = batchResultMap.get(sql);
                if (batchResult != null) {
                    try {
                        batchResult.setUpdateCounts(stmt.executeBatch());
                        MappedStatement ms = batchResult.getMappedStatement();
                        List<Object> parameterObjects = batchResult.getParameterObjects();
                        KeyGenerator keyGenerator = ms.getKeyGenerator();
                        if (Jdbc3KeyGenerator.class.equals(keyGenerator.getClass())) {
                            Jdbc3KeyGenerator jdbc3KeyGenerator = (Jdbc3KeyGenerator) keyGenerator;
                            jdbc3KeyGenerator.processBatch(ms, stmt, parameterObjects);
                        } else if (!NoKeyGenerator.class.equals(keyGenerator.getClass())) {
                            // issue #141
                            for (Object parameter : parameterObjects) {
                                keyGenerator.processAfter(this, ms, stmt, parameter);
                            }
                        }
                    } catch (BatchUpdateException e) {
                        StringBuilder message = new StringBuilder();
                        message.append(batchResult.getMappedStatement().getId()).append(" (batch index #").append(count + 1).append(")").append(" failed.");
                        if (count > 0) {
                            message.append(" ").append(count).append(" prior sub executor(s) completed successfully, but will be rolled back.");
                        }
                        throw new BatchExecutorException(message.toString(), e, results, batchResult);
                    }
                    results.add(batchResult);
                }
                count = count + 1;
            }
            return results;
        }
    } finally {
        for (Statement stmt : statementMap.values()) {
            closeStatement(stmt);
        }
        statementMap.clear();
        batchResultMap.clear();
    }
}
Also used : MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) BatchExecutorException(org.apache.ibatis.executor.BatchExecutorException) BatchResult(org.apache.ibatis.executor.BatchResult) Jdbc3KeyGenerator(org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator) MappedStatement(org.apache.ibatis.mapping.MappedStatement) HashMap(java.util.HashMap) Map(java.util.Map) NoKeyGenerator(org.apache.ibatis.executor.keygen.NoKeyGenerator) Jdbc3KeyGenerator(org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator) KeyGenerator(org.apache.ibatis.executor.keygen.KeyGenerator) BatchUpdateException(java.sql.BatchUpdateException)

Example 2 with BatchExecutorException

use of org.apache.ibatis.executor.BatchExecutorException in project camunda-bpm-platform by camunda.

the class EnginePersistenceLogger method flushDbOperationsException.

public ProcessEngineException flushDbOperationsException(List<DbOperation> operationsToFlush, Throwable cause) {
    String message = cause.getMessage();
    // collect real SQL exception messages in case of batch processing
    Throwable exCause = cause;
    do {
        if (exCause instanceof BatchExecutorException) {
            final List<SQLException> relatedSqlExceptions = ExceptionUtil.findRelatedSqlExceptions(exCause);
            StringBuffer sb = new StringBuffer();
            for (SQLException sqlException : relatedSqlExceptions) {
                sb.append(sqlException).append("\n");
            }
            message = message + "\n" + sb.toString();
        }
        exCause = exCause.getCause();
    } while (exCause != null);
    String exceptionMessage = exceptionMessage("083", "Exception while executing Batch Database Operations with message '{}'. Flush summary: \n {}", message, buildStringFromList(operationsToFlush));
    return new ProcessEngineException(exceptionMessage, cause);
}
Also used : SQLException(java.sql.SQLException) BatchExecutorException(org.apache.ibatis.executor.BatchExecutorException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

BatchExecutorException (org.apache.ibatis.executor.BatchExecutorException)2 BatchUpdateException (java.sql.BatchUpdateException)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BatchResult (org.apache.ibatis.executor.BatchResult)1 Jdbc3KeyGenerator (org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator)1 KeyGenerator (org.apache.ibatis.executor.keygen.KeyGenerator)1 NoKeyGenerator (org.apache.ibatis.executor.keygen.NoKeyGenerator)1 MappedStatement (org.apache.ibatis.mapping.MappedStatement)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1