HHH-15082 Correctly propagate the original exception when aborting a JDBC batch fails

Not strictly necessary, but it's related to these changes
and I think it's a good idea.
This commit is contained in:
Yoann Rodière 2022-02-17 14:52:40 +01:00 committed by Sanne Grinovero
parent 8f5c0b7610
commit 5febc70134
3 changed files with 13 additions and 8 deletions

View File

@ -93,8 +93,13 @@ public abstract class AbstractBatchImpl implements Batch {
return sqlStatementLogger; return sqlStatementLogger;
} }
protected void abortBatch() { protected void abortBatch(Exception cause) {
jdbcCoordinator.abortBatch(); try {
jdbcCoordinator.abortBatch();
}
catch (RuntimeException e) {
cause.addSuppressed( e );
}
} }
/** /**

View File

@ -78,12 +78,12 @@ public class BatchingBatch extends AbstractBatchImpl {
currentStatement.addBatch(); currentStatement.addBatch();
} }
catch ( SQLException e ) { catch ( SQLException e ) {
abortBatch(); abortBatch( e );
LOG.debugf( "SQLException escaped proxy", e ); LOG.debugf( "SQLException escaped proxy", e );
throw sqlExceptionHelper().convert( e, "could not perform addBatch", currentStatementSql ); throw sqlExceptionHelper().convert( e, "could not perform addBatch", currentStatementSql );
} }
catch (RuntimeException e) { catch (RuntimeException e) {
abortBatch(); abortBatch( e );
throw e; throw e;
} }
statementPosition++; statementPosition++;
@ -130,12 +130,12 @@ public class BatchingBatch extends AbstractBatchImpl {
checkRowCounts( rowCounts, statement, sql ); checkRowCounts( rowCounts, statement, sql );
} }
catch ( SQLException e ) { catch ( SQLException e ) {
abortBatch(); abortBatch( e );
LOG.unableToExecuteBatch( e, sql ); LOG.unableToExecuteBatch( e, sql );
throw sqlExceptionHelper().convert( e, "could not execute batch", sql ); throw sqlExceptionHelper().convert( e, "could not execute batch", sql );
} }
catch ( RuntimeException re ) { catch ( RuntimeException re ) {
abortBatch(); abortBatch( re );
LOG.unableToExecuteBatch( re, sql ); LOG.unableToExecuteBatch( re, sql );
throw re; throw re;
} }

View File

@ -49,11 +49,11 @@ public class NonBatchingBatch extends AbstractBatchImpl {
jdbcCoordinator.afterStatementExecution(); jdbcCoordinator.afterStatementExecution();
} }
catch ( SQLException e ) { catch ( SQLException e ) {
abortBatch(); abortBatch( e );
throw sqlExceptionHelper().convert( e, "could not execute non-batched batch statement", statementSQL ); throw sqlExceptionHelper().convert( e, "could not execute non-batched batch statement", statementSQL );
} }
catch (RuntimeException e) { catch (RuntimeException e) {
abortBatch(); abortBatch( e );
throw e; throw e;
} }
} }