org.glite.security.voms.database.connection
Class DirectUpdate

java.lang.Object
  extended byorg.glite.security.voms.database.connection.Transaction
      extended byorg.glite.security.voms.database.connection.DirectUpdate

public class DirectUpdate
extends Transaction

Database connection wrapper for read-write operations on tables without a history trace. These wrappers are usually used in autonomous nested transactions. Thus, in order to avoid nasty singlethreaded database deadlocks, connections of this type must not be used to query or update any of the traced tables and vice versa. (ADMIN and CA count as traced tables here.)

Tables for which DirectUpdate is safe include SEQUENCE, REALTIME and REQUEST.

The idiom for using a DirectUpdate is as follows:

 DirectUpdate u = DirectUpdate.begin ();
 long transaction = u.getTransaction();
 try {
     // Do something.
     u.commit ();
 }
 catch (Exception e) {
     // Do something
 }
 finally {
     if (u.isInTransaction (transaction)) {
         u.rollback ();
     }
 }
 


Field Summary
 
Fields inherited from class org.glite.security.voms.database.connection.Transaction
conn, log
 
Method Summary
static DirectUpdate begin()
          Allocate a new direct update connection.
 void commit()
          Commit the current transaction, and release this connection.
 long getTransaction()
          Return the current transaction id.
 boolean isInTransaction(long id)
          Return true if the wrapper has the given transaction number.
 void rollback()
          Roll back the current transaction, and release this connection.
 java.lang.String toString()
           
 
Methods inherited from class org.glite.security.voms.database.connection.Transaction
getConnection, getStatement, getStatementCount, isReadOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

begin

public static DirectUpdate begin()
                          throws VOMSException
Allocate a new direct update connection.

Throws:
VOMSException

getTransaction

public long getTransaction()
Return the current transaction id. DirectUpdate's transaction id has no relation to UpdateWrapper's transaction id. It is simply a class-static runtime counter that ensures that no transaction will be mistakenly committed or rolled back by another thread. This id is purely for defensive programming; it will not appear anywhere in the database.


isInTransaction

public boolean isInTransaction(long id)
Return true if the wrapper has the given transaction number.


commit

public void commit()
            throws GeneralDatabaseException
Commit the current transaction, and release this connection.

Throws:
GeneralDatabaseException

rollback

public void rollback()
              throws GeneralDatabaseException
Roll back the current transaction, and release this connection.

Throws:
GeneralDatabaseException

toString

public java.lang.String toString()