悲观锁定在GORM哪里查询

编程入门 行业动态 更新时间:2024-10-23 06:24:12
本文介绍了悲观锁定在GORM哪里查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

类似于

def query = Person.where { firstName ==Bart} //而不是where.findAll()列出personsLocked = where .lockAll()

我知道,我可以通过标准API实现:

列表personsLocked = Person.createCriteria()。list { eq('firstName','Bart') lock true }

有没有办法通过where查询来实现这一点?

解决方案

lock 在 grails.gorm.DetachedCriteria (的结果,其中),并且只能从 createCriteira 提供的org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder 或通过显式调用 lock(),因此将 LockMode 更改为 LockMode.UPGRADE 您可以使用传播点运算符并在获得结果后锁定结果。

I'd like to achieve pessimistic lock with GORM's where query.

Something like

def query = Person.where { firstName == "Bart" } //instead of where.findAll() List personsLocked = where.lockAll()

I know, I can achieve that by criteria API:

List personsLocked = Person.createCriteria().list { eq('firstName', 'Bart') lock true }

Is there a way to achieve this via the "where" query ?

解决方案

lock is not available in the grails.gorm.DetachedCriteria (result of where) and is only available from the org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder provided by createCriteira or by explicitly calling lock() on the instances and thus changing the LockMode to LockMode.UPGRADE

You could always use the spread dot operator and lock the results after you get them.

更多推荐

悲观锁定在GORM哪里查询

本文发布于:2023-06-04 19:09:09,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:悲观   GORM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!