Return-Path: X-Original-To: apmail-myfaces-users-archive@www.apache.org Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DEF2B4C77 for ; Fri, 1 Jul 2011 20:15:19 +0000 (UTC) Received: (qmail 3972 invoked by uid 500); 1 Jul 2011 20:15:19 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 3927 invoked by uid 500); 1 Jul 2011 20:15:18 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 3919 invoked by uid 99); 1 Jul 2011 20:15:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jul 2011 20:15:18 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of pieter.martin@gmail.com designates 74.125.82.181 as permitted sender) Received: from [74.125.82.181] (HELO mail-wy0-f181.google.com) (74.125.82.181) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jul 2011 20:15:12 +0000 Received: by wyh22 with SMTP id 22so2884881wyh.12 for ; Fri, 01 Jul 2011 13:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=6+6Fg+stkXFa2tbgmnG/vLcCwNEy7X7vZYFo9tlve8U=; b=quCBoSO59QQ6+AF2n34W6GDcMT/NNtN7RYE4aBiuWlZHVF9CPt9lBWjQAcc6foJU3R 8DYy6HsWOucch8B7YPe0FW7a1FwIIzuVipD3NjCq/IdM2F/VxXlU7Eo8o9YRMsY4JDrL +2ZkcmNGmLiUp+baV1T+5RjwBPqsTr5mdt45s= Received: by 10.227.199.139 with SMTP id es11mr3352885wbb.46.1309551290719; Fri, 01 Jul 2011 13:14:50 -0700 (PDT) Received: from [192.168.1.100] (wbs-196-2-103-32.wbs.co.za [196.2.103.32]) by mx.google.com with ESMTPS id ei4sm2580154wbb.43.2011.07.01.13.14.47 (version=SSLv3 cipher=OTHER); Fri, 01 Jul 2011 13:14:49 -0700 (PDT) Message-ID: <4E0E2AB4.4040404@gmail.com> Date: Fri, 01 Jul 2011 22:14:44 +0200 From: Pieter Martin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110516 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: MyFaces Discussion Subject: Re: Conversations References: <4E0CE08B.70500@gmail.com> <4E0DD495.1090509@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, looks like it worked. I can now inject a conversation scoped db instance into the faces listener set the threadvar and start the transaction. To clarify, is codi now starting a conversation before calling the beforeRequest observer? Many thanks Pieter On 01/07/2011 20:09, Gerhard Petracek wrote: > hi pieter, > > you can try to patch codi with [1] (attention: it wouldn't work in > combination with view-access scoped beans). > if it works, we will include it in codi. > information about building codi is available at [2]. > an alternative would be to produce a proxy instead of the real instance and > start the transaction lazily in the proxy before methods are invoked which > should be executed within the transaction. > > regards, > gerhard > > [1] http://people.apache.org/~gpetracek/myfaces/codi/20110701_01.patch > [2] https://cwiki.apache.org/confluence/display/EXTCDI/Building+CODI > > http://www.irian.at > > Your JSF powerhouse - > JSF Consulting, Development and > Courses in English and German > > Professional Support for Apache MyFaces > > > 2011/7/1 Pieter Martin > >> Hi, >> >> Currently I have gotten the following to work, using only request scoped db >> instance and backing beans. >> >> public class FacesListener { >> @Inject >> NakedGraph db; >> @Inject >> Logger logger; >> >> public void beforeFacesRequest(@Observes @BeforeFacesRequest >> FacesContext ctx) { >> logger.fine("**beforeFacesRequest, setting db and starting >> transaction"); >> GraphDb.setDb(db); >> db.startTransaction(); >> } >> >> public void afterFacesRequest(@Observes @AfterFacesRequest FacesContext >> ctx) { >> logger.fine("**afterFacesRequest, stopping transaction and removing >> db"); >> db.stopTransaction(Conclusion.**SUCCESS); >> GraphDb.remove(); >> } >> >> } >> >> GraphDb is a threadvar. >> >> I am hoping to do something similar but for a ConversationScoped db >> instance and backing beans. However the conversation is not active during >> beforeFacesRequest. >> >> The idea is to have a conversation scoped producer for db instance. With a >> corresponding @Disposal method to ensure that the db instance is closed >> properly. For every request made from jsf before jsf touches any beans I >> need to set the db instance on the threadvar and start a transaction. >> >> The above code does not work as the conversation is not yet active during >> beforeFacesRequest. >> >> When I go to a particular page, with a conversation scoped backing bean, >> the backing bean will make entities available, loaded from the conversation >> scoped db instance to view/edit on the page. Then on updating a particular >> entity (backingBean.update) , seeing as jsf directly access the entity and >> sets the fields the db instance needs to have been set on a threadvar before >> jsf accesses the entity. >> >> I am looking for a listener of sorts to set the threadvar and start the >> transaction before jsf touches any beans but after the conversation is >> active. >> >> Hope it makes some sense. >> Thanks >> Pieter >> >> >> >> On 01/07/2011 09:15, Gerhard Petracek wrote: >> >>> hi pieter, >>> >>> please provide a bit more details. esp. the first phase of the jsf >>> request lifecycle which has to access this instance and how you would >>> like to access it. >>> >>> codi tries to restore the window-id as early as possible. the first >>> attempt is before the restore-view phase. if it isn't possible there, >>> codi restores it after the restore-view phase. >>> >>> conversation scoped beans can be accessed as soon as there is a window-id. >>> >>> regards, >>> gerhard >>> >>> >>> 2011/6/30, Pieter Martin: >>> >>>> Hi, >>>> >>>> I have the following requirement and wondering how to implement it with >>>> codi. >>>> >>>> We want to use conversations and have a database instance that is >>>> conversation scoped. However for every request that we need to put the >>>> conversation scoped database instance in a threadvar where domain >>>> entities can access it later. We are using a graph db and the domain >>>> entities uses the db instance to add vertexes and edges. >>>> >>>> For request scoped use cases it is easy to set the threadvar when >>>> observing the @BeforeFacesRequest event and to clear the threadvar on >>>> the @AfterFacesRequest. >>>> >>>> However this does not work for conversation scoped use cases as the >>>> conversation context is not yet active. >>>> >>>> Is there a suggested way for me to achieve this? >>>> >>>> Thanks >>>> Pieter >>>> >>>>