Skip to content

Commit

Permalink
feat: one transaction is notified only once (jcasbin#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse9527 authored Jun 7, 2024
1 parent d1b6524 commit aef3b87
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main/java/org/casbin/spring/boot/autoconfigure/TxWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

public class TxWatcher implements Watcher {
private final Watcher watcher;
private final AfterCommitExecute afterCommitExecute;

public TxWatcher(Watcher watcher) {
this.watcher = watcher;
this.afterCommitExecute = new AfterCommitExecute(watcher);
}

@Override
Expand All @@ -28,14 +30,22 @@ public void setUpdateCallback(Consumer<String> consumer) {
@Override
public void update() {
if (isActualTransactionActive()) {
registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
watcher.update();
}
});
registerSynchronization(afterCommitExecute);
} else {
watcher.update();
}
}

public static class AfterCommitExecute implements TransactionSynchronization {
private final Watcher watcher;

public AfterCommitExecute(Watcher watcher) {
this.watcher = watcher;
}

@Override
public void afterCommit() {
watcher.update();
}
}
}

0 comments on commit aef3b87

Please sign in to comment.