Example usage for org.springframework.transaction.support DefaultTransactionStatus DefaultTransactionStatus

List of usage examples for org.springframework.transaction.support DefaultTransactionStatus DefaultTransactionStatus

Introduction

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

Prototype

public DefaultTransactionStatus(@Nullable Object transaction, boolean newTransaction,
        boolean newSynchronization, boolean readOnly, boolean debug, @Nullable Object suspendedResources) 

Source Link

Document

Create a new DefaultTransactionStatus instance.

Usage

From source file:fr.paris.lutece.portal.service.database.LuteceTransactionManager.java

/**
 * {@inheritDoc}/*from  www . j  a  va  2  s  .  c  o m*/
 */
@Override
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
    TransactionStatus trStatus = new DefaultTransactionStatus(null, true, false, false, false, null);
    TransactionManager.beginTransaction(getPlugin());

    return trStatus;
}

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 w  w w  .j  av  a  2s .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
}

From source file:org.openspaces.core.transaction.internal.InternalAsyncFutureListener.java

public static <T> AsyncFutureListener<T> wrapIfNeeded(AsyncFutureListener<T> listener, GigaSpace gigaSpace) {
    DefaultTransactionProvider txProvider = (DefaultTransactionProvider) gigaSpace.getTxProvider();
    JiniTransactionHolder holder = txProvider.getHolder();
    PlatformTransactionManager transactionManager = txProvider.getTransactionManager();
    if (holder == null || transactionManager == null) {
        // just wrap for exception translation
        return new InternalAsyncFutureListener<T>(gigaSpace, listener, null, transactionManager, holder);
    }/* w ww.ja  va 2 s  . com*/
    // here, we create a dummy transaction status (with its new transaction set to true, so the commit/roolback
    // process will be performed). We also increase the ref count of the transaction, so only the last one will
    // be performed
    AbstractJiniTransactionManager.JiniTransactionObject jiniTransactionObject = new AbstractJiniTransactionManager.JiniTransactionObject();
    jiniTransactionObject.setJiniHolder(holder, false);
    TransactionStatus txStatus = new DefaultTransactionStatus(jiniTransactionObject, true, false, false, false,
            null);
    holder.incRef();
    return new InternalAsyncFutureListener<T>(gigaSpace, listener, txStatus, transactionManager, holder);
}

From source file:org.springframework.transaction.support.AbstractPlatformTransactionManager.java

/**
 * Create a TransactionStatus instance for the given arguments.
 *///from w w  w .j av  a  2s .  c o m
protected DefaultTransactionStatus newTransactionStatus(TransactionDefinition definition,
        @Nullable Object transaction, boolean newTransaction, boolean newSynchronization, boolean debug,
        @Nullable Object suspendedResources) {

    boolean actualNewSynchronization = newSynchronization
            && !TransactionSynchronizationManager.isSynchronizationActive();
    return new DefaultTransactionStatus(transaction, newTransaction, actualNewSynchronization,
            definition.isReadOnly(), debug, suspendedResources);
}