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

java.lang.Object
  |
  +--org.edg.security.voms.database.connection.ConnectionWrapper
        |
        +--org.edg.security.voms.database.connection.DirectUpdate

public class DirectUpdate
extends ConnectionWrapper

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 ();
     }
 }
 


Nested Class Summary
private static class DirectUpdate.Counter
          A trivial class for thread-safe counters.
 
Field Summary
(package private) static DirectUpdate.Counter counter
          Global transaction counter.
private  long transaction
          Current transaction id.
 
Fields inherited from class org.edg.security.voms.database.connection.ConnectionWrapper
conn, id, inTransaction, log, pool, stmts
 
Constructor Summary
DirectUpdate(java.sql.Connection c, ConnectionPool pool, int id)
           
 
Method Summary
static DirectUpdate begin()
          Allocate a new direct update connection.
(package private)  void beginTransaction()
           
 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 is still in the specified transaction.
 boolean isReadonly()
           
 void rollback()
          Roll back the current transaction, and release this connection.
 
Methods inherited from class org.edg.security.voms.database.connection.ConnectionWrapper
close, getConnection, getStatement, isClosed, isDirty, isFunctional, isInTransaction, setDirty, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

counter

static DirectUpdate.Counter counter
Global transaction counter.


transaction

private long transaction
Current transaction id.

Constructor Detail

DirectUpdate

public DirectUpdate(java.sql.Connection c,
                    ConnectionPool pool,
                    int id)
Method Detail

begin

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

VOMSException

beginTransaction

void beginTransaction()
                throws VOMSException
Overrides:
beginTransaction in class ConnectionWrapper
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 is still in the specified transaction.


rollback

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


commit

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

GeneralDatabaseException

isReadonly

public boolean isReadonly()
Specified by:
isReadonly in class ConnectionWrapper