Return-Path: Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: (qmail 83703 invoked from network); 3 Dec 2004 21:02:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Dec 2004 21:02:13 -0000 Received: (qmail 69181 invoked by uid 500); 3 Dec 2004 21:02:10 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 69163 invoked by uid 500); 3 Dec 2004 21:02:10 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 69144 invoked by uid 99); 3 Dec 2004 21:02:10 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=DNS_FROM_RFC_ABUSE X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from web41310.mail.yahoo.com (HELO web41310.mail.yahoo.com) (66.218.93.59) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 03 Dec 2004 13:02:08 -0800 Received: (qmail 73459 invoked by uid 60001); 3 Dec 2004 21:02:07 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=h1BRdOvfhhL6oVWoLU5+N2BbZJGoRQCojin/8hEEi6wE3wwj8cTM295VrbqLYgX4Kffh+GpbTFl1P2JaRipuYmm6asewlLrfPWm75eaUbSPrekom34gpXYV3R5hzAE7Gg47COgS/YcZyTT99ldcdBjh4ALPIvYHv2hqzO0qjbUo= ; Message-ID: <20041203210207.73457.qmail@web41310.mail.yahoo.com> Received: from [150.147.18.140] by web41310.mail.yahoo.com via HTTP; Fri, 03 Dec 2004 13:02:07 PST Date: Fri, 3 Dec 2004 13:02:07 -0800 (PST) From: KeyofDMinor Subject: Best Practices for read-only operations and concurrency? To: torque-user@db.apache.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hello all, I'm using Torque 3.1 in a multithreaded web app against Oracle 10g. The short version of my question is: is there a "read-only" transaction in Torque? The importance of a Transaction object for _writes_ is clear, but what about read-only operations? The long version: I do not have experience with Oracle; I have some experience with OO databases. With that background, I'm inclined to define a TransactionManager class which has two methods -- read() and readwrite(). These methods would be synchronized so that writers do not interfere with readers. The readwrite() method would do a full transaction with commit/rollback etc. The read() method should -- in theory -- do a "lightweight" read of the database; a rollback is not necessary. Does this make sense in Torque? I realize that Oracle will isolate readers from writers. That is, until a writer commits, no one will see the changes. But I'm concerned about a concurrent read and write -- what if a writer commits during a long read operation? Am I being paranoid? The following code is my basic idea. In English: an Action interface encapsulates access to the database; the TransactionManager provides read() and write() methods which call the perform() method on the Action. In this way, the try-catch-commit-rollback paradigm can be centralized in one place. Also, there is strong serialization of DB access (though I realize this may be too much serialization!). Any comments? Again, I'm not sure if this is too strict. It feels like I'm rewriting a framework like Spring :-} thanks, Mike keyofdminor@yahoo.com ------------------------------------------------------ interface Action { void perform(); } class TransactionManager { public void readwrite(Action action) synchronized { Connection connection = null; try { connection = Transaction.begin(...); action.perform(); Transaction.commit(connection); connection = null; } catch(TorqueException tex) { Transaction.rollback(connection); } // log success/fail and timing info } public void read(Action action) synchronized { // the "easy" way is to mimic readwrite() // but can we make this lightweight. // Should we even use a transaction here? } } class Example implements Action { public void run() { TransactionManager manager = ...; manager.read( this ); } public void action() { Criteria c = new Criteria(); c.add( stuff here ); List results = SomePeer.doSelect( criteria ); // populate Example with data from // results List } } __________________________________ Do you Yahoo!? Yahoo! Mail - Easier than ever with enhanced search. Learn more. http://info.mail.yahoo.com/mail_250 --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org