2
如果我把存儲過程的sql調用放在withTransaction
裏面,Grails GORM withTransaction
和groovy.sql.Sql
會使用相同的連接嗎?例如:Grails:groovy.sql.Sql和Model.withTransaction會發生什麼?
可以說我有一個命令:
@Validateable
class MyCommand {
List<MyModel> listOfModel
}
,然後我有一個服務來處理這個命令
class MyService {
def dataSource
def handleCommand(MyCommand command) {
MyModel.withTransaction { status ->
for(MyModel m : command.listOfModel) {
if(!m.save()) {
status.setRollbackOnly()
throw new MyException(m.errors)
}
}
//now I need to call a stored proc. This will use the same connection?
//withTransaction will commit the call?
Sql s = new Sql(dataSource)
s.call('my_stored_proc')
}
}
}