db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From KeyofDMinor <keyofdmi...@yahoo.com>
Subject Best Practices for read-only operations and concurrency?
Date Fri, 03 Dec 2004 21:02:07 GMT

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 :-}



interface Action {
    void perform();

class TransactionManager {
    public void readwrite(Action action) synchronized
        Connection connection = null;
        try {
            connection = Transaction.begin(...);
            connection = null;
        } catch(TorqueException tex) {
        // 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.

To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message