2008-07-02
grails services transaction
关键字: grails services transaction
在 graisl 应用中,默认情况下,services 的事务是系统自动控制的,默认下 是true
可以通过以下几种方法改变transaction的状态
1) 通过sessonFactory
def session = sessionFactory.getCurrentSession()
Transaction tx = session.beginTransaction()
<>
tx.commit()
or
tx.rollback()
2)withTransaction grails 文档中介绍的
def transferFunds = {
Account.withTransaction { status ->
def source = Account.get(params.from)
def dest = Account.get(params.to)
def amount = params.amount.toInteger() if(source.active) { source.balance -= amount if(dest.active) { dest.amount += amount } else { status.setRollbackOnly() } }
}
}
可以通过以下几种方法改变transaction的状态
1) 通过sessonFactory
def session = sessionFactory.getCurrentSession()
Transaction tx = session.beginTransaction()
<>
tx.commit()
or
tx.rollback()
2)withTransaction grails 文档中介绍的
def transferFunds = {
Account.withTransaction { status ->
def source = Account.get(params.from)
def dest = Account.get(params.to)
def amount = params.amount.toInteger() if(source.active) { source.balance -= amount if(dest.active) { dest.amount += amount } else { status.setRollbackOnly() } }
}
}
发表评论
- 浏览: 15900 次
- 性别:

- 来自: 济南

- 详细资料
搜索本博客
我的相册
detail
共 1 张
共 1 张
最新评论
-
grails 根据数据库自动生 ...
不错,不知道实践结果感觉如何,呵呵
-- by casephoen -
grails 导出 excel
你确认在你的controller中定义这个XlsExportService 吗 ...
-- by dellsoft -
grails 导出 excel
不能执行:java.lang.NullPointerException: Can ...
-- by ourfirebird -
jsecurity 资料
一直在关注中,其基于pojo的特性还是很诱人的.
-- by agile_boy -
extjs dwr spring
谢谢,学习,学习
-- by fang_qi






评论排行榜