Return-Path: Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: (qmail 93408 invoked from network); 16 Apr 2011 09:14:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Apr 2011 09:14:48 -0000 Received: (qmail 23028 invoked by uid 500); 16 Apr 2011 09:14:48 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 23018 invoked by uid 500); 16 Apr 2011 09:14:46 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 23011 invoked by uid 99); 16 Apr 2011 09:14:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Apr 2011 09:14:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Apr 2011 09:14:42 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id B6C32A4BF6 for ; Sat, 16 Apr 2011 09:14:05 +0000 (UTC) Date: Sat, 16 Apr 2011 09:14:05 +0000 (UTC) From: "Andrus Adamchik (JIRA)" To: commits@cayenne.apache.org Message-ID: <212618751.62151.1302945245745.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <821864699.61679.1302915305733.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (CAY-1559) Use Lifecycle Annotations as markers on PersistentObject methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAY-1559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13020578#comment-13020578 ] Andrus Adamchik commented on CAY-1559: -------------------------------------- Great. This was actually on my TODO list. Should be a useful feature. Will inspect the patch the apply it to trunk, > Use Lifecycle Annotations as markers on PersistentObject methods > ---------------------------------------------------------------- > > Key: CAY-1559 > URL: https://issues.apache.org/jira/browse/CAY-1559 > Project: Cayenne > Issue Type: New Feature > Components: Core Library > Affects Versions: 3.1M3, 3.1 (final), Short term future, Undefined future > Reporter: Mike M Pestorich > Priority: Trivial > Labels: annotations, listener > Attachments: LifecycleAnnotationMarker.patch > > > In my current project I have various abstract classes that my persistent objects inherit from. While experimenting with various new ways of using lifecycle listeners and their corresponding annotations available in 3.1, I found myself wanting to annotate a method on one of those abstract classes (say with @PostAdd) and have it act as a callback on all of its subclasses. Out of the box, I could get this to work the way I wanted by doing something like: > public class SomeAbstractPersistantObject { > ... > @PostAdd(SomeAbstractPersistantObject.class) > public void onPostAdd(Object object) > { > object.getObjectId() ... > } > } > And then later on registering the listener by doing something like: > serverRuntime.getDataDomain().getEntityResolver().getCallbackRegistry().addListener(new SomePersistentObject()); > The problem was that I didn't what to have to instantiate an object just to register it, or for that matter even have to register the listener in the first place. My callback is already part of the PersistentObject that it applies to and as such should "just work" for that object or anything that extends it. I wanted to be able to do something like: > public class SomeAbstractPersistantObject { > ... > @PostAdd > public void onPostAdd() > { > this.getObjectId() ... > } > } > And that's it. Listeners/Callbacks defined in this manner are registered when lazy initialization of the callback registry occurs within the EntityResolver. All I have to do now is annotate a method within the persistent object that I want it to act on and don't have to worry about anything else. > I don't know if this sort of thing would be useful to anyone but I have attached a patch that I believe does just that. I have been using it for a couple of days now and it seems to be working as intended without breaking the other available means of using lifecycle listeners. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira