That is very elegant. Thank you Mike. I'm still struggling with shifting my thinking around from a procedural language to a declarative language. This will work perfectly.
Mark -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Blakeley Sent: Thursday, September 25, 2008 2:26 PM To: General Mark Logic Developer Discussion Subject: Re: [MarkLogic Dev General] restructuring to avoid undetectable deadlocks Mark, The best solution is to think about the problem as a single transaction: don't attempt to emulate dirty reads. In the developer training, we talk about this issue when discussing updates, and show its use in the implementation of a persistent FIFO queue. Untested code... let $doc-root := doc($uri)/root let $user-element as element()? := $doc-root/[EMAIL PROTECTED] eq $user] let $new-child := element new-child { 1234 } let $new := if (not($user-element)) then element child { attribute user { $user }, $new-child } else element { node-name($user-element) } { $user-element/@*, $user-element/node(), $new-child } return if ($doc-root) then xdmp:node-insert-child($doc-root, $new) else xdmp:document-insert($uri, element root { $new }) -- Mike Mark Boyd wrote: > Can anyone provide suggestions on how to restructure a module to avoid > undetectable deadlocks as outlined in section 4 of the developer's guide? > Specifically, how can I: > > > 1) Create a document if it isn't already found in the database > > 2) Create a user specific element if it doesn't already exist for the > user in that document > > 3) Add a child element to the user element in that document if such a > child element does not already exist > > 4) Update an existing child element if it does exist > > I attempted to use eval statements to ensure visibility along the way but > ended up with deadlocks. What strategy should I follow restructuring this > code to avoid such deadlocks? > > Thanks. > > Mark > > ---------------------------------------------------------------------- > NOTICE: This email message is for the sole use of the intended recipient(s) > and may contain confidential and privileged information. Any unauthorized > review, use, disclosure or distribution is prohibited. If you are not the > intended recipient, please contact the sender by reply email and destroy all > copies of the original message. > > > > ------------------------------------------------------------------------ > > _______________________________________________ > General mailing list > [email protected] > http://xqzone.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general ---------------------------------------------------------------------- NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
