Hi Geert,

I've implemented this with a single document using eval:
declare function get-next-id() as xs:int
{
let $query :=
"xquery version '1.0-ml';
let $uri := '/sequence'
let $nextId :=
    if (fn:doc-available($uri)) then
        fn:data(fn:doc($uri)/nextId
    else 1
let $insert := xdmp:document-insert($uri, <nextId>{$nextId + 1}</nextId>, 
xdmp:default-permissions())
return nextId"

return xdmp:eval($query)
};

My expectation is that the /sequence document would be locked when reading the 
nextId because the eval statement includes an update.  Am I mistaken in this?

Bob

------------------------------------------------------------------------------------
The most simplest way would be to have two documents. Perform a dummy update on 
the first, read the second doc after that, increment the number you got from 
the second, and update the second doc with the new number. The dummy update 
will cause a transaction long write lock on the first document, which causes 
automatic synchronisation. You will need to do the update first, as reading the 
second doc will not prevent it being updated or read by others..
 
Kind regards,
Geert
 
                                          
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to