xdmp:lock-acquire( $uri as xs:string, [$scope as xs:string?], [$depth as xs:string?], [$owner as item()*], [$timeout as xs:unsignedLong?] ) as empty-sequence()
Acquire a lock on a document or directory for an extended amount of time. Locks restrict updates to a document or directory to the user who acquires the lock.
If you lock a directory specifying a depth of "infinity", the directory and all of it children (all documents and directories with a URI started with the locked directory) are locked. You will not be able to add any children to the directory until the lock is released.
When a user locks a URI, it is locked to other users, but not to the user
who locked it. For example, if the user sam locks the URI
/home/sam.xml
by issuing the statement
xdmp:lock-acquire("/home/sam.xml")
, the user sam
can still issue update commands to the document at that URI, but other users
(for example, the user josh) will get an exception if they try
to update the document.
If you attempt to acquire a lock on a document that already has a lock, the XDMP-LOCKCONFLICT exception is thrown.
If you attempt to update a document that is locked by another user, the XDMP-LOCKED exception is thrown.
Note that the lock described here is a relatively heavy persistent document lock for file system emulation through WebDAV, not a relatively light transaction lock for database consistency.
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)) => ()