当前位置: 首页>>代码示例>>Java>>正文


Java TransactionSynchronizationManager.isCurrentTransactionReadOnly方法代码示例

本文整理汇总了Java中org.springframework.transaction.support.TransactionSynchronizationManager.isCurrentTransactionReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionSynchronizationManager.isCurrentTransactionReadOnly方法的具体用法?Java TransactionSynchronizationManager.isCurrentTransactionReadOnly怎么用?Java TransactionSynchronizationManager.isCurrentTransactionReadOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.transaction.support.TransactionSynchronizationManager的用法示例。


在下文中一共展示了TransactionSynchronizationManager.isCurrentTransactionReadOnly方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTransactionReadState

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
/**
 * @return      Returns the read-write state of the current transaction
 * @since 2.1.4
 */
public static TxnReadState getTransactionReadState()
{
    if (!TransactionSynchronizationManager.isSynchronizationActive())
    {
        return TxnReadState.TXN_NONE;
    }
    // Find the read-write state of the txn
    if (getResource(RESOURCE_KEY_TXN_COMPLETING) != null)
    {
        // Transaction is completing.  For all intents and purposes, we are not in a transaction.
        return TxnReadState.TXN_NONE;
    }
    else if (TransactionSynchronizationManager.isCurrentTransactionReadOnly())
    {
        return TxnReadState.TXN_READ_ONLY;
    }
    else
    {
        return TxnReadState.TXN_READ_WRITE;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:26,代码来源:AlfrescoTransactionSupport.java

示例2: beforeCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
/**
 * JTA {@code beforeCompletion} callback: just invoked before commit.
 * <p>In case of an exception, the JTA transaction will be marked as rollback-only.
 * @see org.springframework.transaction.support.TransactionSynchronization#beforeCommit
 */
@Override
public void beforeCompletion() {
	try {
		boolean readOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly();
		this.springSynchronization.beforeCommit(readOnly);
	}
	catch (RuntimeException ex) {
		setRollbackOnlyIfPossible();
		throw ex;
	}
	catch (Error err) {
		setRollbackOnlyIfPossible();
		throw err;
	}
	finally {
		// Process Spring's beforeCompletion early, in order to avoid issues
		// with strict JTA implementations that issue warnings when doing JDBC
		// operations after transaction completion (e.g. Connection.getWarnings).
		this.beforeCompletionCalled = true;
		this.springSynchronization.beforeCompletion();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:SpringJtaSynchronizationAdapter.java

示例3: currentSession

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
public Session currentSession() throws HibernateException {
    Object value = TransactionSynchronizationManager
            .getResource(this.sessionFactory);

    if (value instanceof Session) {
        return (Session) value;
    } else if (value instanceof SessionHolder) {
        SessionHolder sessionHolder = (SessionHolder) value;
        Session session = sessionHolder.getSession();

        if (TransactionSynchronizationManager.isSynchronizationActive()
                && !sessionHolder.isSynchronizedWithTransaction()) {
            TransactionSynchronizationManager
                    .registerSynchronization(new SpringSessionSynchronization(
                            sessionHolder, this.sessionFactory));
            sessionHolder.setSynchronizedWithTransaction(true);

            // Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
            // with FlushMode.MANUAL, which needs to allow flushing within the transaction.
            FlushMode flushMode = session.getFlushMode();

            if (FlushMode.isManualFlushMode(flushMode)
                    && !TransactionSynchronizationManager
                            .isCurrentTransactionReadOnly()) {
                session.setFlushMode(FlushMode.AUTO);
                sessionHolder.setPreviousFlushMode(flushMode);
            }
        }

        return session;
    } else {
        throw new HibernateException("No Session found for current thread");
    }
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:35,代码来源:SpringSessionContext.java

示例4: buildOrObtainSession

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected Session buildOrObtainSession() {
	Session session = super.buildOrObtainSession();
	if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
		session.setFlushMode(FlushMode.MANUAL);
	}
	return session;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:SpringJtaSessionContext.java

示例5: currentSession

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
/**
    * Binds the configured session to Spring's transaction manager strategy if there's no session.
    *
    * @return Returns the configured session, or the one managed by Spring. Never returns null.
    */
   @Override
   public Session currentSession() {
try {
    Session s = defaultSessionContext.currentSession();
    return s;
} catch (HibernateException cause) {

    // There's no session bound to the current thread. Let's open one if
    // needed.
    if (ManagedSessionContext.hasBind(sessionFactory)) {
	return localSessionContext.currentSession();
    }

    Session session;
    session = sessionFactory.openSession();
    TransactionAwareSessionContext.logger.warn("No Session bound to current Thread. Opened new Session ["
	    + session + "]. Transaction: " + session.getTransaction());

    if (registerSynchronization(session)) {
	// Normalizes Session flush mode, defaulting it to AUTO. Required for
	// synchronization.
	FlushMode flushMode = session.getFlushMode();

	if (FlushMode.isManualFlushMode(flushMode)
		&& !TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
	    session.setFlushMode(FlushMode.AUTO);
	}
    }
    ManagedSessionContext.bind(session);

    return session;
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:TransactionAwareSessionContext.java

示例6: getCurrentReadOnlyFlag

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
/**
 * Determine the current read-only flag: by default,
 * the transaction's read-only hint.
 * @return whether there is a read-only hint for the current scope
 * @see org.springframework.transaction.support.TransactionSynchronizationManager#isCurrentTransactionReadOnly()
 */
protected Boolean getCurrentReadOnlyFlag() {
	boolean txReadOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly();
	return (txReadOnly ? Boolean.TRUE : null);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:IsolationLevelDataSourceAdapter.java


注:本文中的org.springframework.transaction.support.TransactionSynchronizationManager.isCurrentTransactionReadOnly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。