Example usage for org.springframework.transaction.support TransactionSynchronizationManager isSynchronizationActive

List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager isSynchronizationActive

Introduction

In this page you can find the example usage for org.springframework.transaction.support TransactionSynchronizationManager isSynchronizationActive.

Prototype

public static boolean isSynchronizationActive() 

Source Link

Document

Return if transaction synchronization is active for the current thread.

Usage

From source file:com.github.rholder.spring.transaction.TransactionBindingSupport.java

/**
 * Binds the Alfresco-specific to the transaction resources
 * /*  ww  w .ja va  2 s  . c  om*/
 * @return Returns the current or new synchronization implementation
 */
private static TransactionSynchronizationImpl registerSynchronizations() {
    /*
     * No thread synchronization or locking required as the resources are all threadlocal
     */
    if (!TransactionSynchronizationManager.isSynchronizationActive()) {
        Thread currentThread = Thread.currentThread();
        throw new RuntimeException(
                "Transaction must be active and synchronization is required: " + currentThread);
    }
    TransactionSynchronizationImpl txnSynch = (TransactionSynchronizationImpl) TransactionSynchronizationManager
            .getResource(RESOURCE_KEY_TXN_SYNCH);
    if (txnSynch != null) {
        // synchronization already registered
        return txnSynch;
    }
    // we need a unique ID for the transaction
    String txnId = UUID.randomUUID().toString();
    // register the synchronization
    txnSynch = new TransactionSynchronizationImpl(txnId);
    TransactionSynchronizationManager.registerSynchronization(txnSynch);
    // register the resource that will ensure we don't duplication the synchronization
    TransactionSynchronizationManager.bindResource(RESOURCE_KEY_TXN_SYNCH, txnSynch);
    // done
    if (logger.isDebugEnabled()) {
        logger.debug("Bound txn synch: " + txnSynch);
    }
    return txnSynch;
}

From source file:com._4dconcept.springframework.data.marklogic.datasource.DatabaseConnectorJtaTransactionTest.java

private void doTestJtaTransactionWithPropagationRequiresNew(final boolean rollback,
        final boolean openOuterConnection, final boolean accessAfterResume,
        final boolean useTransactionAwareContentSource) throws Exception {

    given(transactionManager.suspend()).willReturn(transaction);
    if (rollback) {
        given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
    } else {//from w w  w . j  ava  2 s .  c o m
        given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE,
                Status.STATUS_ACTIVE);
    }

    given(session.getTransactionMode()).willReturn(Session.TransactionMode.QUERY);

    final ContentSource dsToUse = useTransactionAwareContentSource
            ? new TransactionAwareContentSourceProxy(contentSource)
            : contentSource;

    JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
    final TransactionTemplate tt = new TransactionTemplate(ptm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(dsToUse));
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

    tt.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
            assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(dsToUse));
            assertTrue("JTA synchronizations active",
                    TransactionSynchronizationManager.isSynchronizationActive());
            assertTrue("Is new transaction", status.isNewTransaction());

            Session s = ContentSourceUtils.getSession(dsToUse);
            assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
            s.getTransactionMode();
            ContentSourceUtils.releaseSession(s, dsToUse);

            s = ContentSourceUtils.getSession(dsToUse);
            assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
            if (!openOuterConnection) {
                ContentSourceUtils.releaseSession(s, dsToUse);
            }

            for (int i = 0; i < 5; i++) {

                tt.execute(new TransactionCallbackWithoutResult() {
                    @Override
                    protected void doInTransactionWithoutResult(TransactionStatus status)
                            throws RuntimeException {
                        assertTrue("Hasn't thread session",
                                !TransactionSynchronizationManager.hasResource(dsToUse));
                        assertTrue("JTA synchronizations active",
                                TransactionSynchronizationManager.isSynchronizationActive());
                        assertTrue("Is new transaction", status.isNewTransaction());

                        Session s = ContentSourceUtils.getSession(dsToUse);
                        s.getTransactionMode();
                        assertTrue("Has thread session",
                                TransactionSynchronizationManager.hasResource(dsToUse));
                        ContentSourceUtils.releaseSession(s, dsToUse);

                        s = ContentSourceUtils.getSession(dsToUse);
                        assertTrue("Has thread session",
                                TransactionSynchronizationManager.hasResource(dsToUse));
                        ContentSourceUtils.releaseSession(s, dsToUse);
                    }
                });

            }

            if (rollback) {
                status.setRollbackOnly();
            }

            if (accessAfterResume) {
                if (!openOuterConnection) {
                    s = ContentSourceUtils.getSession(dsToUse);
                }
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
                s.getTransactionMode();
                ContentSourceUtils.releaseSession(s, dsToUse);

                s = ContentSourceUtils.getSession(dsToUse);
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
                ContentSourceUtils.releaseSession(s, dsToUse);
            } else {
                if (openOuterConnection) {
                    ContentSourceUtils.releaseSession(s, dsToUse);
                }
            }
        }
    });

    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(dsToUse));
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
    verify(userTransaction, times(6)).begin();
    verify(transactionManager, times(5)).resume(transaction);
    if (rollback) {
        verify(userTransaction, times(5)).commit();
        verify(userTransaction).rollback();
    } else {
        verify(userTransaction, times(6)).commit();
    }
    if (accessAfterResume && !openOuterConnection) {
        verify(session, times(7)).close();
    } else {
        verify(session, times(6)).close();
    }
}

