FileDocCategorySizeDatePackage
TransactionImpl.javaAPI DocGlassfish v2 API13871Fri May 04 22:36:40 BST 2007com.sun.jts.jta

TransactionImpl

public class TransactionImpl extends Object implements Transaction
An implementation of javax.transaction.Transaction using JTS XXX TODO should catch all org.omg.CORBA.SystemException and throw javax.transaction.SystemException
author
Tony Ng

Fields Summary
private Control
control
OTS Control object for this transaction
private com.sun.jts.CosTransactions.GlobalTID
gtid
private TransactionState
tranState
private static TransactionManagerImpl
tm
static Logger
_logger
private long
startTime
Constructors Summary
public TransactionImpl(Control control, com.sun.jts.CosTransactions.GlobalTID gtid)

    // END 4662745

        
          

        this.control = control;
        this.gtid = gtid;
        startTime=System.currentTimeMillis();
    
Methods Summary
private static voidassert_prejdk14(boolean value)
a simple assertion mechanism that print stack trace if assertion fails

        if (!value) {
            Exception e = new Exception();
			_logger.log(Level.WARNING,"jts.assert",e);
        }
    
public voidcommit()
Complete the transaction represented by this Transaction object

        try {
            if (Configuration.isLocalFactory()) {
              ((ControlImpl) control).get_localTerminator().commit(true);
            } else {
                control.get_terminator().commit(true);
            }
        } catch (TRANSACTION_ROLLEDBACK ex) {
            throw new RollbackException();
        } catch (INVALID_TRANSACTION ex) {
            throw new IllegalStateException();
        } catch (HeuristicMixed ex) {
            throw new HeuristicMixedException();
        } catch (HeuristicHazard ex) {
            throw new HeuristicMixedException();
        } catch (NO_PERMISSION ex) {
            throw new SecurityException();
        } catch (Unavailable ex) {
            SystemException sException = new SystemException();
            sException.initCause(ex);
            throw sException;
        } catch (Exception ex) {
            SystemException sException = new SystemException();
            sException.initCause(ex);
            throw sException;
        }

    
public booleandelistResource(javax.transaction.xa.XAResource res, int flags)


        /*
        int status = getStatus();
        if (status != javax.transaction.Status.STATUS_ACTIVE &&
            status != javax.transaction.Status.STATUS_MARKED_ROLLBACK) {
            throw new IllegalStateException();
        }
        */

        try {
            // TransactionState tranState = tm.getTransactionState(gtid, this);
            if (tranState == null) {
                // transaction has completed
                throw new IllegalStateException();
            }
            if (tranState.containsXAResource(res) == false) {
                throw new IllegalStateException();
            }
            tranState.endAssociation(res, flags);
            if ((flags & XAResource.TMFAIL) != 0) {
                // set transaction to rollback only if TMFAIL used
                setRollbackOnly();
            }
            return true;
        } catch (XAException ex) {
            setRollbackOnly();
            throw new SystemException();
        }
    
public booleanenlistResource(javax.transaction.xa.XAResource res)
enlist a resource with the current transaction If a transaction is marked as rollback, enlistment will succeed if the resource has been enlisted before. Otherwise, enlistment will fail. In both cases, a RollbackException will be thrown.


        int status = getStatus();
        if (status != javax.transaction.Status.STATUS_ACTIVE &&
            status != javax.transaction.Status.STATUS_MARKED_ROLLBACK) {
            throw new IllegalStateException();
        }
	//START IASRI 4706150
	try{
	    if(tm.getXAResourceTimeOut() > 0)
	        res.setTransactionTimeout(tm.getXAResourceTimeOut());
	}catch(Exception ex){
	    _logger.log(Level.WARNING,"jts.error_while_setting_xares_txn_timeout",ex);
	}
	//END IASRI 4706150
        try {
            if (tranState == null) {
                tranState = new TransactionState(gtid, this);
                // Synchronization sync = new SynchronizationListener(tranState);
                // registerSynchronization(sync);
            }
            tranState.startAssociation(res, control, status);
            if (status == javax.transaction.Status.STATUS_MARKED_ROLLBACK) {
                throw new RollbackException();
            }
            return true;
        } catch (XAException ex) {
			_logger.log(Level.WARNING,"jts.resource_outside_transaction",ex);
            if (ex.errorCode == XAException.XAER_OUTSIDE) {
                throw new IllegalStateException();
            }
            // XXX FIXME should throw rollback exception on XARB_*
            // for now just throw SystemException
            throw new SystemException();
        }

    
