Lifecycle Event Behavior

Lifecycle events are used to perform heuristic data manipulations and/or business logic that applies to your business logic. This contains an example of the behavior of how it can be used to interact with your data model.

You can download the code for this example here:

OnyxDevTools/onyx-database-samples/lifecycle-events.

  1. Define a simple BeverageEffect entity

    The BeverageEffect is a simple entity used to demonstrate how lifecycle events can be used to manipulate it.

  2. Create a simple enum to contain basic constants regarding beverage effects
    Notes:
    Not everyone who consumes beer is annoying.
    This tutorial was written while on an airplane.
  3. Apply some lifecycle events in the BeverageEffect class.

    The BeverageEffect is a simple entity used to demonstrate how lifecycle events can be used to manipulate it.

    Notes:
    The lifecycle events are defined in the same class as the entity.
    Here we have defined different methods for @PreInsert, @PreUpdate, and @PostRemove. Onyx is flexible enough to use multiple annotations on one method if you wanted to.
  4. Observe the Behavior

    Watch the behavior of the lifecycle events as you save, update, and delete the BeverageEffect entity.

    Notes:
    After inserting the entity, the description is defaulted to Beverage.WATER.preConsumption.
    Updating the entity will change the description to the Beverage.WATER.duringConsumption value.
    Finally, deleting an entity will update the description again to Beverage.WATER.afterConsumption.
  5. Query Change Listeners