From source file:com.frank.search.solr.repository.support.SimpleSolrRepository.java

private void registerTransactionSynchronisationIfSynchronisationActive() {
    if (TransactionSynchronizationManager.isSynchronizationActive()) {
        registerTransactionSynchronisationAdapter();
    }/*ww  w  .  j a v  a 2s. co m*/
}

From source file:com.frank.search.solr.repository.support.SimpleSolrRepository.java

private void commitIfTransactionSynchronisationIsInactive() {
    if (!TransactionSynchronizationManager.isSynchronizationActive()) {
        this.solrOperations.commit();
    }//w  w w.  j  a  va  2  s  .  co  m
}

From source file:org.alfresco.util.transaction.SpringAwareUserTransaction.java

/**
 * @throws NotSupportedException if an attempt is made to reuse this instance
 *///from   w  ww  .j a  v a2s.co  m
public synchronized void begin() throws NotSupportedException, SystemException {
    // make sure that the status and info align - the result may or may not be null
    @SuppressWarnings("unused")
    TransactionInfo txnInfo = getTransactionInfo();
    if (internalStatus != Status.STATUS_NO_TRANSACTION) {
        throw new NotSupportedException("The UserTransaction may not be reused");
    }

    // check 

    if ((propagationBehaviour != TransactionDefinition.PROPAGATION_REQUIRES_NEW)) {
        if (!readOnly && TransactionSynchronizationManager.isSynchronizationActive()
                && TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
            throw new IllegalStateException("Nested writable transaction in a read only transaction");
        }
    }

    // begin a transaction
    try {
        internalTxnInfo = createTransactionIfNecessary((Method) null, (Class<?>) null); // super class will just pass nulls back to us
    } catch (CannotCreateTransactionException e) {
        throw new ConnectionPoolException("The DB connection pool is depleted.", e);
    }

    internalStatus = Status.STATUS_ACTIVE;
    threadId = Thread.currentThread().getId();

    // Record that transaction details now that begin was successful
    isBeginMatched = false;
    if (isCallStackTraced) {
        // get the stack trace
        Exception e = new Exception();
        e.fillInStackTrace();
        beginCallStack = e.getStackTrace();
    }

    // done
    if (logger.isDebugEnabled()) {
        logger.debug("Began user transaction: " + this);
    }
}

From source file:com._4dconcept.springframework.data.marklogic.datasource.DatabaseConnectorJtaTransactionTest.java

