Record Class EntityChangedEvent

java.lang.Object
java.lang.Record
com.onec.events.EntityChangedEvent
Record Components:
changeType - what happened: created, updated, deleted, posted, unposted, or changed (a coarse "something changed" signal, e.g. register movements after a post).
entityType - the kind of entity: catalog, document, or register.
entityName - the entity's registered logical name (e.g. Properties), or * for a non-specific signal.
id - the affected row's id, or null when not applicable.
naturalKey - the business key that maps the change to an addressable resource — a catalog's code or a document's number (the "slug") — or null if unknown. Carried so listeners can target a specific resource instead of invalidating everything.

public record EntityChangedEvent(String changeType, String entityType, String entityName, UUID id, String naturalKey) extends Record
Published whenever a catalog or document changes, regardless of which write path made the change — the generic REST controllers (raw JDBI) and repository.save(...) (Spring Data JDBC) both emit it, so server-side listeners see every change, not just back-office edits (issues #28, #29).

Consume it with an ordinary Spring @EventListener; the built-in SSE bridge (browser live updates) is just one such listener. Cache/ISR revalidation, search indexing, and outbox relays become trivial listeners:


 @EventListener
 void onChange(EntityChangedEvent event) {
     if ("catalog".equals(event.entityType()) && "Properties".equals(event.entityName())) {
         revalidate("/properties/" + event.naturalKey());   // slug, not just UUID
     }
 }
 
  • Field Details

  • Constructor Details

    • EntityChangedEvent

      public EntityChangedEvent(String changeType, String entityType, String entityName, UUID id, String naturalKey)
      Creates an instance of a EntityChangedEvent record class.
      Parameters:
      changeType - the value for the changeType record component
      entityType - the value for the entityType record component
      entityName - the value for the entityName record component
      id - the value for the id record component
      naturalKey - the value for the naturalKey record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • changeType

      public String changeType()
      Returns the value of the changeType record component.
      Returns:
      the value of the changeType record component
    • entityType

      public String entityType()
      Returns the value of the entityType record component.
      Returns:
      the value of the entityType record component
    • entityName

      public String entityName()
      Returns the value of the entityName record component.
      Returns:
      the value of the entityName record component
    • id

      public UUID id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • naturalKey

      public String naturalKey()
      Returns the value of the naturalKey record component.
      Returns:
      the value of the naturalKey record component