2

Grails GORMwithTransactiongroovy.sql.Sql、ストアドプロシージャのSQL呼び出しを内部に配置すると、同じ接続が使用されます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')
    }
  }

}
4

1 に答える 1

2

私はこれを行う方法を見つけました。

def sessionFactory

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

このトピックの詳細情報。

于 2012-04-19T20:34:39.330 に答える