private void doTestJtaTransactionCommitWithNewTransactionWithinEmptyTransaction(final boolean requiresNew,
        boolean notSupported) throws Exception {

    if (notSupported) {
        given(userTransaction.getStatus()).willReturn(Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION,
                Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
        given(transactionManager.suspend()).willReturn(transaction);
    } else {//from  w  ww. j  a  v  a2 s  . c o  m
        given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
                Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
    }

    final ContentSource contentSource = mock(ContentSource.class);
    final Session session1 = mock(Session.class);
    final Session session2 = mock(Session.class);
    given(contentSource.newSession()).willReturn(session1, session2);

    final JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
    TransactionTemplate tt = new TransactionTemplate(ptm);
    tt.setPropagationBehavior(notSupported ? TransactionDefinition.PROPAGATION_NOT_SUPPORTED
            : TransactionDefinition.PROPAGATION_SUPPORTS);

    assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
    tt.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
            assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
            assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
            assertSame(session1, ContentSourceUtils.getSession(contentSource));
            assertSame(session1, ContentSourceUtils.getSession(contentSource));

            TransactionTemplate tt2 = new TransactionTemplate(ptm);
            tt2.setPropagationBehavior(requiresNew ? TransactionDefinition.PROPAGATION_REQUIRES_NEW
                    : TransactionDefinition.PROPAGATION_REQUIRED);
            tt2.execute(new TransactionCallbackWithoutResult() {
                @Override
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                    assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
                    assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
                    assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
                    assertSame(session2, ContentSourceUtils.getSession(contentSource));
                    assertSame(session2, ContentSourceUtils.getSession(contentSource));
                }
            });

            assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
            assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
            assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
            assertSame(session1, ContentSourceUtils.getSession(contentSource));
        }
    });
    assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
    verify(userTransaction).begin();
    verify(userTransaction).commit();
    if (notSupported) {
        verify(transactionManager).resume(transaction);
    }
    verify(session2).close();
    verify(session1).close();
}

From source file:com._4dconcept.springframework.data.marklogic.datasource.DatabaseConnectorJtaTransactionTest.java

private void doTestJtaTransactionWithPropagationRequiresNewAndBeginException(boolean suspendException,
        final boolean openOuterConnection, final boolean useTransactionAwareContentSource) throws Exception {

    given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE,
            Status.STATUS_ACTIVE);
    if (suspendException) {
        given(transactionManager.suspend()).willThrow(new SystemException());
    } else {//  ww  w  . j av a2 s  .c  om
        given(transactionManager.suspend()).willReturn(transaction);
        willThrow(new SystemException()).given(userTransaction).begin();
    }

    given(session.getTransactionMode()).willReturn(Session.TransactionMode.QUERY);

    final ContentSource dsToUse = useTransactionAwareContentSource
            ? new TransactionAwareContentSourceProxy(contentSource)
            : contentSource;
    if (dsToUse instanceof TransactionAwareContentSourceProxy) {
        ((TransactionAwareContentSourceProxy) dsToUse).setReobtainTransactionalSessions(true);
    }

    JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
    final TransactionTemplate tt = new TransactionTemplate(ptm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(dsToUse));
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

    try {
        tt.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
                assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(dsToUse));
                assertTrue("JTA synchronizations active",
                        TransactionSynchronizationManager.isSynchronizationActive());
                assertTrue("Is new transaction", status.isNewTransaction());

                Session c = ContentSourceUtils.getSession(dsToUse);
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
                c.getTransactionMode();
                ContentSourceUtils.releaseSession(c, dsToUse);

                c = ContentSourceUtils.getSession(dsToUse);
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
                if (!openOuterConnection) {
                    ContentSourceUtils.releaseSession(c, dsToUse);
                }

                try {
                    tt.execute(new TransactionCallbackWithoutResult() {
                        @Override
                        protected void doInTransactionWithoutResult(TransactionStatus status)
                                throws RuntimeException {
                            assertTrue("Hasn't thread session",
                                    !TransactionSynchronizationManager.hasResource(dsToUse));
                            assertTrue("JTA synchronizations active",
                                    TransactionSynchronizationManager.isSynchronizationActive());
                            assertTrue("Is new transaction", status.isNewTransaction());

                            Session c = ContentSourceUtils.getSession(dsToUse);
                            assertTrue("Has thread session",
                                    TransactionSynchronizationManager.hasResource(dsToUse));
                            ContentSourceUtils.releaseSession(c, dsToUse);

                            c = ContentSourceUtils.getSession(dsToUse);
                            assertTrue("Has thread session",
                                    TransactionSynchronizationManager.hasResource(dsToUse));
                            ContentSourceUtils.releaseSession(c, dsToUse);
                        }
                    });
                } finally {
                    if (openOuterConnection) {
                        c.getTransactionMode();
                        ContentSourceUtils.releaseSession(c, dsToUse);

                    }
                }
            }
        });

        fail("Should have thrown TransactionException");
    } catch (TransactionException ex) {
        // expected
    }

    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(dsToUse));
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

    verify(userTransaction).begin();
    if (suspendException) {
        verify(userTransaction).rollback();
    }

    if (suspendException) {
        verify(session, atLeastOnce()).close();
    } else {
        verify(session, never()).close();
    }
}

