MarkLogic Server 11.0 Product Documentation
xdmp.documentLocks

xdmp.documentLocks(
   [uri as String[]]
) as Sequence

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.documentLocks("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

//   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.json, for example
//   by running the following:
//
//  declareUpdate();
//  xdmp.lockAcquire("/example.json", "exclusive", "0", [], 120);

var lock = fn.head(xdmp.documentLocks("/example.json")).root;
var lockDuration = new Number;
lockDuration = fn.head(lock.xpath(
  "/lock:lock/lock:active-locks/lock:active-lock/lock:timeout/fn:data(.)",
  {"lock": "http://marklogic.com/xdmp/lock"}));
var currentEpochTime =
     fn.round(fn.currentDateTime().toObject().getTime() / 1000) ; 
     // divide by 1000 to convert miliseconds to seconds
var startTime = new Number;
startTime = fn.head(lock.xpath(
  "/lock:lock/lock:active-locks/lock:active-lock/lock:timestamp/fn:data(.)",
  {"lock": "http://marklogic.com/xdmp/lock"}));
var endTime = new Number;
endTime = startTime + lockDuration;
var secondsLeft = endTime - currentEpochTime;
var res = [currentEpochTime, endTime, secondsLeft];
res;

=>
1290136837
1290136832
115
Powered by MarkLogic Server | Terms of Use | Privacy Policy