public booleanequals(java.lang.Object object)

        if ((object instanceof TransactionImpl) == false) {
            return false;
        } else if (object == this) {
            return true;
        } else {
            return gtid.equals(((TransactionImpl) object).gtid);
        }
    
ControlgetControl()
return the OTS Control object for this transaction.

        return control;
    
public longgetStartTime()

        return startTime;
    
public intgetStatus()

        // XXX what should getStatus return on exception?
        Status  status;
        try {
            if (Configuration.isLocalFactory()) {
              status = ((ControlImpl) control).get_localCoordinator().get_status();
            } else {
              status = control.get_coordinator().get_status();
            }
            return TransactionManagerImpl.mapStatus(status);
        } catch (TRANSACTION_ROLLEDBACK ex) {
            return javax.transaction.Status.STATUS_NO_TRANSACTION;
        } catch (INVALID_TRANSACTION ex) {
            return javax.transaction.Status.STATUS_NO_TRANSACTION;
        } catch (Unavailable ex) {
            return javax.transaction.Status.STATUS_NO_TRANSACTION;
        } catch (Exception ex) {
			_logger.log(Level.WARNING,"jts.unexpected_error_in_getstatus",ex);
            throw new SystemException();
        }
    
public java.lang.StringgetTransactionId()

        return gtid.toString();
    
public inthashCode()

        return gtid.hashCode();
    
public voidregisterInterposedSynchronization(javax.transaction.Synchronization sync)


        int status = getStatus();
        if (status == javax.transaction.Status.STATUS_MARKED_ROLLBACK) {
            throw new RollbackException();
        }
        if (status != javax.transaction.Status.STATUS_ACTIVE) {
            throw new IllegalStateException();
        }
        if (tranState == null) {
            tranState = new TransactionState(gtid, this);
        }
        tranState.registerSynchronization(sync, control, true);
    
public voidregisterSynchronization(javax.transaction.Synchronization sync)


        int status = getStatus();
        if (status == javax.transaction.Status.STATUS_MARKED_ROLLBACK) {
            throw new RollbackException();
        }
        if (status != javax.transaction.Status.STATUS_ACTIVE) {
            throw new IllegalStateException();
        }
        if (tranState == null) {
            tranState = new TransactionState(gtid, this);
        }
        tranState.registerSynchronization(sync, control, false);
    
public voidrollback()
Rollback the transaction represented by this Transaction object.


        try {
            if (Configuration.isLocalFactory()) {
              ((ControlImpl) control).get_localTerminator().rollback();
            } else {
              control.get_terminator().rollback();
            }
        } catch (INVALID_TRANSACTION ex) {
            throw new IllegalStateException();
        } catch (TRANSACTION_ROLLEDBACK ex) {
            throw new IllegalStateException();
        } catch (Unavailable ex) {
            SystemException sException = new SystemException();
            sException.initCause(ex);
            throw sException;
        } catch (Exception ex) {
            SystemException sException = new SystemException();
            sException.initCause(ex);
            throw sException;
        }
    
public voidsetRollbackOnly()


        int status = getStatus();
        if (status != javax.transaction.Status.STATUS_MARKED_ROLLBACK &&
            status != javax.transaction.Status.STATUS_ACTIVE) {
            throw new IllegalStateException();
        }
        try {
            if (Configuration.isLocalFactory()) {
              ((ControlImpl) control).get_localCoordinator().rollback_only();
            } else {
              control.get_coordinator().rollback_only();
            }
        } catch (Unavailable ex) {
            throw new SystemException();
        } catch (Inactive ex) {
            throw new IllegalStateException();
        } catch (Exception ex) {
            throw new SystemException();
        }