16
16
import org .hibernate .engine .jdbc .mutation .spi .Binding ;
17
17
import org .hibernate .engine .jdbc .spi .JdbcServices ;
18
18
import org .hibernate .engine .spi .SharedSessionContractImplementor ;
19
+ import org .hibernate .jdbc .Expectation ;
19
20
import org .hibernate .persister .entity .mutation .EntityMutationTarget ;
20
21
import org .hibernate .persister .entity .mutation .EntityTableMapping ;
21
22
import org .hibernate .persister .entity .mutation .UpdateValuesAnalysis ;
@@ -40,6 +41,8 @@ public class DeleteOrUpsertOperation implements SelfExecutingUpdateOperation {
40
41
41
42
private final OptionalTableUpdate optionalTableUpdate ;
42
43
44
+ private final Expectation expectation = new Expectation .RowCount ();
45
+
43
46
public DeleteOrUpsertOperation (
44
47
EntityMutationTarget mutationTarget ,
45
48
EntityTableMapping tableMapping ,
@@ -123,6 +126,16 @@ private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionCon
123
126
final int rowCount = session .getJdbcCoordinator ().getResultSetReturn ()
124
127
.executeUpdate ( upsertDeleteStatement , statementDetails .getSqlString () );
125
128
MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upsert-deleted from `%s`" , rowCount , tableMapping .getTableName () );
129
+ try {
130
+ expectation .verifyOutcome ( rowCount , upsertDeleteStatement , -1 , statementDetails .getSqlString () );
131
+ }
132
+ catch (SQLException e ) {
133
+ throw jdbcServices .getSqlExceptionHelper ().convert (
134
+ e ,
135
+ "Unable to verify outcome for upsert delete" ,
136
+ statementDetails .getSqlString ()
137
+ );
138
+ }
126
139
}
127
140
finally {
128
141
statementDetails .releaseStatement ( session );
@@ -182,12 +195,23 @@ private void performUpsert(JdbcValueBindings jdbcValueBindings, SharedSessionCon
182
195
final var statementDetails = statementGroup .resolvePreparedStatementDetails ( tableMapping .getTableName () );
183
196
try {
184
197
final PreparedStatement updateStatement = statementDetails .resolveStatement ();
185
- session .getJdbcServices ().getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
198
+ final JdbcServices jdbcServices = session .getJdbcServices ();
199
+ jdbcServices .getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
186
200
jdbcValueBindings .beforeStatement ( statementDetails );
187
201
final int rowCount =
188
202
session .getJdbcCoordinator ().getResultSetReturn ()
189
203
.executeUpdate ( updateStatement , statementDetails .getSqlString () );
190
204
MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upserted into `%s`" , rowCount , tableMapping .getTableName () );
205
+ try {
206
+ expectation .verifyOutcome ( rowCount , updateStatement , -1 , statementDetails .getSqlString () );
207
+ }
208
+ catch (SQLException e ) {
209
+ throw jdbcServices .getSqlExceptionHelper ().convert (
210
+ e ,
211
+ "Unable to verify outcome for upsert" ,
212
+ statementDetails .getSqlString ()
213
+ );
214
+ }
191
215
}
192
216
finally {
193
217
statementDetails .releaseStatement ( session );
0 commit comments