A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/objectify/objectify/wiki/LifecycleCallbacks below:

LifecycleCallbacks · objectify/objectify Wiki · GitHub

Objectify supports two lifecycle callbacks: @OnLoad and @OnSave. If you mark methods on your POJO entity or embedded class (or any superclasses) with these annotations, they will be called:

You can have any number of these callback methods in your POJO class or its superclasses. They will be called in order of declaration, with superclass methods called first.

class MyEntityBase {
    String foo;
    String lowercaseFoo;
    @OnSave void maintainCaseInsensitiveSearchField() { this.lowercaseFoo = foo.toLowerCase(); }
}

class MyEntity extends MyEntityBase {
    @Id Long id;

    @Ignore Date loaded;
    @OnLoad void trackLoadedDate() { this.loaded = new Date(); }

    List<String> stuff = new ArrayList<String>();
    int stuffSize;   // indexed so we can query by list size
    @OnSave void maintainStuffSize() { this.stuffSize = stuff.size(); }
}

Caution: You can't update @Id or @Parent fields in a @OnSave callback.

Also: If you load an entity multiple times in the same session, the @OnLoad callback will be called only once - subsequent loads just retrieve the POJO from the session cache.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4