2012-04-19 11 views
2

Grails GORM withTransactiongroovy.sql.Sqlは、ストアドプロシージャのSQL呼び出しをwithTransactionの内部に置くと同じ接続を使用しますか?たとえば: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') 
    } 
    } 

} 

答えて

2

を処理するためのサービスを持ってこれを行う方法を、私を見つけた:

は私がコマンドを考えてみましょう。

def sessionFactory 

//after GORM saves... 
sessionFactory.currentSession.flush() 
Sql s = new Sql(sessionFactory.currentSession.connection() ) 
s.call() 

さらに詳しい情報はthis topicです。

関連する問題