Skip to content

Commit aef3b87

Browse files
authored
feat: one transaction is notified only once (#100)
1 parent d1b6524 commit aef3b87

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main/java/org/casbin/spring/boot/autoconfigure/TxWatcher.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
public class TxWatcher implements Watcher {
1212
private final Watcher watcher;
13+
private final AfterCommitExecute afterCommitExecute;
1314

1415
public TxWatcher(Watcher watcher) {
1516
this.watcher = watcher;
17+
this.afterCommitExecute = new AfterCommitExecute(watcher);
1618
}
1719

1820
@Override
@@ -28,14 +30,22 @@ public void setUpdateCallback(Consumer<String> consumer) {
2830
@Override
2931
public void update() {
3032
if (isActualTransactionActive()) {
31-
registerSynchronization(new TransactionSynchronization() {
32-
@Override
33-
public void afterCommit() {
34-
watcher.update();
35-
}
36-
});
33+
registerSynchronization(afterCommitExecute);
3734
} else {
3835
watcher.update();
3936
}
4037
}
38+
39+
public static class AfterCommitExecute implements TransactionSynchronization {
40+
private final Watcher watcher;
41+
42+
public AfterCommitExecute(Watcher watcher) {
43+
this.watcher = watcher;
44+
}
45+
46+
@Override
47+
public void afterCommit() {
48+
watcher.update();
49+
}
50+
}
4151
}

0 commit comments

Comments
 (0)