如何在Grails GORM中强制刷新 [英] How to force flushing in Grails GORM

查看:131
本文介绍了如何在Grails GORM中强制刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项向操作员分配任务的服务。
在一个方法中,我在循环内及时分配许多任务。我想冲洗任务,操作员和DistributionLog。如果我只有一个域来保存,我想我可以做一些像

  Operator.withTransaction {//...some code } 

但我至少有3个域名要保存,并且更糟糕,其中两个域名相互依赖。操作员有一个任务列表。



在操作员可以完成任务之前,我无法等待所有分配完成,因此我必须强制它完成冲洗。为了使它更难,它全部放在multitenantService.doWithTenant()(多租户插件)中。

您可以使用会话来获取会话所有域类中都有 withSession 方法,并调用 flush()

  Operator.withSession {session  - > 
// ...
session.flush()
}


I have a service that distributes tasks to operators. Inside a method I distribute many tasks in time inside a loop. I want to flush the task, the operator, and a DistributionLog. If I just had one domain to save I think I could do something like

Operator.withTransaction{ //...some code }

but I have at least 3 domains to save and to make it even worse, two of them have dependency on each other. The operator have a list of tasks.

I can't wait all the distribution to finish before an operator can get his tasks, so I have to force it to flush. To make it even harder, it's all inside a multitenantService.doWithTenant() (multitenant plugin)

解决方案

You can get the session using the withSession method available in all domain classes and call to flush() on it.

Operator.withSession { session ->
   // ...
   session.flush()
}

这篇关于如何在Grails GORM中强制刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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