悲观锁定在GORM哪里查询 [英] pessimistic locking in GORM where query

查看:620
本文介绍了悲观锁定在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哪里查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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