Return-Path: Delivered-To: apmail-incubator-cayenne-dev-archive@locus.apache.org Received: (qmail 79862 invoked from network); 29 Oct 2006 23:46:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Oct 2006 23:46:01 -0000 Received: (qmail 82790 invoked by uid 500); 29 Oct 2006 23:46:12 -0000 Delivered-To: apmail-incubator-cayenne-dev-archive@incubator.apache.org Received: (qmail 82685 invoked by uid 500); 29 Oct 2006 23:46:12 -0000 Mailing-List: contact cayenne-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-dev@incubator.apache.org Delivered-To: mailing list cayenne-dev@incubator.apache.org Received: (qmail 82676 invoked by uid 99); 29 Oct 2006 23:46:12 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Oct 2006 15:46:12 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [64.124.179.102] (HELO polatsk.objectstyle.org) (64.124.179.102) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 29 Oct 2006 15:46:00 -0800 Received: (qmail 16454 invoked from network); 29 Oct 2006 23:45:39 -0000 Received: from unknown (HELO ??6?????????IPv6:::1?) (127.0.0.1) by localhost with SMTP; 29 Oct 2006 23:45:39 -0000 Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: <20061015180335.7de0ab54@localhost.localdomain> References: <20061015180335.7de0ab54@localhost.localdomain> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Andrus Adamchik Subject: Re: Lifecycle Callback Date: Sun, 29 Oct 2006 18:45:38 -0500 To: cayenne-dev@incubator.apache.org X-Mailer: Apple Mail (2.752.3) X-Virus-Checked: Checked by ClamAV on apache.org Hi Adrian, Your code is right, but an extra setup is needed - DataContext needs to be decorated in two callback interceptors. I haven't documented it yet, as we still need to come up with a more transparent procedure. But here is how I am doing it in my apps: DataDomain dataDomain = configuration.getDomain("sobf"); // build interceptor sitting between DD and DC - one interceptor can be shared by multiple DataContexts. DataChannel postInterceptor = new DataChannelCallbackInterceptor(); postInterceptor.setChannel(domain); // do this for every ObjectContext used by the application: // build DC ObjectStore objectStore = new ObjectStore (dataDomain.getSharedSnapshotCache()); DataContext dataContext = new DataContext(postInterceptor, objectStore); // build interceptor ObjectContext used by the application ObjectContextCallbackInterceptor preInterceptor = new ObjectContextCallbackInterceptor(); preInterceptor.setContext(new DataContext(postInterceptor, objectStore)); ObjectContext appContext = preInterceptor; Note that "appContext" is what your application should be using. Andrus On Oct 15, 2006, at 12:03 PM, Adrian Wiesmann wrote: > Hello list > > I am in the process to migrate my project to Cayenne 3 and doing so I > would like to use the Lifecycle Callbacks. My problem with them is, > that > I can't make them to work. > > I am using cayenne-generic-3.0-incubating-SNAPSHOT from 14. 10. 2006. > > In the sourcecode I am doing this: > > Configuration.initializeSharedConfiguration(); > configuration = Configuration.getSharedConfiguration(); > > dataDomain = configuration.getDomain("sobf"); > > EntityResolver er = dataDomain.getEntityResolver(); > > LifecycleEventCallbackMap cbPrePersist = > er.getCallbacks(LifecycleEventCallback.PRE_PERSIST ); > cbPrePersist.addListener( CDBCommon.class, "prePersist" ); > cbPrePersist.addListener( CThreatAgent.class, "prePersist" ); > > I have the same sourcecode (last 3 lines) for all of the 7 callback > events. > > But neither the CThreatAgent nor the CDBCommon class get's called. > Neither > when I am creating a new DBObject, nor when I am commiting my > changes to > the DataContext. > > What am I missing or doing wrong? > > Thanks, > Adrian >