如何知道grails服务中的交易方法是否成功? [英] How to know if a transactional method in a grails service was successful?

查看:102
本文介绍了如何知道grails服务中的交易方法是否成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class SomeService {
static transactional = true

def someMethod(){
...
a.save()
....
b.save()
....
c.save()
....
等...
}

}



我想知道事务性方法是否成功,我不想检查每个域对象中的错误属性因为逻辑涉及许多域类,所以很难。

  a.save(failOnError:true)
b.save(failOnError:true)
c.save(failOnError:true)
d .save(failOnError:true)

我假设你想要的服务是抛出异常单域保存错误,并在这种情况下回滚事务。


I have something like this:

class SomeService {
   static transactional = true

    def someMethod(){
      ...
      a.save()
      ....
      b.save()
      ....
      c.save()
      ....
      etc...
}

}

I want to know if the transactional method was successful or not, I don't want to check the error property in each domain object because the logic involve many domain classes and it would be difficult.

解决方案

Use

a.save(failOnError: true) 
b.save(failOnError: true)
c.save(failOnError: true) 
d.save(failOnError: true)

I'm assuming what you want is the service to throw exception on error of a single domain save, and rollback the transaction in such cases.

这篇关于如何知道grails服务中的交易方法是否成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