Description
tl;dr: Is there any way of determining whether a DAO entity is being inserted, deleted or updated in the current transaction?
Context: I am maintaining an entity change tracker that needs to detect:
- every insert (table, entity id)
- every update (table, entity id, updated column, previous and current values)
- every delete (table, entity id)
Leveraging Exposed's EntityHooks I get notified about the inserts and deletes but the updates get flushed before I am able to extract the updated values from writeValues and readValues. See the source.
This has lead me to extract the changes by overriding the entity flush function and log the changes before forwarding to the original flush, but then I cannot differentiate between updated and inserted entities. My best bet currently is to access the internal isNewEntity function via reflection.
Hence the question: is there any recommended way I can determine entity state? Or is there some other less convoluted approach I can take to implement my change tracker?
Activity