Java Code Examples for javax.resource.spi.TransactionSupport.TransactionSupportLevel#NoTransaction

The following examples show how to use javax.resource.spi.TransactionSupport.TransactionSupportLevel#NoTransaction . 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: TomEEManagedConnectionFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
public void setTransactionSupport(String transactionSupport) {
    if (transactionSupport == null) {
        throw new IllegalArgumentException("transactionSupport cannot be not null");
    } else {
        switch (transactionSupport.toLowerCase(Locale.ENGLISH)) {
            case "xa":
                transactionSupportLevel = TransactionSupportLevel.XATransaction;
                break;
            case "local":
                transactionSupportLevel = TransactionSupportLevel.LocalTransaction;
                break;
            case "none":
                transactionSupportLevel = TransactionSupportLevel.NoTransaction;
                break;
            default:
                throw new IllegalArgumentException("transactionSupport must be xa, local, or none:" + transactionSupport);
        }
    }
}
 
Example 2
Source File: AbstractPool.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ConnectionListener getActiveConnectionListener(Credential credential)
{
   if (cm.getTransactionSupport() == TransactionSupportLevel.NoTransaction)
      return null;

   try
   {
      TransactionalConnectionManager txCM = (TransactionalConnectionManager) cm;
      Transaction tx = txCM.getTransactionIntegration().getTransactionManager().getTransaction();

      if (TxUtils.isUncommitted(tx))
      {
         Object id = txCM.getTransactionIntegration().getTransactionSynchronizationRegistry().getTransactionKey();
         Map<ManagedConnectionPool, ConnectionListener> currentMap = transactionMap.get(id);
         ManagedConnectionPool key = pools.get(credential);

         return currentMap.get(key);
      }
   }
   catch (Exception e)
   {
      log.tracef(e, "getActiveConnectionListener(%s)", credential);
   }

   return null;
}
 
Example 3
Source File: TomEEManagedConnectionProxy.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
    int mode;
    boolean xa;
    TransactionSupportLevel transactionSupportLevel;
    if (connection instanceof TomEEManagedConnection) {
        transactionSupportLevel = ((TomEEManagedConnection) connection).getTransactionSupportLevel();
    } else if (!transacted) {
        transactionSupportLevel = TransactionSupportLevel.NoTransaction;
    } else {
        transactionSupportLevel = TransactionSupportLevel.XATransaction;
    }
    switch (transactionSupportLevel) {
        case XATransaction:
            if (JMS2.inTx()) {
                mode = -1;
                xa = true;
                break;
            }
        case NoTransaction:
            mode = acknowledgeMode;
            xa = false;
            break;
        case LocalTransaction:
            mode = JMSContext.SESSION_TRANSACTED;
            xa = false;
            break;
        default:
            throw new IllegalStateException("transactionSupportLevel mode not supported:" + transactionSupportLevel);
    }
    if (xa) {
        return createXASession();
    } else {
        return connection.getPhysicalConnection().createSession(mode);
    }
}
 
Example 4
Source File: StablePool.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ConnectionListener createConnectionListener(Credential credential, ManagedConnectionPool mcp)
   throws ResourceException
{
   try
   {
      if (semaphore.tryAcquire(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS))
      {
         long start = getInternalStatistics().isEnabled() ? System.currentTimeMillis() : 0L;

         ManagedConnection mc =
            cm.getManagedConnectionFactory().createManagedConnection(credential.getSubject(),
                                                                     credential.getConnectionRequestInfo());

         if (getInternalStatistics().isEnabled())
         {
            getInternalStatistics().deltaCreatedCount();
            getInternalStatistics().deltaTotalCreationTime(System.currentTimeMillis() - start);
         }

         if (cm.getTransactionSupport() == TransactionSupportLevel.NoTransaction)
         {
            return new NoTransactionConnectionListener(cm, mc, credential, mcp, cm.getPool().getFlushStrategy());
         }
         else if (cm.getTransactionSupport() == TransactionSupportLevel.LocalTransaction)
         {
            return new LocalTransactionConnectionListener(cm, mc, credential, getLocalXAResource(mc), mcp,
                  cm.getPool().getFlushStrategy());
         }
         else
         {
            return new XATransactionConnectionListener(cm, mc, credential, getXAResource(mc),
                  cm.getConnectionManagerConfiguration().getXAResourceTimeout(), mcp,
                  cm.getPool().getFlushStrategy());
         }
      }
   }
   catch (ResourceException re)
   {
      throw re;
   }
   catch (Exception e)
   {
      throw new ResourceException(e);
   }

   throw new ResourceException("No ConnectionListener");
}
 
