当插入、更新和删除后,将触发IChangeListener,该监听器内容若有SQL语句,将参与事务,若事务回滚,将全部回滚:

//若在Spring容器内,则不需要手动添加
testService.addChangeListener(new TestChangeListener());
Test test = new Test();
test.setId(100);
test.setName("test");
System.out.println("Name: " + test.getName());
testService.save(test);
test = testService.get(test.getId());
System.out.println("After insert Name: " + test.getName());
testService.update(test);
System.out.println("After update  Name: " + test.getName());
testService.delete(test);

 结果:

注意:本测试直接将监听对象加入Service中,若在Spring容器中,只需将TestChangedListener标记@Service即可。

目录
Copyright © objectsql.com 2021 闽ICP备17009107号-3

闽公网安备 35020302035600号