Example usage for org.springframework.transaction TransactionDefinition ISOLATION_DEFAULT

List of usage examples for org.springframework.transaction TransactionDefinition ISOLATION_DEFAULT

Introduction

In this page you can find the example usage for org.springframework.transaction TransactionDefinition ISOLATION_DEFAULT.

Prototype

int ISOLATION_DEFAULT

To view the source code for org.springframework.transaction TransactionDefinition ISOLATION_DEFAULT.

Click Source Link

Document

Use the default isolation level of the underlying datastore.

Usage

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

private UserTransaction getTxn() {
    return new SpringAwareUserTransaction(transactionManager, false, TransactionDefinition.ISOLATION_DEFAULT,
            TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.TIMEOUT_DEFAULT);
}

From source file:org.springextensions.neodatis.NeoDatisTransactionManager.java

@Override
protected void doBegin(Object transaction, TransactionDefinition transactionDefinition)
        throws TransactionException {
    if (transactionDefinition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        throw new InvalidIsolationLevelException("NeoDatis does not support an isolation level concept.");
    }/*from w  w  w  .ja  va 2 s .  co m*/

    ODB odb = null;

    try {
        NeoDatisTransactionObject transactionObject = (NeoDatisTransactionObject) transaction;
        if (transactionObject.getODBHolder() == null) {
            odb = getOdb();
            logger.debug("Using given ODB [{}] for the current thread transaction.", odb);
            transactionObject.setODBHolder(new ODBHolder(odb));
        }

        ODBHolder odbHolder = transactionObject.getODBHolder();

        odbHolder.setSynchronizedWithTransaction(true);

        // start transaction
        // no-op
        // register timeout
        if (transactionDefinition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
            transactionObject.getODBHolder().setTimeoutInSeconds(transactionDefinition.getTimeout());
        }

        //Bind session holder to the thread
        TransactionSynchronizationManager.bindResource(getOdb(), odbHolder);

    } catch (Exception e) {
        throw new CannotCreateTransactionException("Can not create an NeoDatis transaction.", e);
    }

}

From source file:org.dalesbred.integration.spring.SpringTransactionManager.java

static int springIsolationCode(@NotNull Isolation isolation) {
    if (isolation == Isolation.DEFAULT)
        return TransactionDefinition.ISOLATION_DEFAULT;
    else//  w ww  .  j  av a2s.c  om
        return isolation.getJdbcLevel();
}

From source file:org.springextensions.db4o.Db4oTransactionManager.java

protected void doBegin(Object transaction, TransactionDefinition transactionDefinition)
        throws TransactionException {
    if (transactionDefinition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        throw new InvalidIsolationLevelException("Db4o does not support an isolation level concept");
    }//from w w w. jav  a  2s .co  m

    ObjectContainer container = null;

    try {
        Db4oTransactionObject txObject = (Db4oTransactionObject) transaction;
        if (txObject.getObjectContainerHolder() == null) {
            // use the given container
            container = getObjectContainer();
            logger.debug("Using given objectContainer [{}] for the current thread transaction", container);
            txObject.setObjectContainerHolder(new ObjectContainerHolder(container));
        }

        ObjectContainerHolder containerHolder = txObject.getObjectContainerHolder();

        containerHolder.setSynchronizedWithTransaction(true);

        /*
        * We have no notion of flushing inside a db4o object container
        *
        if (transactionDefinition.isReadOnly() && txObject.isNewObjectContainerHolder()) {
        containerHolder.setReadOnly(true);
        }
                
        if (!transactionDefinition.isReadOnly() && !txObject.isNewObjectContainerHolder()) {
        if (containerHolder.isReadOnly()) {
        containerHolder.setReadOnly(false);
        }
        }
        */

        // start the transaction
        // no-op
        // Register transaction timeout.
        if (transactionDefinition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
            txObject.getObjectContainerHolder().setTimeoutInSeconds(transactionDefinition.getTimeout());
        }

        // Bind the session holder to the thread.
        TransactionSynchronizationManager.bindResource(getObjectContainer(), containerHolder);
    } catch (Exception ex) {
        throw new CannotCreateTransactionException("Could not start db4o object container transaction", ex);
    }
}

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

