Damn it! This is a pretty odd bug with db4o SODA - 查詢條件體位影響查詢結果

def _m = Module.find(name:'studyLevelPerson'), _pid='76f198cf-9a26-49ec-82ed-f52d4b772875'
def closure = {m, pid, t, q->
  if(m.belongsTo) {
    // sop is the parent object of objects shared by all
    def sop = Module.find(name:m.belongsTo).clazz.find(id:'00000000-0000-0000-0000-000000000000',all:true)
    q.descend(m.belongsTo).descend('id').constrain(pid).or(
      q.descend(m.belongsTo).constrain(sop)
    )
  }
}.curry(_m, _pid, null)
Person.findAll(closure)

 

def _m = Module.find(name:'studyLevelPerson'), _pid='76f198cf-9a26-49ec-82ed-f52d4b772875'
def closure = {m, pid, t, q->
  if(m.belongsTo) {
    // sop is the parent object of objects shared by all
    def sop = Module.find(name:m.belongsTo).clazz.find(id:'00000000-0000-0000-0000-000000000000',all:true)
    q.descend(m.belongsTo).constrain(sop).or(
       q.descend(m.belongsTo).descend('id').constrain(pid)
    )
  }
}.curry(_m, _pid, null)
Person.findAll(closure)
 

 


查詢只涉及兩個條件(條件1:parent object 的id爲'76f198cf-9a26-49ec-82ed-f52d4b772875'
; 條件2:parent object爲sop
) ,而這兩段代碼執行的結果竟然截然不同!後者的結果纔是預期的結果(爲空集合,因爲數據庫中不存在滿足“條件1 OR 條件2”的數據),前者似乎是把兩個條件都弄掉了,於是返回數據庫中該類的所有實例。


兩者外在的區別在於兩個條件體位不同,查詢路徑一個由深入淺,一個由淺入深。看來得注意體位,要由淺入深。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章