@@ -69,8 +69,8 @@ void testFind(SessionFactoryScope factoryScope) {
69
69
assertThat ( Hibernate .isInitialized ( theTalisman ) ).isTrue ();
70
70
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
71
71
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), BOOKS );
72
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
73
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , false );
72
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
73
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , false );
74
74
} );
75
75
}
76
76
@@ -85,9 +85,9 @@ void testFindWithExtended(SessionFactoryScope factoryScope) {
85
85
assertThat ( Hibernate .isInitialized ( theTalisman ) ).isTrue ();
86
86
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
87
87
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), BOOKS );
88
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
88
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
89
89
// For strict compliance, EXTENDED here should lock `book_genres` but we do not
90
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , false );
90
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , false );
91
91
} );
92
92
}
93
93
@@ -103,8 +103,8 @@ void testFindWithExtendedJpaExpectation(SessionFactoryScope factoryScope) {
103
103
// these 2 assertions would depend a bit on the approach and/or dialect
104
104
// assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 );
105
105
// Helper.checkSql( sqlCollector.getSqlQueries().get( 0 ), session.getDialect(), Helper.Table.BOOK_GENRES );
106
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
107
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , true );
106
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
107
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , true );
108
108
} );
109
109
}
110
110
@@ -131,8 +131,8 @@ void testFindWithExtendedAndFetch(SessionFactoryScope factoryScope) {
131
131
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
132
132
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), BOOKS , BOOK_GENRES );
133
133
134
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
135
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , true );
134
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
135
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , true );
136
136
}
137
137
else {
138
138
// should be 3, but follow-on locking is not locking collection tables...
@@ -142,7 +142,7 @@ void testFindWithExtendedAndFetch(SessionFactoryScope factoryScope) {
142
142
143
143
// todo : track this down - HHH-19513
144
144
//Helper.checkSql( sqlCollector.getSqlQueries().get( 2 ), session.getDialect(), BOOK_GENRES );
145
- //TransactionUtil.updateTable ( factoryScope, BOOK_GENRES.getTableName(), "genre", true );
145
+ //TransactionUtil.assertRowLock ( factoryScope, BOOK_GENRES.getTableName(), "genre", "book_fk", theTalisman.getId() , true );
146
146
}
147
147
} );
148
148
}
@@ -161,8 +161,8 @@ void testLock(SessionFactoryScope factoryScope) {
161
161
162
162
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), BOOKS );
163
163
164
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
165
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , false );
164
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
165
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , false );
166
166
} );
167
167
}
168
168
@@ -178,9 +178,9 @@ void testLockWithExtended(SessionFactoryScope factoryScope) {
178
178
session .lock ( theTalisman , PESSIMISTIC_WRITE , EXTENDED );
179
179
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
180
180
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), BOOKS );
181
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
181
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
182
182
// Again, for strict compliance, EXTENDED here should lock `book_genres` but we do not
183
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , false );
183
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , false );
184
184
} );
185
185
}
186
186
@@ -196,8 +196,8 @@ void testRefresh(SessionFactoryScope factoryScope) {
196
196
session .refresh ( theTalisman , PESSIMISTIC_WRITE );
197
197
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
198
198
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), BOOKS );
199
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
200
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , false );
199
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
200
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , false );
201
201
} );
202
202
}
203
203
@@ -213,9 +213,9 @@ void testRefreshWithExtended(SessionFactoryScope factoryScope) {
213
213
session .refresh ( theTalisman , PESSIMISTIC_WRITE , EXTENDED );
214
214
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
215
215
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), BOOKS );
216
- TransactionUtil .updateTable ( factoryScope , BOOKS .getTableName (), "title" , true );
216
+ TransactionUtil .assertRowLock ( factoryScope , BOOKS .getTableName (), "title" , "id" , theTalisman . getId () , true );
217
217
// Again, for strict compliance, EXTENDED here should lock `book_genres` but we do not
218
- TransactionUtil .updateTable ( factoryScope , BOOK_GENRES .getTableName (), "genre" , false );
218
+ TransactionUtil .assertRowLock ( factoryScope , BOOK_GENRES .getTableName (), "genre" , "book_fk" , theTalisman . getId () , false );
219
219
} );
220
220
}
221
221
@@ -226,12 +226,12 @@ void testEagerFind(SessionFactoryScope factoryScope) {
226
226
227
227
factoryScope .inTransaction ( (session ) -> {
228
228
sqlCollector .clear ();
229
- session .find ( Report .class , 2 , PESSIMISTIC_WRITE );
229
+ final Report report = session .find ( Report .class , 2 , PESSIMISTIC_WRITE );
230
230
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
231
231
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), REPORTS );
232
- TransactionUtil .updateTable ( factoryScope , REPORTS .getTableName (), "title" , true );
233
- TransactionUtil .updateTable ( factoryScope , REPORT_LABELS .getTableName (), "txt" , willAggressivelyLockJoinedTables ( session .getDialect () ) );
234
- TransactionUtil .updateTable ( factoryScope , PERSONS .getTableName (), "name" , willAggressivelyLockJoinedTables ( session .getDialect () ) );
232
+ TransactionUtil .assertRowLock ( factoryScope , REPORTS .getTableName (), "title" , "id" , report . getId () , true );
233
+ TransactionUtil .assertRowLock ( factoryScope , REPORT_LABELS .getTableName (), "txt" , "report_fk" , report . getId () , willAggressivelyLockJoinedTables ( session .getDialect () ) );
234
+ TransactionUtil .assertRowLock ( factoryScope , PERSONS .getTableName (), "name" , "id" , report . getReporter (). getId () , willAggressivelyLockJoinedTables ( session .getDialect () ) );
235
235
} );
236
236
}
237
237
@@ -258,28 +258,29 @@ void testEagerFindWithExtended(SessionFactoryScope factoryScope) {
258
258
259
259
factoryScope .inTransaction ( (session ) -> {
260
260
sqlCollector .clear ();
261
- session .find ( Report .class , 2 , PESSIMISTIC_WRITE , EXTENDED );
261
+ final Report report = session .find ( Report .class , 2 , PESSIMISTIC_WRITE , EXTENDED );
262
262
if ( session .getDialect ().supportsOuterJoinForUpdate () ) {
263
263
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
264
264
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), REPORTS , REPORT_LABELS );
265
- TransactionUtil .updateTable ( factoryScope , REPORTS .getTableName (), "title" , true );
266
- TransactionUtil .updateTable ( factoryScope , PERSONS .getTableName (), "name" , willAggressivelyLockJoinedTables ( session .getDialect () ) );
267
- TransactionUtil .updateTable ( factoryScope , REPORT_LABELS .getTableName (), "txt" , true );
265
+ TransactionUtil .assertRowLock ( factoryScope , REPORTS .getTableName (), "title" , "id" , report .getId (), true );
266
+ TransactionUtil .assertRowLock ( factoryScope , PERSONS .getTableName (), "name" , "id" , report .getReporter ().getId (),
267
+ willAggressivelyLockJoinedTables ( session .getDialect () ) );
268
+ TransactionUtil .assertRowLock ( factoryScope , REPORT_LABELS .getTableName (), "txt" , "report_fk" , report .getId (), true );
268
269
}
269
270
else {
270
271
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 3 );
271
272
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 1 ), session .getDialect (), REPORTS );
272
273
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 2 ), session .getDialect (), PERSONS );
273
- TransactionUtil .updateTable ( factoryScope , REPORTS .getTableName (), "title" , true );
274
+ TransactionUtil .assertRowLock ( factoryScope , REPORTS .getTableName (), "title" , "id" , report . getId () , true );
274
275
275
276
// these should happen but currently do not - follow-on locking is not locking element-collection tables...
276
277
// todo : track this down - HHH-19513
277
278
//Helper.checkSql( sqlCollector.getSqlQueries().get( 2 ), session.getDialect(), REPORT_LABELS );
278
- //TransactionUtil.updateTable ( factoryScope, REPORT_LABELS.getTableName(), "txt", true );
279
+ //TransactionUtil.assertRowLock ( factoryScope, REPORT_LABELS.getTableName(), "txt", "report_fk", report.getId() , true );
279
280
280
281
// this one should not happen at all. follow-on locking is not understanding scope probably..
281
282
// todo : track this down - HHH-19514
282
- TransactionUtil .updateTable ( factoryScope , PERSONS .getTableName (), "name" , true );
283
+ TransactionUtil .assertRowLock ( factoryScope , PERSONS .getTableName (), "name" , "id" , report . getReporter (). getId (), true );
283
284
}
284
285
} );
285
286
}
@@ -292,29 +293,29 @@ void testEagerFindWithFetchScope(SessionFactoryScope factoryScope) {
292
293
293
294
factoryScope .inTransaction ( (session ) -> {
294
295
sqlCollector .clear ();
295
- session .find ( Report .class , 2 , PESSIMISTIC_WRITE , Locking .Scope .INCLUDE_FETCHES );
296
+ final Report report = session .find ( Report .class , 2 , PESSIMISTIC_WRITE , Locking .Scope .INCLUDE_FETCHES );
296
297
297
298
if ( session .getDialect ().supportsOuterJoinForUpdate () ) {
298
299
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 1 );
299
300
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 0 ), session .getDialect (), REPORTS , REPORT_LABELS , JOINED_REPORTER );
300
- TransactionUtil .updateTable ( factoryScope , REPORTS .getTableName (), "title" , true );
301
- TransactionUtil .updateTable ( factoryScope , PERSONS .getTableName (), "name" , true );
302
- TransactionUtil .updateTable ( factoryScope , REPORT_LABELS .getTableName (), "txt" , true );
301
+ TransactionUtil .assertRowLock ( factoryScope , REPORTS .getTableName (), "title" , "id" , report . getId () , true );
302
+ TransactionUtil .assertRowLock ( factoryScope , PERSONS .getTableName (), "name" , "id" , report . getReporter (). getId (), true );
303
+ TransactionUtil .assertRowLock ( factoryScope , REPORT_LABELS .getTableName (), "txt" , "report_fk" , report . getId () , true );
303
304
}
304
305
else {
305
306
assertThat ( sqlCollector .getSqlQueries () ).hasSize ( 3 );
306
307
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 1 ), session .getDialect (), REPORTS );
307
308
Helper .checkSql ( sqlCollector .getSqlQueries ().get ( 2 ), session .getDialect (), PERSONS );
308
- TransactionUtil .updateTable ( factoryScope , REPORTS .getTableName (), "title" , true );
309
+ TransactionUtil .assertRowLock ( factoryScope , REPORTS .getTableName (), "title" , "id" , report . getId () , true );
309
310
310
311
// these should happen but currently do not - follow-on locking is not locking element-collection tables...
311
312
// todo : track this down - HHH-19513
312
313
//Helper.checkSql( sqlCollector.getSqlQueries().get( 2 ), session.getDialect(), REPORT_LABELS );
313
- //TransactionUtil.updateTable ( factoryScope, REPORT_LABELS.getTableName(), "txt", true );
314
+ //TransactionUtil.assertRowLock ( factoryScope, REPORT_LABELS.getTableName(), "txt", "report_fk", report.getId() , true );
314
315
315
316
// this one should not happen at all. follow-on locking is not understanding scope probably..
316
317
// todo : track this down - HHH-19514
317
- TransactionUtil .updateTable ( factoryScope , PERSONS .getTableName (), "name" , true );
318
+ TransactionUtil .assertRowLock ( factoryScope , PERSONS .getTableName (), "name" , "id" , report . getReporter (). getId (), true );
318
319
}
319
320
} );
320
321
}
0 commit comments