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

The following examples show how to use javax.resource.spi.TransactionSupport.TransactionSupportLevel#XATransaction . 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: 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 3
Source File: TomEEManagedConnectionProxy.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public Session createSession() throws JMSException {
    int mode;
    boolean xa;
    TransactionSupportLevel transactionSupportLevel;
    if (connection instanceof TomEEManagedConnection) {
        transactionSupportLevel = ((TomEEManagedConnection) connection).getTransactionSupportLevel();
    } else {
        transactionSupportLevel = TransactionSupportLevel.XATransaction;
    }
    switch (transactionSupportLevel) {
        case XATransaction:
            if (JMS2.inTx()) {
                mode = -1;
                xa = true;
                break;
            }
        case NoTransaction:
            mode = JMSContext.AUTO_ACKNOWLEDGE;
            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: AbstractPool.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ConnectionListener getConnectionListener(Credential credential) throws ResourceException
{
   log.tracef("getConnectionListener(%s)", credential);

   ConnectionListener cl = null;
   ManagedConnectionPool mcp = getManagedConnectionPool(credential);

   if (isShutdown())
      throw new ResourceException();
   
   if (cm.getTransactionSupport() == TransactionSupportLevel.LocalTransaction
         || cm.getTransactionSupport() == TransactionSupportLevel.XATransaction)
   {
      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;
               }
            }

            cl = currentMap.get(mcp);

            if (cl == null)
            {
               if (TxUtils.isActive(tx))
               {
                  cl = mcp.getConnectionListener();

                  currentMap.put(mcp, cl);

                  txCM.getTransactionIntegration().getTransactionSynchronizationRegistry().
                     registerInterposedSynchronization(new TransactionMapCleanup(id, transactionMap));
               }
               else
               {
                  throw new ResourceException();
               }
            }
         }
      }
      catch (ResourceException re)
      {
         throw re;
      }
      catch (Exception e)
      {
         throw new ResourceException(e);
      }
   }

   if (cl == null)
      cl = mcp.getConnectionListener();

   return cl;
}
 
Example 5
Source File: XATransactionConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public TransactionSupportLevel getTransactionSupport()
{
   return TransactionSupportLevel.XATransaction;
}
 
Example 6
Source File: TomEEManagedConnectionProxy.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Session createSession(final int acknowledgeMode) throws JMSException {
    // For the next three methods, we ignore the requested session mode per the
    // spec:
    // https://docs.oracle.com/javaee/7/api/javax/jms/Connection.html#createSession-int-
    //
    // But we also allow the user to override this behavior. If they set
    // transactionSupport on the connection factory
    // we will not return to them a xa session, even though the underlying physical
    // connection may support XA.

    int mode;
    boolean xa;
    TransactionSupportLevel transactionSupportLevel;
    if (connection instanceof TomEEManagedConnection) {
        transactionSupportLevel = ((TomEEManagedConnection) connection).getTransactionSupportLevel();
    } 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);
    }
}