2020import org .hibernate .engine .jdbc .mutation .internal .PreparedStatementGroupSingleTable ;
2121import org .hibernate .engine .jdbc .mutation .spi .Binding ;
2222import org .hibernate .engine .jdbc .mutation .spi .BindingGroup ;
23+ import org .hibernate .engine .jdbc .spi .JdbcServices ;
2324import org .hibernate .engine .spi .SharedSessionContractImplementor ;
25+ import org .hibernate .jdbc .Expectation ;
2426import org .hibernate .persister .entity .mutation .EntityMutationTarget ;
2527import org .hibernate .persister .entity .mutation .EntityTableMapping ;
2628import org .hibernate .persister .entity .mutation .UpdateValuesAnalysis ;
@@ -46,6 +48,7 @@ public class DeleteOrUpsertOperation implements SelfExecutingUpdateOperation {
4648
4749 private final OptionalTableUpdate optionalTableUpdate ;
4850
51+ private final Expectation expectation = new Expectation .RowCount ();
4952
5053 public DeleteOrUpsertOperation (
5154 EntityMutationTarget mutationTarget ,
@@ -118,7 +121,8 @@ private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionCon
118121
119122 try {
120123 final PreparedStatement upsertDeleteStatement = statementDetails .resolveStatement ();
121- session .getJdbcServices ().getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
124+ final JdbcServices jdbcServices = session .getJdbcServices ();
125+ jdbcServices .getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
122126
123127 bindDeleteKeyValues (
124128 jdbcValueBindings ,
@@ -130,6 +134,16 @@ private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionCon
130134 final int rowCount = session .getJdbcCoordinator ().getResultSetReturn ()
131135 .executeUpdate ( upsertDeleteStatement , statementDetails .getSqlString () );
132136 MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upsert-deleted from `%s`" , rowCount , tableMapping .getTableName () );
137+ try {
138+ expectation .verifyOutcome ( rowCount , upsertDeleteStatement , -1 , statementDetails .getSqlString () );
139+ }
140+ catch (SQLException e ) {
141+ throw jdbcServices .getSqlExceptionHelper ().convert (
142+ e ,
143+ "Unable to verify outcome for upsert delete" ,
144+ statementDetails .getSqlString ()
145+ );
146+ }
133147 }
134148 finally {
135149 statementDetails .releaseStatement ( session );
@@ -197,14 +211,24 @@ private void performUpsert(JdbcValueBindings jdbcValueBindings, SharedSessionCon
197211
198212 try {
199213 final PreparedStatement updateStatement = statementDetails .resolveStatement ();
200- session .getJdbcServices (). getSqlStatementLogger (). logStatement ( statementDetails . getSqlString () );
201-
214+ final JdbcServices jdbcServices = session .getJdbcServices ();
215+ jdbcServices . getSqlStatementLogger (). logStatement ( statementDetails . getSqlString () );
202216 jdbcValueBindings .beforeStatement ( statementDetails );
203217
204218 final int rowCount = session .getJdbcCoordinator ().getResultSetReturn ()
205219 .executeUpdate ( updateStatement , statementDetails .getSqlString () );
206220
207221 MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upserted into `%s`" , rowCount , tableMapping .getTableName () );
222+ try {
223+ expectation .verifyOutcome ( rowCount , updateStatement , -1 , statementDetails .getSqlString () );
224+ }
225+ catch (SQLException e ) {
226+ throw jdbcServices .getSqlExceptionHelper ().convert (
227+ e ,
228+ "Unable to verify outcome for upsert" ,
229+ statementDetails .getSqlString ()
230+ );
231+ }
208232 }
209233 finally {
210234 statementDetails .releaseStatement ( session );
0 commit comments