[MarkLogic Dev General] unique ids

Paul M pjmaip at yahoo.com
Tue Oct 14 10:38:40 PDT 2008


(:~
 : Gets the next unique id. Reserves as many id as needed.
 : i.e. current id=3 next-id(5) will return 4 and will set current id=8.
 : so 4,5,6,7,8 are now unique for you to use
 : calling next-id(2) will now return 9 and will set current id=10.
 : so 9, 10 are now unique for you to use
 : Sequences not used are lost.
 :
 : @param   $reserve the number of unique id's required 
 :) 
define function next-id($reserve as xs:unsignedLong) as xs:unsignedLong
{
    let $last-unique-id := xs:long(fn:doc("/my-id.xml")//id)
    let $new-unique-id := $last-unique-id + $reserve
    let $id := <id>{$new-unique-id}</id>
    let $dumb := xdmp:document-insert("/seg-id.xml", $id,
        (xdmp:permission("my-access", "update"),
                xdmp:permission("my-access", "insert"),
                xdmp:permission("my-access","read")))
    return ($last-unique-id + 1)
}


1. I do not need an explicit  lock because flowr stmt uses document-insert? The read and the insert are one flowr stmt?

2.
Any preferences document-insert vs node-insert? (ps. I prefer
explicitly setting the permissions. I presume, with node-insert, this
would not be required?)

3. Reasonable solution in trying to mimic Oracle functionality?



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xqzone.marklogic.com/pipermail/general/attachments/20081014/e8fb7f55/attachment.html


More information about the General mailing list