Return-Path: Delivered-To: apmail-cayenne-dev-archive@www.apache.org Received: (qmail 29856 invoked from network); 1 Dec 2009 13:42:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Dec 2009 13:42:28 -0000 Received: (qmail 74411 invoked by uid 500); 1 Dec 2009 13:42:28 -0000 Delivered-To: apmail-cayenne-dev-archive@cayenne.apache.org Received: (qmail 74389 invoked by uid 500); 1 Dec 2009 13:42:28 -0000 Mailing-List: contact dev-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 dev@cayenne.apache.org Received: (qmail 74378 invoked by uid 99); 1 Dec 2009 13:42:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Dec 2009 13:42:28 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of apparition077@gmail.com designates 209.85.219.210 as permitted sender) Received: from [209.85.219.210] (HELO mail-ew0-f210.google.com) (209.85.219.210) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Dec 2009 13:42:19 +0000 Received: by ewy2 with SMTP id 2so194620ewy.12 for ; Tue, 01 Dec 2009 05:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type; bh=PVGHp3TqGsp/dnsxsehBlcpiCagpQNAEJOabaMhAlXY=; b=Ls6iOZvKcGNoG3Zn25GjRkik9+40Wo+jTPXL/Y95XhhVURhJ5udYK9Y/NSr0Tnvwpl iFVV/Cw6s9wMvZc6gmYlBnVJ3BwBb1Ml91+LKkQYOZSn9zqsIYIvByWSvspr1bzKstRe WxyUoaLFxkDndKp5S6sIq+5wEpdkNUHjbkkSM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; b=xEPbi1I21IAn+Af2VhHRPyHnqT7jb63aC8zLSrgptR643D/lbrVE1GP0wApb/AG420 o7+vGgNTAFwPxGPYDDmaSIcDcf+yo61UEUpRaef7b43kYJSOtSOO+RFkodpEbIY8SdYJ gfxM9yT8gcAq+2yHprlVX3gVuyORSQjgQmVk4= MIME-Version: 1.0 Sender: apparition077@gmail.com Received: by 10.216.90.15 with SMTP id d15mr1926063wef.219.1259674918823; Tue, 01 Dec 2009 05:41:58 -0800 (PST) In-Reply-To: References: <9f90c2b60912010444j716ae91cu61bf29e382922047@mail.gmail.com> <24928454-C18A-49A9-B732-16EB18E2BBD2@objectstyle.org> <9f90c2b60912010527v6186ea6fre3d1e9a5c2a67324@mail.gmail.com> Date: Tue, 1 Dec 2009 16:41:58 +0300 X-Google-Sender-Auth: 6d9d6769433bd8fe Message-ID: <9f90c2b60912010541h70242988y5937ebe74ca8a292@mail.gmail.com> Subject: Re: Singletons in Cayenne and problems. Can I use multiple transactions? From: Evgeny Ryabitskiy To: dev@cayenne.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org Manual? I create them manually by calling domain1.createTransaction() and domain2.createTransaction(). How it happen: One method from Module 1 do some queries (first domain) then call method from Module 2 that is also doing some queries (second domain), after method from module 2 finished: method from module 1 is doing more queries. So it's like an "nested" transaction (from mod 2) but is performed on another DataDomain (it's another DB server) and absolutely isolated from huge "outer" transaction (mod 1). But I want to control both! and separately... Evgeny. 2009/12/1 Andrus Adamchik : > Are those manual transactions? (I.e. how does it happen that transaction > scopes overlap between two queries?) > > Also you can reuse the current thread transaction between multiple domains. > As I said, connections are scoped by DataNode name, so the same transaction > will return 2 separate connections for 2 queries run against 2 different > nodes. > > Andrus > > On Dec 1, 2009, at 3:27 PM, Evgeny Ryabitskiy wrote: > >> Problem in multiple Domains. >> When I am creating transaction I am creating it's for specific >> DataDomain (like a DataContext). >> When I have 2 Modules with dedicated DataDomains (so it will be 2 >> DataDomains) I can create 2 Transactions >> (domain.createTransaction()). >> >> But to thread I can bind only one. Then when I start performing queries I >> got: >> 1)First Domain Transaction is binded and handled normally >> 2)Second Domain Transaction is override by first DataDomain. So when I >> perform query for second: ThreadLocals return Transaction for firs >> Domain. >> >> Evgeny >> >> >> >> 2009/12/1 Andrus Adamchik : >>> >>> Singletons are bad in a general purpose framework, like Cayenne. No >>> question >>> about that. Per your description even thread-local singletons can be a >>> problem, which is less obvious to me, but I guess real in some >>> circumstances. So let's see what those are. >>> >>>> 2)DataContext.getThreadLocal() >>>> Solved by own ThreadLocal for each module. (modules can work in one >>>> thread) >>>> //also spend some time >>> >>> This is just a convenience in Cayenne. Nobody's forced to use it. I will >>> go >>> as far as to suggest to remove it from Cayenne 3.1 as a built-in feature, >>> and just document it as a possible design pattern in a user application. >>> >>>> 3)Transaction.getThreadTransaction() >>>> this is killing one!!! >>>> using of own ThreadLocal doesn't help. >>>> It's hard-coded in performing Query to use this singleton >>>> Transaction.getThreadTransaction() >>>> And that is really huge problem for me. >>> >>> J2EE pattern of tying a transaction to an execution thread, even if >>> multiple >>> data sources are involved, makes sense as it allows to commit/rollback >>> multiple things at once. Cayenne Transaction sort of follows that. JDBC >>> connections within the transaction are scoped by DataNode name. So what >>> exactly is the problem? >>> >>> Andrus >>> >>> >>> >>> On Dec 1, 2009, at 2:44 PM, Evgeny Ryabitskiy wrote: >>> >>>> Hello 2 everyone! >>>> >>>> Today I one more time thinking about singleton pattern and it's hard >>>> usssage in Cayenne. >>>> >>>> So.. I have several modules, each has own DomainConfig file and >>>> connection to it's DataBase. Sometimes there can be used different DB >>>> servers and even different DB types (usually it's Oracle and MS SQL, >>>> sometimes Sybase). >>>> >>>> Singletons: >>>> 1) Configuration.getSharedConfiguration() >>>> This problem is solved: >>>> DefaultConfiguration conf = new >>>> DefaultConfiguration("module1-cayenne.xml"); >>>> conf .initialize; >>>> conf.getDomain(); >>>> //spend some time to find solution... everywhere examples with >>>> SharedConfiguration >>>> >>>> 2)DataContext.getThreadLocal() >>>> Solved by own ThreadLocal for each module. (modules can work in one >>>> thread) >>>> //also spend some time >>>> >>>> 3)Transaction.getThreadTransaction() >>>> this is killing one!!! >>>> using of own ThreadLocal doesn't help. >>>> It's hard-coded in performing Query to use this singleton >>>> Transaction.getThreadTransaction() >>>> And that is really huge problem for me. >>>> >>>> So me suggestion is to move this ThreadLocal to DataDomain. Still can >>>> use singleton API for standalone applications. >>>> Also we can move DataContext to DataDomain. >>>> >>>> Evgeny. >>>> >>> >>> >> > >