Java Code Examples for javax.transaction.TransactionSynchronizationRegistry#putResource()

The following examples show how to use javax.transaction.TransactionSynchronizationRegistry#putResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TxConnectionListener.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void dissociate() throws ResourceException
{
   log.tracef("dissociate: %s", this);

   try
   {
      TransactionManager tm = getConnectionManager().getTransactionIntegration().getTransactionManager();
      int status = tm.getStatus();

      log.tracef("dissociate: status=%s", TxUtils.getStatusAsString(status));

      if (status != Status.STATUS_NO_TRANSACTION)
      {
         if (isEnlisted())
         {
            if (doDelistResource)
            {
               Transaction tx = tm.getTransaction();
               boolean delistResult = tx.delistResource(getXAResource(), XAResource.TMSUCCESS);

               log.tracef("dissociate: delistResult=%s", delistResult);
            }
         }
         else
         {
            log.tracef("dissociate: not enlisted (%s)", this);
         }

         if (isTrackByTx())
         {
            ManagedConnectionPool mcp = getManagedConnectionPool();
            TransactionSynchronizationRegistry tsr =
               getConnectionManager().getTransactionIntegration().getTransactionSynchronizationRegistry();

            Lock lock = (Lock)tsr.getResource(LockKey.INSTANCE);
            if (lock != null)
            {
               try
               {
                  lock.lockInterruptibly();
               }
               catch (InterruptedException ie)
               {
                  Thread.interrupted();
                  
                  throw new ResourceException(bundle.unableObtainLock(), ie);
               }

               try
               {
                  tsr.putResource(mcp, null);
               }
               finally
               {
                  lock.unlock();
               }
            }
         }
      }

      localTransaction.set(false);
      setTrackByTx(false);
   
      if (transactionSynchronization != null)
      {
         transactionSynchronization.cancel();
         transactionSynchronization = null;
      }

      setEnlisted(false);
   }
   catch (Throwable t)
   {
      throw new ResourceException(bundle.errorInDissociate(), t);
   }
}