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();
}
}
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);
}
Aggregations