Skip to content

Any way to determine entity state? #1711

Open
@icguy

Description

@icguy

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions