Re: DBTransactions and DBConnections

"Michael Strapp" <[email protected]> Mon, 28 Mar 2005 10:35:55 -0500
Newsgroups gmane.comp.java.enhydra.dods
Message-ID <004401c533ab$da34e150$3401a8c0@Mike>
This is a multi-part message in MIME format...

------------=_1112024207-15307-48
Content-Type: text/plain;
	format=flowed;
	charset="iso-8859-1";
	reply-type=original
Content-Transfer-Encoding: 8bit

Hi again,
    Actually, having previously noticed a quirk when performing a query 
within a transaction, I realise there's a bug in the code you copied from 
the XxxQuery object.  The section:

if(((com.lutris.appserver.server.sql.CachedDBTransaction)transaction).getAutoWrite()) 
try {
    transaction.write();
} catch (SQLException sqle) {

Should actually have a not applied to the if condition.  I found that when 
you have auto-write off, and you use a XxxQuery object within the 
transaction, the results can be incorrect due to the DBTransaction wrapper 
queueing up database operations that haven't been forwarded to the 
database - I've been explicitly calling .write() prior to doing the query in 
such cases.  Turning auto-write on causes .write() to be called after every 
operation - so the above .write() call is actually unnecessary when 
auto-write is on (which was presumably the purpose of having the above 
.write() call within an if statement).

Sinisa, could you apply this fix to the runQuery() method in the code 
templates for the XxxQuery objects?

Thanks,
Mike.

----- Original Message ----- 
From: "Gilles Serasset" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 24, 2005 3:31 AM
Subject: Re: [dods] DBTransactions and DBConnections


Hi Michael,

Thanks for the suggestion, I'll try it if I cannot find another way.

For the moment, I tried to implement the class as a subclass of a
Query, where I redefined the executeQuery method to fit my needs...

     public ResultSet executeQuery(DBConnection conn) throws
SQLException {
         conn.execute(currentSQL);
         return null;
     }

And I create an instance of the query using the trans as a parameter
(like other queries):

     public SpecialDatabaseRequest(DBTransaction trans) {
         this.transaction = trans;
     }

Invoking the query is done by creating an instance of the
SpecialDatabaseRequest and invoking the executeSql method:

     public void executeSQL(String sql) throws DatabaseManagerException,
DataObjectException {
         //Flush the current transaction (?)
         currentSQL = sql;
         if ((transaction!=null) &&
             (transaction instanceof
com.lutris.appserver.server.sql.CachedDBTransaction)) {

if(((com.lutris.appserver.server.sql.CachedDBTransaction)transaction).ge
tAutoWrite()) try {
                 transaction.write();
             } catch (SQLException sqle) {
                 sqle.printStackTrace();
                 throw new DataObjectException("Couldn't write
transaction: "+sqle);
             }

//
((com.lutris.appserver.server.sql.CachedDBTransaction)transaction).dontA
ggregateDOModifications();
         }
         // Create the DB Query Object
         try {
             if (transaction == null) {
                 dbQuery = DODS.getDatabaseManager().createQuery();
             } else {
                 dbQuery = transaction.createQuery();
             }
         } catch ( DatabaseManagerException e ) {
             String err = "ERROR SpecialDatabaseRequest: Could not
create a DBQuery.  ";
             throw new DatabaseManagerException( err, e );
         }
         dbQuery.query( this );   // invokes executeQuery
         currentSQL = "";
     }

The executeSQL code is inspired from code extracted from the Queries.
It hits DB without checking for anything in the caches. This may be
harmfull if caches are not in sync with DB and if the SQL does queries
on objects that have been modified before... (maybe a dods specialist
can confirm on this). However, my need are creation, truncation, drop
of tables so this is not a problem here...

I still haven't tested it yet... but I'll tell you if this works...

Regards,

Gilles,

--
Gilles Sérasset
GETA-CLIPS-IMAG (UJF, INPG & CNRS)
BP 53 - F-38041 Grenoble Cedex 9
Phone: +33 4 76 51 43 80
Fax:   +33 4 76 44 66 75






--------------------------------------------------------------------------------


>
> --
> You receive this message as a subscriber of the [email protected] mailing 
> list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
> 



------------=_1112024207-15307-48
Content-Type: text/plain; name="message.footer"
Content-Disposition: inline; filename="message.footer"
Content-Transfer-Encoding: 8bit


--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

------------=_1112024207-15307-48--