/**
 * Specify the default isolation level to use for Session retrieval,
 * according to the XDBC {@link Session} constants
 * (equivalent to the corresponding Spring
 * {@link TransactionDefinition} constants).
 * <p>If not specified, the target ContentSource's default will be used.
 * Note that a transaction-specific isolation value will always override
 * any isolation setting specified at the ContentSource level.
 * @param isolationLevel the default isolation level to use for session retrieval
 * @see Session.TransactionMode#UPDATE/* w w  w . jav a2s  .  c  o  m*/
 * @see Session.TransactionMode#QUERY
 * @see TransactionDefinition#ISOLATION_READ_UNCOMMITTED
 * @see TransactionDefinition#ISOLATION_READ_COMMITTED
 * @see TransactionDefinition#ISOLATION_REPEATABLE_READ
 * @see TransactionDefinition#ISOLATION_SERIALIZABLE
 * @see TransactionDefinition#getIsolationLevel()
 * @see TransactionSynchronizationManager#getCurrentTransactionIsolationLevel()
 */
public void setIsolationLevel(int isolationLevel) {
    if (!constants.getValues(DefaultTransactionDefinition.PREFIX_ISOLATION).contains(isolationLevel)) {
        throw new IllegalArgumentException("Only values of isolation constants allowed");
    }
    this.isolationLevel = (isolationLevel != TransactionDefinition.ISOLATION_DEFAULT ? isolationLevel : null);
}

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

/**
 * Prepare the given Session with the given transaction semantics.
 * @param ses the Session to prepare//from w  ww . j  a v  a2s  .c om
 * @param definition the transaction definition to apply
 * @return the previous isolation level, if any
 * @throws XccException if thrown by XDBC methods
 * @see #resetSessionAfterTransaction
 */
public static Integer prepareSessionForTransaction(Session ses, TransactionDefinition definition)
        throws XccException {

    Assert.notNull(ses, "No Session specified");

    if (definition != null && definition.isReadOnly()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Setting XDBC Session [" + ses + "] read-only");
        }
        ses.setTransactionMode(Session.TransactionMode.QUERY);
    } else {
        ses.setTransactionMode(Session.TransactionMode.UPDATE);
    }

    // Apply specific isolation level, if any.
    Integer previousIsolationLevel = null;
    if (definition != null && definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        if (logger.isDebugEnabled()) {
            logger.debug("Changing isolation level of XDBC Session [" + ses + "] to "
                    + definition.getIsolationLevel());
        }
        int currentIsolation = ses.getTransactionMode().ordinal();
        if (currentIsolation != definition.getIsolationLevel()) {
            previousIsolationLevel = currentIsolation;
            ses.setTransactionMode(Session.TransactionMode.values()[definition.getIsolationLevel()]);
        }
    }

    return previousIsolationLevel;
}

From source file:org.cfr.capsicum.datasource.DataSourceUtils.java

/**
 * Prepare the given Connection with the given transaction semantics.
 * @param con the Connection to prepare//ww w .jav  a 2 s  . c  om
 * @param definition the transaction definition to apply
 * @return the previous isolation level, if any
 * @throws SQLException if thrown by JDBC methods
 * @see #resetConnectionAfterTransaction
 */
