Loading TOC...

MarkLogic 12 EA 2 Product Documentation
xdmp:document-locks

xdmp:document-locks(
   [$uri as xs:string*]
) as document-node()*

Summary

Returns the locks for one or more documents or directories. Returns the locks for all documents and directories in the database if no parameter is given.

Parameters
uri A document URI.

Usage Notes

Note that the locks described here are relatively heavy persistent document locks for file system emulation through WebDAV, not relatively light transaction locks for database consistency.

Example

xdmp:document-locks("example.xml")
=>
<?xml version="1.0" encoding="ASCII"?>
<lock:lock xmlns:lock="http://marklogic.com/xdmp/lock">
  <lock:lock-type>write</lock:lock-type>
  <lock:lock-scope>exclusive</lock:lock-scope>
  <lock:active-locks>
    <lock:active-lock>
      <lock:depth>0</lock:depth>
      <lock:owner>
        <DAV:href xmlns:DAV="DAV:">http://example.com/~user</DAV:href>
      </lock:owner>
      <lock:timeout>120</lock:timeout>
      <lock:lock-token>http://marklogic.com/xdmp/locks/1c267a036b8480c3
      </lock:lock-token>
      <lock:timestamp>1290136652</lock:timestamp>
      <sec:user-id xmlns:sec="http://marklogic.com/xdmp/security">
        893641342095093063</sec:user-id>
    </lock:active-lock>
  </lock:active-locks>
</lock:lock>

Example

xquery version "1.0-ml";

(:
   The time is in epoch time, which is seconds from the start
   of 1970, so this code does a little math on the values in
   the lock document to figure out how many seconds are left
   for the lock.  Assumes a lock on /example.xml, for example
   by running the following:

xquery version "1.0-ml";
declare namespace DAV="DAV:";

xdmp:lock-acquire("/example.xml",
           "exclusive",
           "0",
           <DAV:href>http://example.com/~user</DAV:href>,
           xs:unsignedLong(120))

:)
let $lock := xdmp:document-locks("/example.xml")
let $lock-duration :=
   $lock/lock:lock/lock:active-locks/lock:active-lock/
         lock:timeout/fn:data(.)
let $current-epoch-time :=
 fn:round(
  ( fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00") )
  div xs:dayTimeDuration('PT1S') )
let $start-time :=
  $lock/lock:lock/lock:active-locks/lock:active-lock/
        lock:timestamp/fn:data(.)
let $end-time := $start-time + $lock-duration
let $seconds-left := $end-time - $current-epoch-time
return
 ($current-epoch-time, $start-time, $seconds-left)
=>
1290136837
1290136832
115

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.