From source file:org.grails.datastore.mapping.mongo.query.MongoQuery.java

@Override
protected void flushBeforeQuery() {
    // with Mongo we only flush the session if a transaction is not active to allow for session-managed transactions
    if (!TransactionSynchronizationManager.isSynchronizationActive()) {
        super.flushBeforeQuery();
    }//from   w w  w. j a  v a  2  s  . c o  m
}

From source file:com._4dconcept.springframework.data.marklogic.datasource.DatabaseConnectorJtaTransactionTest.java

@Test
public void testJtaTransactionWithConnectionHolderStillBound() throws Exception {
    @SuppressWarnings("serial")
    JtaTransactionManager ptm = new JtaTransactionManager(userTransaction) {

        @Override//from  w w  w .  ja v a2  s  . c om
        protected void doRegisterAfterCompletionWithJtaTransaction(JtaTransactionObject txObject,
                final List<TransactionSynchronization> synchronizations)
                throws RollbackException, SystemException {
            Thread async = new Thread() {
                @Override
                public void run() {
                    invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_COMMITTED);
                }
            };
            async.start();
            try {
                async.join();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    };
    TransactionTemplate tt = new TransactionTemplate(ptm);
    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(contentSource));
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

    given(userTransaction.getStatus()).willReturn(Status.STATUS_ACTIVE);
    for (int i = 0; i < 3; i++) {
        final boolean releaseCon = (i != 1);

        tt.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
                assertTrue("JTA synchronizations active",
                        TransactionSynchronizationManager.isSynchronizationActive());
                assertTrue("Is existing transaction", !status.isNewTransaction());

                Session c = ContentSourceUtils.getSession(contentSource);
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(contentSource));
                ContentSourceUtils.releaseSession(c, contentSource);

                c = ContentSourceUtils.getSession(contentSource);
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(contentSource));
                if (releaseCon) {
                    ContentSourceUtils.releaseSession(c, contentSource);
                }
            }
        });

        if (!releaseCon) {
            assertTrue("Still has session holder",
                    TransactionSynchronizationManager.hasResource(contentSource));
        } else {
            assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(contentSource));
        }
        assertTrue("JTA synchronizations not active",
                !TransactionSynchronizationManager.isSynchronizationActive());
    }
    verify(session, times(3)).close();
}

From source file:com.newmainsoftech.spray.slingong.datastore.Slim3PlatformTransactionManager.java