public static Integer prepareConnectionForTransaction(Connection con, TransactionDefinition definition)
        throws SQLException {

    Assert.notNull(con, "No Connection specified");

    // Set read-only flag.
    if (definition != null && definition.isReadOnly()) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Setting JDBC Connection [" + con + "] read-only");
            }
            con.setReadOnly(true);
        } catch (Throwable ex) {
            // SQLException or UnsupportedOperationException
            // -> ignore, it's just a hint anyway.
            logger.debug("Could not set JDBC Connection read-only", ex);
        }
    }

    // Apply specific isolation level, if any.
    Integer previousIsolationLevel = null;
    if (definition != null && definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        if (logger.isDebugEnabled()) {
            logger.debug("Changing isolation level of JDBC Connection [" + con + "] to "
                    + definition.getIsolationLevel());
        }
        previousIsolationLevel = new Integer(con.getTransactionIsolation());
        con.setTransactionIsolation(definition.getIsolationLevel());
    }

    return previousIsolationLevel;
}

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

private UserTransaction getFailingTxn() {
    return new SpringAwareUserTransaction(failingTransactionManager, false,
            TransactionDefinition.ISOLATION_DEFAULT, TransactionDefinition.PROPAGATION_REQUIRED,
            TransactionDefinition.TIMEOUT_DEFAULT);
}

From source file:org.guzz.web.context.spring.GuzzTransactionManager.java

@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
    GuzzTransactionObject txObject = (GuzzTransactionObject) transaction;

    //TODO: checkout the outside DataSourceTransactionManager 
    //      if (txObject.hasConnectionHolder() && !txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
    //         throw new IllegalTransactionStateException(
    //               "Pre-bound JDBC Connection found! GuzzTransactionManager does not support " +
    //               "running within DataSourceTransactionManager if told to manage the DataSource itself. ") ;
    //      }//from   ww w . j ava  2  s  .co m

    WriteTranSession writeTranSession = null;

    try {
        if (txObject.getSessionHolder() == null
                || txObject.getSessionHolder().isSynchronizedWithTransaction()) {
            writeTranSession = getTransactionManager().openRWTran(false);

            if (logger.isDebugEnabled()) {
                logger.debug("Opened new Session [" + TransactionManagerUtils.toString(writeTranSession)
                        + "] for Guzz transaction");
            }
            txObject.setWriteTranSession(writeTranSession);
        }

        writeTranSession = txObject.getSessionHolder().getWriteTranSession();

        if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
            // We should set a specific isolation level but are not allowed to...
            IsolationsSavePointer oldSavePointer = writeTranSession
                    .setTransactionIsolation(definition.getIsolationLevel());

            txObject.setIsolationsSavePointer(oldSavePointer);
        }

        // Register transaction timeout.
        int timeout = determineTimeout(definition);
        if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
            txObject.getSessionHolder().setTimeoutInSeconds(timeout);
        }

        // Bind the session holder to the thread.
        if (txObject.isNewWriteTranSessionHolder()) {
            TransactionSynchronizationManager.bindResource(getTransactionManager(),
                    txObject.getSessionHolder());
        }
        txObject.getSessionHolder().setSynchronizedWithTransaction(true);

    } catch (Exception ex) {
        if (txObject.isNewWriteTranSession()) {
            try {
                if (writeTranSession != null) {
                    //TransactionIsolation?????
                    writeTranSession.rollback();
                }
            } catch (Throwable ex2) {
                logger.debug("Could not rollback WriteTranSession after failed transaction begin", ex);
            } finally {
                TransactionManagerUtils.closeSession(writeTranSession);
            }
        }
        throw new CannotCreateTransactionException("Could not open Guzz WriteTranSession for transaction", ex);
    }
}

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

protected void validateIsolationLevel(final int isolationLevel) throws TransactionException {
    if ((isolationLevel != TransactionDefinition.ISOLATION_DEFAULT)
            && (isolationLevel != TransactionDefinition.ISOLATION_SERIALIZABLE)) {
        throw new InvalidIsolationLevelException(String.format(
                "%1$d is not among the supported isolation levels; "
                        + "only ISOLATION_DEFAULT (%2$d) and ISOLATION_SERIALIZABLE (%3$d) are supported.",
                isolationLevel, TransactionDefinition.ISOLATION_DEFAULT,
                TransactionDefinition.ISOLATION_SERIALIZABLE));
    }/*ww  w. j a  v a 2s  . c om*/
}