Two FAQs about Ammentos 1.3.0

January 17, 2008

There are two frequently asked questions I receive by email about the new version (1.3.0) of Ammentos (lightweight Java persistence framework). The first one is if I suggest to update it in production projects. The second one is about the difference between new persistence handlers and legacy persistence listeners.

About the first question, my answer is the same as with the other versions: Ammentos 1.3.0 is fully backward compatible and passes all the unit tests (at the moment 25) I wrote to ensure its correct behavior in several working cases (concurrency, inheritance, circular references etc.). Of course I’m far from being “the perfect programmer”, even less the perfect tester :) Some bugs can certainly still quietly live into my code, sunbathing at Poetto’s beatch. But what I can certainly say is that every time I discover a bug, or when one of Ammentos users does the same, once the bug is fixed a new test is added to ensure it will never appear again.

This is the biggest power of opensource: I know my code is read and checked by other programmers. I’ve even received some very important code contributions from users, and all of them have been introduced in this new version, and of course they’ve been put also under unit testing. All this makes me more confident about any new version; that’s why I’ve updated all my production software with it. And so far it seems to be OK :-P For your production project, I suggest to do the same if you have the possibility to check its behavior a few time. You always can put the new version with your first project update. Of course, if you found any bugs in the old version, and especially if you told me about it, it is highly probable this new version contains the fix.

About the second question. There are some very big difference between new persistence handlers and legacy persistence listeners. The first one, and most important, is about threading. Old persistence listeners are an implementation of the Observer/Observable pattern. A PersistenceListener is an external observer which can be registered to the main Ammentos’ PersistenceContext, to obtain information when every type of PersistenceEntity is saved or deleted. This information is delivered in a separate thread, in the same way as Swing’s EDT mechanism. A Persistence Handler is instead a mechanism to have some code executed in the same Ammentos’ thread and in the same PersistentEntity’s instance which is being saved, loaded or deleted by Ammentos.

As you can see these two methods are very different and have very different purposes. For instance, you will use legacy persistence handlers if you want send an email automatically every time a new user registers into your web application; but if you need to update the “modified” field of an article being saved into your CMS you will prefere doing it this way:

@OnSave(When.BEFORE)
private void updateModifiedDate(){
this.modified = new Date();
}

As usually, this kind of code can be private if you don’t want to make it visible.

What happens with the code above? When Ammentos is going to save the object (so BEFORE doing it) containing that method the modified field is updated, and so it will be saved in the database with the new date. Of course there were a lot of other ways to do the same, for instance just updating externally the date and after that calling Ammentos.save(), but in my opinion this is the more reliable way to ensure that every time the article is saved, the modified field will be updated.

Entry Filed under: development, java, opensource. Tags: .

2 Comments Add your own

  • 1. Daniele  |  January 17, 2008 at 11:46 am

    Really an amazing features!!!

    Thank you
    Daniele

    Reply
  • 2. ddpole  |  January 17, 2008 at 11:55 am

    :) Thanks Dani

    Reply

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Mission plan

January 2008
M T W T F S S
    Feb »
 123456
78910111213
14151617181920
21222324252627
28293031  

Recent Posts

Top Clicks

RSS News from JUG Sardegna

Links

Blogroll