@@ -232,22 +232,25 @@ private void assertSQL(
232
232
233
233
try {
234
234
entityService .ingestProposal (opContext , batch , false );
235
- List <String > txnLog =
235
+ // First collect all SQL statements that start with "txn[]"
236
+ List <String > allSqlStatements =
236
237
LoggedSql .collect ().stream ()
237
238
.filter (sql -> sql .startsWith ("txn[]" ))
238
- .collect (
239
- ArrayList ::new ,
240
- (ArrayList <String > list , String sql ) -> {
241
- // fold into previous line
242
- if (sql .startsWith ("txn[] -- " )) {
243
- String current = list .get (list .size () - 1 );
244
- list .set (list .size () - 1 , current + "\n " + sql );
245
- } else {
246
- list .add (sql );
247
- }
248
- },
249
- ArrayList ::addAll );
239
+ .collect (Collectors .toList ());
250
240
241
+ // Then process them to fold comments into previous lines
242
+ List <String > txnLog = new ArrayList <>();
243
+ for (String sql : allSqlStatements ) {
244
+ if (sql .startsWith ("txn[] -- " ) && !txnLog .isEmpty ()) {
245
+ // Append this comment to the previous statement
246
+ int lastIndex = txnLog .size () - 1 ;
247
+ String current = txnLog .get (lastIndex );
248
+ txnLog .set (lastIndex , current + "\n " + sql );
249
+ } else {
250
+ // Add as a new statement
251
+ txnLog .add (sql );
252
+ }
253
+ }
251
254
// Get the captured SQL statements
252
255
Map <String , List <String >> statementMap =
253
256
txnLog .stream ()
0 commit comments