• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NoTransactionException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.transaction.NoTransactionException的典型用法代码示例。如果您正苦于以下问题:Java NoTransactionException类的具体用法?Java NoTransactionException怎么用?Java NoTransactionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NoTransactionException类属于org.springframework.transaction包,在下文中一共展示了NoTransactionException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: invoke

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
@Override
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
    Sql sql = this.sql;

    if (method.getDeclaringClass() == SqlStreamHolder.class) {
        return sql;
    }

    TransactionStatus transactionStatus = null;
    try {
        transactionStatus = TransactionAspectSupport.currentTransactionStatus();
    } catch (NoTransactionException e) {
        if (FAIL_WITHOUT_TRANSACTION) {
            throw e;
        }
    }
    if (transactionStatus instanceof SqlStreamTransactionStatus) {
        sql = ((SqlStreamTransactionStatus) transactionStatus).transaction;
    }

    return method.invoke(sql, objects);
}
 
开发者ID:bendem,项目名称:sql-streams-spring,代码行数:23,代码来源:SqlStreamTransactionAwareProxy.java


示例2: before

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
	// do transaction checks
	if (requireTransactionContext) {
		TransactionInterceptor.currentTransactionStatus();
	}
	else {
		try {
			TransactionInterceptor.currentTransactionStatus();
			throw new RuntimeException("Shouldn't have a transaction");
		}
		catch (NoTransactionException ex) {
			// this is Ok
		}
	}
	super.before(method, args, target);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AdvisorAutoProxyCreatorIntegrationTests.java


示例3: checkNoStatusOnThread

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
private void checkNoStatusOnThread()
{
    try
    {
        TransactionAspectSupport.currentTransactionStatus();
        fail("Spring transaction info is present outside of transaction boundaries");
    }
    catch (NoTransactionException e)
    {
        // expected
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:13,代码来源:SpringAwareUserTransactionTest.java


示例4: currentTransactionStatus

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
/**
 * Return the transaction status of the current method invocation.
 * Mainly intended for code that wants to set the current transaction
 * rollback-only but not throw an application exception.
 * @throws NoTransactionException if the transaction info cannot be found,
 * because the method was invoked outside an AOP invocation context
 */
public static TransactionStatus currentTransactionStatus() throws NoTransactionException {
	TransactionInfo info = currentTransactionInfo();
	if (info == null) {
		throw new NoTransactionException("No transaction aspect-managed TransactionStatus in scope");
	}
	return currentTransactionInfo().transactionStatus;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:TransactionAspectSupport.java


示例5: exec

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
public Object[] exec() {
    return (Object[]) execute(new RedisCallback<Jedis>() {
        public Object doInRedis(Jedis redis) {
            if (transaction != null) {
                List<Object> results = transaction.exec();
                try {
                    return results.toArray(new Object[results.size()]);
                } finally {
                    transaction = null;
                }
            }
            throw new NoTransactionException("No transaction started. Call multi() first!");
        }
    });
}
 
开发者ID:grails,项目名称:gorm-redis,代码行数:16,代码来源:JedisTemplate.java


示例6: currentTransactionStatus

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
/**
 * Return the transaction status of the current method invocation.
 * Mainly intended for code that wants to set the current transaction
 * rollback-only but not throw an application exception.
 * @throws NoTransactionException if the transaction info cannot be found,
 * because the method was invoked outside an AOP invocation context
 */
public static TransactionStatus currentTransactionStatus() throws NoTransactionException {
	TransactionInfo info = currentTransactionInfo();
	if (info == null || info.transactionStatus == null) {
		throw new NoTransactionException("No transaction aspect-managed TransactionStatus in scope");
	}
	return info.transactionStatus;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:TransactionAspectSupport.java


示例7: checkTransactionStatus

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
protected void checkTransactionStatus(boolean expected) {
	try {
		TransactionInterceptor.currentTransactionStatus();
		if (!expected) {
			fail("Should have thrown NoTransactionException");
		}
	}
	catch (NoTransactionException ex) {
		if (expected) {
			fail("Should have current TransactionStatus");
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:AbstractTransactionAspectTests.java


示例8: getTransactionInfo

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
/**
 * Gets the current transaction info, or null if none exists.
 * <p>
 * A check is done to ensure that the transaction info on the stack is exactly
 * the same instance used when this transaction was started.
 * The internal status is also checked against the transaction info.
 * These checks ensure that the transaction demarcation is done correctly and that
 * thread safety is adhered to.
 * 
 * @return Returns the current transaction
 */
private TransactionInfo getTransactionInfo()
{
    // a few quick self-checks
    if (threadId < 0 && internalStatus != Status.STATUS_NO_TRANSACTION)
    {
        throw new RuntimeException("Transaction has been started but there is no thread ID");
    }
    else if (threadId >= 0 && internalStatus == Status.STATUS_NO_TRANSACTION)
    {
        throw new RuntimeException("Transaction has not been started but a thread ID has been recorded");
    }
    
    TransactionInfo txnInfo = null;
    try
    {
        txnInfo = TransactionAspectSupport.currentTransactionInfo();
        // we are in a transaction
    }
    catch (NoTransactionException e)
    {
        // No transaction.  It is possible that the transaction threw an exception during commit.
    }
    // perform checks for active transactions
    if (internalStatus == Status.STATUS_ACTIVE)
    {
        if (Thread.currentThread().getId() != threadId)
        {
            // the internally stored transaction info (retrieved in begin()) should match the info
            // on the thread
            throw new RuntimeException("UserTransaction may not be accessed by multiple threads");
        }
        else if (txnInfo == null)
        {
            // internally we recorded a transaction starting, but there is nothing on the thread
            throw new RuntimeException("Transaction boundaries have been made to overlap in the stack");
        }
        else if (txnInfo != internalTxnInfo)
        {
            // the transaction info on the stack isn't the one we started with
            throw new RuntimeException("UserTransaction begin/commit mismatch");
        }
    }
    return txnInfo;
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:56,代码来源:SpringAwareUserTransaction.java


示例9: currentTransactionInfo

import org.springframework.transaction.NoTransactionException; //导入依赖的package包/类
/**
 * Subclasses can use this to return the current TransactionInfo.
 * Only subclasses that cannot handle all operations in one method,
 * such as an AspectJ aspect involving distinct before and after advice,
 * need to use this mechanism to get at the current TransactionInfo.
 * An around advice such as an AOP Alliance MethodInterceptor can hold a
 * reference to the TransactionInfo throughout the aspect method.
 * <p>A TransactionInfo will be returned even if no transaction was created.
 * The {@code TransactionInfo.hasTransaction()} method can be used to query this.
 * <p>To find out about specific transaction characteristics, consider using
 * TransactionSynchronizationManager's {@code isSynchronizationActive()}
 * and/or {@code isActualTransactionActive()} methods.
 * @return TransactionInfo bound to this thread, or {@code null} if none
 * @see TransactionInfo#hasTransaction()
 * @see org.springframework.transaction.support.TransactionSynchronizationManager#isSynchronizationActive()
 * @see org.springframework.transaction.support.TransactionSynchronizationManager#isActualTransactionActive()
 */
protected static TransactionInfo currentTransactionInfo() throws NoTransactionException {
	return transactionInfoHolder.get();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:TransactionAspectSupport.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GeometryFilter类代码示例发布时间:2022-05-22
下一篇:
Java LayoutManager类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap