HHH-17688 Make statement release more consistent in mutation delegates

This commit is contained in:
Marco Belladelli 2024-01-29 14:57:59 +01:00 committed by Christian Beikov
parent 0f2e736b6d
commit a71bb28a8a
7 changed files with 46 additions and 28 deletions

View File

@ -125,9 +125,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

@ -67,5 +67,6 @@ public class MutationExecutorSingleNonBatched extends AbstractSingleMutationExec
@Override
public void release() {
// nothing to do - `#performNonBatchedMutation` already releases the statement
assert statementGroup.getSingleStatementDetails().getStatement() == null;
}
}

View File

@ -53,8 +53,21 @@ public abstract class AbstractReturningDelegate extends AbstractGeneratedValuesM
Object entity,
SharedSessionContractImplementor session) {
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );
valueBindings.beforeStatement( statementDetails );
return executeAndExtractReturning( statementDetails.getSqlString(), statementDetails.getStatement(), session );
try {
valueBindings.beforeStatement( statementDetails );
return executeAndExtractReturning(
statementDetails.getSqlString(),
statementDetails.getStatement(),
session
);
}
finally {
if ( statementDetails.getStatement() != null ) {
statementDetails.releaseStatement( session );
}
valueBindings.afterStatement( statementDetails.getMutatingTableDetails() );
session.getJdbcCoordinator().afterStatementExecution();
}
}
@Override
@ -80,7 +93,7 @@ public abstract class AbstractReturningDelegate extends AbstractGeneratedValuesM
}
/**
* @deprecated
* @deprecated No longer used
*/
@Deprecated( forRemoval = true, since = "6.5" )
protected Object executeAndExtract(

View File

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

View File

@ -109,10 +109,10 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate {
jdbcServices.getSqlStatementLogger().logStatement( sql );
final PreparedStatement preparedStatement = statementDetails.resolveStatement();
jdbcValueBindings.beforeStatement( statementDetails );
try {
final PreparedStatement preparedStatement = statementDetails.resolveStatement();
jdbcValueBindings.beforeStatement( statementDetails );
jdbcCoordinator.getResultSetReturn().executeUpdate( preparedStatement, sql );
try {
@ -140,19 +140,20 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate {
}
}
}
finally {
if ( statementDetails.getStatement() != null ) {
statementDetails.releaseStatement( session );
}
jdbcValueBindings.afterStatement( statementDetails.getMutatingTableDetails() );
catch (SQLException e) {
throw jdbcServices.getSqlExceptionHelper().convert(
e,
"Unable to extract generated-keys ResultSet",
sql
);
}
}
catch (SQLException e) {
throw jdbcServices.getSqlExceptionHelper().convert(
e,
"Unable to extract generated-keys ResultSet",
sql
);
finally {
if ( statementDetails.getStatement() != null ) {
statementDetails.releaseStatement( session );
}
jdbcValueBindings.afterStatement( statementDetails.getMutatingTableDetails() );
jdbcCoordinator.afterStatementExecution();
}
}

View File

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

View File

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