@Override
protected DefaultTransactionStatus newTransactionStatus(TransactionDefinition definition, Object transaction,
        boolean newTransaction, boolean newSynchronization, boolean debug, Object suspendedResources) {
    // Validate isolation level and time-out settings 
    validateIsolationLevel(definition.getIsolationLevel());

    boolean actualNewSynchronization = newSynchronization
            && !TransactionSynchronizationManager.isSynchronizationActive();

    GlobalTransaction gtx = (GlobalTransaction) transaction;
    Set<GlobalTransactionState> gtxStateSet = getGlobalTransactionStates(gtx);

    GlobalTransaction newGtx;//from   www .jav  a  2 s  .c o m

    switch (definition.getPropagationBehavior()) {
    case TransactionAttribute.PROPAGATION_NESTED:
        if (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance)) {
            if (!isNestedTransactionAllowed()) {
                throw new TransactionSystemException(String.format(
                        "Unexpected system state: the value of nestedTransactionAllowed boolean "
                                + "member field is false. It should have been checked early as true within "
                                + "handleExistingTransaction method, in order to provide the nested "
                                + "propagation behavior over the transaction (what has already begun "
                                + "GlobalTransaction instance (ID:%1$s)) by nested begin and commit/rollback calls.",
                        (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance) ? gtx.getId()
                                : "null")));
            }
            if (logger.isInfoEnabled()) {
                logger.info(String.format(
                        "Going to provide nested propagation behavior by nested begin and "
                                + "commit/rollback calls on new GlobalTransaction instance over the "
                                + "transaction what has already begun GlobalTransaction instance (ID:%1$s).",
                        gtx.getId()));
            }
        }
        // Enter to below logic (for TransactionAttribute.PROPAGATION_REQUIRES_NEW case)
    case TransactionAttribute.PROPAGATION_REQUIRES_NEW:
        // Sanity check on system state
        if (!newTransaction) {
            throw new IllegalTransactionStateException(String.format(
                    "Unexpected system state: the value of newTransaction boolean member field "
                            + "is false for %1$s propagation behavior (%2$d). Exptected it to be true.",
                    getPropagationBehaviorStr(definition.getPropagationBehavior()),
                    definition.getPropagationBehavior()));
        }

        // Sanity check on current GlobalTransaction instances
        if (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance)) {
            validateCurrentActiveGlobalTransactionToParticipate(gtx, definition);
        }

        // begin new GlobalTransaction
        newGtx = beginGlogalTransaction(gtx, gtxStateSet, definition);

        return new DefaultTransactionStatus(newGtx, newTransaction, actualNewSynchronization,
                definition.isReadOnly(), debug, suspendedResources);
    case TransactionAttribute.PROPAGATION_REQUIRED:
        if (newTransaction) {
            // Sanity check on current GlobalTransaction instances
            if (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance)) {
                throw new IllegalTransactionStateException(String.format(
                        "Unexpected system state: the value of newTransaction boolean member "
                                + "field is true what direct to create new transaction for %1$s "
                                + "propagation behavior (%2$d) though this transaction has already begun "
                                + "the GlobalTransaction instance (ID:%3$s). Exptected it to be false and "
                                + "participate to the existing transaction.",
                        getPropagationBehaviorStr(definition.getPropagationBehavior()),
                        definition.getPropagationBehavior(), gtx.getId()));
            }

            // begin new GlobalTransaction
            newGtx = beginGlogalTransaction(gtx, gtxStateSet, definition);

            return new DefaultTransactionStatus(newGtx, newTransaction, actualNewSynchronization,
                    definition.isReadOnly(), debug, suspendedResources);
        } else {
            // Sanity check on current GlobalTransaction instances
            validateCurrentActiveGlobalTransactionToParticipate(gtx, definition);

            return new DefaultTransactionStatus(gtx, newTransaction, actualNewSynchronization,
                    definition.isReadOnly(), debug, suspendedResources);
        }
    case TransactionAttribute.PROPAGATION_NEVER:
        if (newTransaction && !gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance)) {
            return new DefaultTransactionStatus(null, newTransaction, actualNewSynchronization,
                    definition.isReadOnly(), debug, suspendedResources);
        } else {
            throw new IllegalTransactionStateException(String.format(
                    "Unexpected system state: for %1$s propagation behavior (%2$d), the value of "
                            + "newTransaction boolean member field is expected to be true (actual: %3$b) "
                            + "and transaction Object argument is expected to hold current active "
                            + "GlobalTransaction instance (actual: %4$s %5$s one (ID:%6$s)).",
                    getPropagationBehaviorStr(definition.getPropagationBehavior()),
                    definition.getPropagationBehavior(), newTransaction,
                    (gtxStateSet.contains(GlobalTransactionState.CurrentGlobalTransaction) ? "current"
                            : "not-current"),
                    (gtxStateSet.contains(GlobalTransactionState.ActiveGlobalTransaction) ? "active"
                            : "inactive"),
                    (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance) ? gtx.getId()
                            : "null")));
        }
    case TransactionAttribute.PROPAGATION_NOT_SUPPORTED:
        if (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance)) {
            throw new IllegalTransactionStateException(String.format(
                    "Unexpected system state: for %1$s propagation behavior (%2$d), the "
                            + "transaction Object argument is expected to hold null value (actual: "
                            + "%3$s %4$s GlobalTransaction instance (ID:%5$s)).",
                    getPropagationBehaviorStr(definition.getPropagationBehavior()),
                    definition.getPropagationBehavior(),
                    (gtxStateSet.contains(GlobalTransactionState.CurrentGlobalTransaction) ? "current"
                            : "not-current"),
                    (gtxStateSet.contains(GlobalTransactionState.ActiveGlobalTransaction) ? "active"
                            : "inactive"),
                    gtx.getId()));
        }

        // Create DeafultTransactionState with null transaction
        return new DefaultTransactionStatus(null, newTransaction, actualNewSynchronization,
                definition.isReadOnly(), debug, suspendedResources);
    case TransactionAttribute.PROPAGATION_SUPPORTS:
        if (newTransaction) {
            if (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance)) {
                throw new IllegalTransactionStateException(String.format(
                        "Unexpected system state: for %1$s propagation behavior (%2$d), when the "
                                + "newTransaction is true, the transaction Object argument is expected to "
                                + "hold null value (actual: %3$s %4$s GlobalTransaction instance (ID:%5$s)).",
                        getPropagationBehaviorStr(definition.getPropagationBehavior()),
                        definition.getPropagationBehavior(),
                        (gtxStateSet.contains(GlobalTransactionState.CurrentGlobalTransaction) ? "current"
                                : "not-current"),
                        (gtxStateSet.contains(GlobalTransactionState.ActiveGlobalTransaction) ? "active"
                                : "inactive"),
                        gtx.getId()));
            }
            return new DefaultTransactionStatus(null, newTransaction, actualNewSynchronization,
                    definition.isReadOnly(), debug, suspendedResources);
        } else {
            if (!gtxStateSet.contains(GlobalTransactionState.ActiveGlobalTransaction)
                    || !gtxStateSet.contains(GlobalTransactionState.CurrentGlobalTransaction)) {
                throw new IllegalTransactionStateException(String.format(
                        "Unexpected system state: for %1$s propagation behavior (%2$d), when the "
                                + "newTransaction is false, the transaction Object argument is expected to "
                                + "hold current active GlobalTransaction instance (actual: %3$s %4$s "
                                + "GlobalTransaction instance (ID:%5$s)).",
                        getPropagationBehaviorStr(definition.getPropagationBehavior()),
                        definition.getPropagationBehavior(),
                        (gtxStateSet.contains(GlobalTransactionState.CurrentGlobalTransaction) ? "current"
                                : "not-current"),
                        (gtxStateSet.contains(GlobalTransactionState.ActiveGlobalTransaction) ? "active"
                                : "inactive"),
                        (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance) ? gtx.getId()
                                : "null")));
            }
            return new DefaultTransactionStatus(gtx, newTransaction, actualNewSynchronization,
                    definition.isReadOnly(), debug, suspendedResources);
        }

    case TransactionAttribute.PROPAGATION_MANDATORY:
        if (newTransaction || !gtxStateSet.contains(GlobalTransactionState.ActiveGlobalTransaction)
                || !gtxStateSet.contains(GlobalTransactionState.CurrentGlobalTransaction)) {
            throw new IllegalTransactionStateException(String.format(
                    "Unexpected system state: for %1$s propagation behavior (%2$d), the "
                            + "newTransaction is expected to be false (actual: %3$b) and the transaction "
                            + "Object argument is expected to hold current active GlobalTransaction "
                            + "instance (actual: %3$s %4$s GlobalTransaction instance (ID:%5$s)).",
                    getPropagationBehaviorStr(definition.getPropagationBehavior()),
                    definition.getPropagationBehavior(),
                    (gtxStateSet.contains(GlobalTransactionState.CurrentGlobalTransaction) ? "current"
                            : "not-current"),
                    (gtxStateSet.contains(GlobalTransactionState.ActiveGlobalTransaction) ? "active"
                            : "inactive"),
                    (gtxStateSet.contains(GlobalTransactionState.GlobalTransactionInstance) ? gtx.getId()
                            : "null")));
        }

        return new DefaultTransactionStatus(gtx, newTransaction, actualNewSynchronization,
                definition.isReadOnly(), debug, suspendedResources);

    default:
        throw new IllegalTransactionStateException(String.format(
                "Unknown propagation behavior (%1$d) is specified. Supported propagation "
                        + "behaviors is either PROPAGATION_MANDATORY (%2$d), PROPAGATION_NESTED (%3$d), "
                        + "PROPAGATION_NEVER (%4$d), PROPAGATION_NOT_SUPPORTED (%5$d), "
                        + "PROPAGATION_REQUIRED (%6$d), PROPAGATION_REQUIRES_NEW (%7$d), "
                        + "or PROPAGATION_SUPPORTS (%8$d).",
                definition.getPropagationBehavior(), TransactionAttribute.PROPAGATION_MANDATORY,
                TransactionAttribute.PROPAGATION_NESTED, TransactionAttribute.PROPAGATION_NEVER,
                TransactionAttribute.PROPAGATION_NOT_SUPPORTED, TransactionAttribute.PROPAGATION_REQUIRED,
                TransactionAttribute.PROPAGATION_REQUIRES_NEW, TransactionAttribute.PROPAGATION_SUPPORTS));

    } // switch
}