HHH-17688 Make statement release more consistent in mutation delegates

This commit is contained in:
Marco Belladelli 2024-01-29 14:13:28 +01:00 committed by Christian Beikov
parent 02fa42d90c
commit 9f3676d690
8 changed files with 50 additions and 26 deletions

View File

@ -99,9 +99,10 @@ public abstract class AbstractMutationExecutor implements MutationExecutor {
// If we get here the statement is needed - make sure it is resolved
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );
valueBindings.beforeStatement( statementDetails );
try {
valueBindings.beforeStatement( statementDetails );
final int affectedRowCount = session.getJdbcCoordinator()
.getResultSetReturn()
.executeUpdate( statementDetails.getStatement(), statementDetails.getSqlString() );

View File

@ -204,9 +204,10 @@ public class MutationExecutorPostInsert implements MutationExecutor, JdbcValueBi
);
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );
valueBindings.beforeStatement( statementDetails );
try {
valueBindings.beforeStatement( statementDetails );
final int affectedRowCount = session.getJdbcCoordinator()
.getResultSetReturn()
.executeUpdate( statementDetails.getStatement(), statementDetails.getSqlString() );
@ -224,6 +225,8 @@ public class MutationExecutorPostInsert implements MutationExecutor, JdbcValueBi
@Override
public void release() {
// The mutation delegate already releases the identity insert statement
assert identityInsertStatementDetails.getStatement() == null;
secondaryTablesStatementGroup.release();
}

View File

@ -112,7 +112,8 @@ public class MutationExecutorPostInsertSingleTable implements MutationExecutor,
@Override
public void release() {
identityInsertStatementDetails.releaseStatement( session );
// Nothing to do - the mutation delegate already releases the identity insert statement
assert identityInsertStatementDetails.getStatement() == null;
}
@Override

View File

@ -38,8 +38,21 @@ public abstract class AbstractReturningDelegate implements InsertGeneratedIdenti
Object entity,
SharedSessionContractImplementor session) {
session.getJdbcServices().getSqlStatementLogger().logStatement( insertStatementDetails.getSqlString() );
valueBindings.beforeStatement( insertStatementDetails );
return executeAndExtract( insertStatementDetails.getSqlString(), insertStatementDetails.getStatement(), session );
try {
valueBindings.beforeStatement( insertStatementDetails );
return executeAndExtract(
insertStatementDetails.getSqlString(),
insertStatementDetails.getStatement(),
session
);
}
finally {
if ( insertStatementDetails.getStatement() != null ) {
insertStatementDetails.releaseStatement( session );
}
valueBindings.afterStatement( insertStatementDetails.getMutatingTableDetails() );
session.getJdbcCoordinator().afterStatementExecution();
}
}
@Override

View File

@ -70,10 +70,19 @@ public abstract class AbstractSelectingDelegate implements InsertGeneratedIdenti
final JdbcServices jdbcServices = session.getJdbcServices();
jdbcServices.getSqlStatementLogger().logStatement( insertStatementDetails.getSqlString() );
jdbcValueBindings.beforeStatement( insertStatementDetails );
jdbcCoordinator.getResultSetReturn()
.executeUpdate( insertStatementDetails.resolveStatement(), insertStatementDetails.getSqlString() );
try {
jdbcValueBindings.beforeStatement( insertStatementDetails );
jdbcCoordinator.getResultSetReturn()
.executeUpdate( insertStatementDetails.resolveStatement(), insertStatementDetails.getSqlString() );
}
finally {
if ( insertStatementDetails.getStatement() != null ) {
insertStatementDetails.releaseStatement( session );
}
jdbcValueBindings.afterStatement( insertStatementDetails.getMutatingTableDetails() );
session.getJdbcCoordinator().afterStatementExecution();
}
// the insert is complete, select the generated id...

View File

@ -100,10 +100,10 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate {
jdbcServices.getSqlStatementLogger().logStatement( insertSql );
final PreparedStatement insertStatement = insertStatementDetails.resolveStatement();
jdbcValueBindings.beforeStatement( insertStatementDetails );
try {
final PreparedStatement insertStatement = insertStatementDetails.resolveStatement();
jdbcValueBindings.beforeStatement( insertStatementDetails );
jdbcCoordinator.getResultSetReturn().executeUpdate( insertStatement, insertSql );
try {
@ -131,16 +131,20 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate {
}
}
}
finally {
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( insertStatement );
catch (SQLException e) {
throw jdbcServices.getSqlExceptionHelper().convert(
e,
"Unable to extract generated-keys ResultSet",
insertSql
);
}
}
catch (SQLException e) {
throw jdbcServices.getSqlExceptionHelper().convert(
e,
"Unable to extract generated-keys ResultSet",
insertSql
);
finally {
if ( insertStatementDetails.getStatement() != null ) {
insertStatementDetails.releaseStatement( session );
}
jdbcValueBindings.afterStatement( insertStatementDetails.getMutatingTableDetails() );
jdbcCoordinator.afterStatementExecution();
}
}

View File

@ -77,9 +77,6 @@ public class InsertReturningDelegate extends AbstractReturningDelegate {
insertSql
);
}
finally {
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( resultSet, insertStatement );
}
}
@Override

View File

@ -73,9 +73,5 @@ public class SybaseJConnGetGeneratedKeysDelegate extends GetGeneratedKeysDelegat
insertSql
);
}
finally {
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( resultSet, insertStatement );
jdbcCoordinator.afterStatementExecution();
}
}
}