Hi, All

I want to get a unique id at ML, a xml called ids.xml will store my id just
like below:

<id>100</id>

Here is my xquery function, it will update ids.xml file after calling it.

define function nextSomeID($number as xs:integer) as xs:integer
{
  let $id := doc("ids.xml")/id/text()
  let $nextId := xs:integer($id) + 1
  let $update := xdmp:node-replace($id, text{$nextId + $number - 1})
  return $nextId
}

the java client method (synchronized also) will call this function to get
next id, but in fact, I still get duplicated id some times.

Notice:
1) I using multi-thread to call this java method.
2) para $number can be 1,2,3,4...., for example, if $number is 3 and current
id=2, nextSomeID will return 3, id will be 2+3=5

So, what situation will happen this? Very confused.

The only possible way is $id get the duplicated value at here:

let $id := doc("ids.xml")/id/text()

But seems before return $nextId, ids.xml has been updated. so,
doc("ids.xml")/id/text() will always get latest values, right?

Very confused about that, can anyone explain that?



-- 
Rgds!

Tide Kong
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to