jooq RecordListener 从不捕获 updateEnd 和 updateStart 事件

jooq RecordListener never catch updateEnd and updateStart event

使用 JOOQ 3.9.6 我尝试实现这样的记录监听器:

public class AuditListener extends DefaultRecordListener {

    ....

    @Override
    public void insertEnd(RecordContext ctx) {
        // OK we enter here when inserting a record
    }

    ...

    @Override
    public void updateEnd(RecordContext ctx) {
        // never enter this method when we update a record
    }
}

我们使用更新的 update(...) 和 execute() 通过 DSLContext 更新记录。 AuditListener 永远不会捕获 updateEnd 事件。

这是用于更新记录的存储库:

@Component
public class JooqMyentityRepository extends AbstractJooqRespository<MyentityRecord, Myentity> implements MyentityRepository {

    public JooqMyentityRepository() {
        super(Myentity.class, MYENTITY);
    }

    @Override
    public Myentity findById(Integer myentityId) {
        return dsl.select(MYENTITY.fields()).from(MYENTITY).where(MYENTITY.ID.eq((myentityId))).fetchOneInto(Myentity.class);
    }

    @Override
    @Transactional
    public void update(Myentity myentity) {
        dsl.update(MYENTITY)
            .set(MYENTITY.NAME, myentity.getName())
            .set(MYENTITY.AREA_ID, myentity.getAreaId())
            .set(MYENTITY.ACTIVE, myentity.getActive())
            .set(MYENTITY.BRAND, myentity.getBrand())
            .where(MYENTITY.ID.eq(myentity.getId()))
            .execute();

    }
}

存储库在自定义服务中被调用:

@Component
@Scope(value = "singleton")
public class CustomerService {

    @Autowired
    private MyentityRepository myentityRepository;


    public void editCustomerMyentity(CustomerMyentity customerMyentity){

        Myentity myentity = myentityRepository.findbyId(customerMyentity.getId());
        ...
        // Do treatments here : insert another record to trace the modification
        ...
        myentity.setName(customerMyentity.getName());
        myentity.setBrand(customerMyentity.getBrand());
        myentityRepository.update(myentity);

    }
}

这是个问题还是我遗漏了什么?

RecordListener SPI Javadoc states that it intercepts calls to methods like UpdatableRecord.update().

它无法拦截任意更新调用,例如DSLContext.update() 甚至 DSLContext.execute("UPDATE ..") 因为 jOOQ 不确定数据库中的更新语句将影响多少记录以及哪些记录。除此之外,在您的服务中,DSLContext.update() 语句的生命周期中并没有实际涉及 UpdatableRecord,那么您期望对 updateEnd() 进行什么样的 SPI 调用?