Example 5
Source File: AbstractPool.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void enlist(ManagedConnection mc) throws ResourceException
{
   if (cm.getTransactionSupport() == TransactionSupportLevel.NoTransaction)
      return;

   ConnectionListener cl = findConnectionListener(mc, null);
   if (cl != null)
   {
      if (cl.isEnlisted())
         throw new ResourceException();

      try
      {
         TransactionalConnectionManager txCM = (TransactionalConnectionManager) cm;
         Transaction tx = txCM.getTransactionIntegration().getTransactionManager().getTransaction();

         if (TxUtils.isUncommitted(tx))
         {
            Object id = txCM.getTransactionIntegration().getTransactionSynchronizationRegistry().getTransactionKey();

            Map<ManagedConnectionPool, ConnectionListener> currentMap = transactionMap.get(id);

            if (currentMap == null)
            {
               Map<ManagedConnectionPool, ConnectionListener> map = new HashMap<>();

               currentMap = transactionMap.putIfAbsent(id, map);
               if (currentMap == null)
               {
                  currentMap = map;
               }
            }

            ConnectionListener existing = currentMap.get(cl.getManagedConnectionPool());

            if (existing == null)
            {
               if (TxUtils.isActive(tx))
               {
                  cl.enlist();
                  
                  currentMap.put(cl.getManagedConnectionPool(), cl);

                  txCM.getTransactionIntegration().getTransactionSynchronizationRegistry().
                     registerInterposedSynchronization(new TransactionMapCleanup(id, transactionMap));
               }
               else
               {
                  throw new ResourceException();
               }
            }
            else
            {
               log.tracef("Already a connection listener in the pool tracked by transaction=%s (existing=%s)",
                          id, existing);

               if (existing.equals(cl))
               {
                  if (TxUtils.isActive(tx))
                  {
                     cl.enlist();
                  }
                  else
                  {
                     throw new ResourceException();
                  }
               }
               else
               {
                  throw new ResourceException();
               }
            }
         }
         else
         {
            throw new ResourceException();
         }
      }
      catch (ResourceException re)
      {
         throw re;
      }
      catch (Throwable t)
      {
         throw new ResourceException(t);
      }
   }
   else
   {
      throw new ResourceException();
   }
}
 
Example 6
Source File: AbstractPool.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void delist(ConnectionListener cl) throws ResourceException
{
   if (cm.getTransactionSupport() == TransactionSupportLevel.NoTransaction)
      return;

   if (cl != null)
   {
      try
      {
         TransactionalConnectionManager txCM = (TransactionalConnectionManager) cm;
         Transaction tx = txCM.getTransactionIntegration().getTransactionManager().getTransaction();

         if (TxUtils.isUncommitted(tx))
         {
            try
            {
               cl.delist();
            }
            finally
            {
               Object id = txCM.getTransactionIntegration()
                  .getTransactionSynchronizationRegistry().getTransactionKey();

               Map<ManagedConnectionPool, ConnectionListener> currentMap = transactionMap.get(id);

               if (currentMap != null)
               {
                  ConnectionListener registered = currentMap.remove(cl.getManagedConnectionPool());
                  transactionMap.put(id, currentMap);
               }
            }
         }
      }
      catch (ResourceException re)
      {
         throw re;
      }
      catch (Exception e)
      {
         throw new ResourceException(e);
      }
   }
   else
   {
      throw new ResourceException();
   }
}
 
Example 7
Source File: DefaultPool.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ConnectionListener createConnectionListener(Credential credential, ManagedConnectionPool mcp)
   throws ResourceException
{
   try
   {
      if (semaphore.tryAcquire(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS))
      {
         long start = getInternalStatistics().isEnabled() ? System.currentTimeMillis() : 0L;

         ManagedConnection mc =
            cm.getManagedConnectionFactory().createManagedConnection(credential.getSubject(),
                                                                     credential.getConnectionRequestInfo());

         if (getInternalStatistics().isEnabled())
         {
            getInternalStatistics().deltaCreatedCount();
            getInternalStatistics().deltaTotalCreationTime(System.currentTimeMillis() - start);
         }

         if (cm.getTransactionSupport() == TransactionSupportLevel.NoTransaction)
         {
            return new NoTransactionConnectionListener(cm, mc, credential, mcp, cm.getPool().getFlushStrategy());
         }
         else if (cm.getTransactionSupport() == TransactionSupportLevel.LocalTransaction)
         {
            return new LocalTransactionConnectionListener(cm, mc, credential, getLocalXAResource(mc), mcp,
                  cm.getPool().getFlushStrategy());
         }
         else
         {
            return new XATransactionConnectionListener(cm, mc, credential, getXAResource(mc),
                  cm.getConnectionManagerConfiguration().getXAResourceTimeout(), mcp,
                  cm.getPool().getFlushStrategy());
         }
      }
   }
   catch (ResourceException re)
   {
      throw re;
   }
   catch (Exception e)
   {
      throw new ResourceException(e);
   }

   throw new ResourceException("No ConnectionListener");
}
 
Example 8
Source File: NoTransactionConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public TransactionSupportLevel getTransactionSupport()
{
   return TransactionSupportLevel.NoTransaction;
}