by Eabin 14 Jul 08:05
Bean Events

Hi Rob.

Long time, no see - everything is working nicely here ;)

But today I got another idea: Events for db-beans.

What I want to do is have a Entity bean, which has methods like this:

@OnPreSave
public void onPreSave() {
if ( x < y ) throw new IllegalStateException(....);
}

@OnLoaded
public void onLoaded() {
calculateDistances();
}

is there any way to do this yet?

best regards,
-erwin

19 Jul 10:03
by Rob

Yes. In com.avaje.ebean.bean there is a BeanController which does what you want (but not via the annotations).

Note that the BeanController has pre and post methods which occur during the transaction. The BeanListener has post type methods which only fire AFTER a successful transaction commit.

I have not yet added support for the JPA annotations as you have above but these map directly to the preInsert preUpdate and postLoad methods on BeanController. I should add this support in though. BeanController has more functionality and you have to be wary when using the post* methods (in that more commonly you would actually be better to use a BeanListener instead).

Cheers, Rob.

Create a New Topic

Title:
Body:
 
Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements
woResponse