FIX: Flush transaction if it is modified in callback

This commit is contained in:
Roland Praml committed 2022-10-25 10:58:06 +02:00
1 parent 7152cf656b
commit a82ba6d4aa
2 files changed
+24

No files matched your search

@@ -885,6 +885,9 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
public final void preCommit() { public final void preCommit() {
internalBatchFlush(); internalBatchFlush();
firePreCommit(); firePreCommit();
// we must flush the batch queue again, because the callback can
// modify current transaction
internalBatchFlush();
} }
/** /**
@@ -105,4 +105,25 @@ public class JdbcTransactionTest {
assertThat(postCommitCallCount.get()).isEqualTo(2); // postcommit executed twice assertThat(postCommitCallCount.get()).isEqualTo(2); // postcommit executed twice
} }
} }
@Test
public void testFlushInCallback() {
try (Transaction transaction = DB.beginTransaction()) {
transaction.setBatchMode(true);
DB.currentTransaction().register(
new TransactionCallbackAdapter() {
@Override
public void preCommit() {
EBasic basic = new EBasic("binner1");
DB.save(basic);
}
}
);
EBasic basic = new EBasic("bouter1");
DB.save(basic);
transaction.commit(); // transaction will fail if recursive post-commit is failing
}
assertThat(DB.find(EBasic.class).where().eq("name", "binner1").exists()).isTrue();
}
} }