<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.lockForUpdate.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.lockForUpdate</api:function-name><api:suggest>xdmp.lockforupdate</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>lockforupdate</api:suggest><api:function-link mode="xquery" fullname="xdmp:lock-for-update">/apidoc/8.0/xdmp:lock-for-update.xml</api:function-link><api:function mode="javascript" name="lockForUpdate" type="builtin" lib="xdmp" category="UpdateBuiltins" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.lockForUpdate"><api:summary>
  Acquires an intent exclusive transaction lock on a URI.
  If a shared transaction lock on the URI is already held by
  the current transaction it is promoted to an exclusive lock.
  If a shared or exclusive transaction lock on the URI is already
  held by some other transaction, this function blocks until
  that lock is released.
</api:summary><api:params><api:param name="uri" type="xs:string"><api:param-description>
    The URI to be locked for update.
  </api:param-description><api:param-name>uri</api:param-name><api:param-type>String</api:param-type></api:param></api:params><api:return>null</api:return><api:usage>
<p xmlns="http://www.w3.org/1999/xhtml">This function allows an update transaction to acquire an exclusive write
lock on a URI without specifying an update. Deadlocks and restarted transactions
can be avoided by first explicitly acquiring an exclusive transaction lock
on the URI with this function, <em>before</em> implicitly acquiring a
shared transaction lock reading a document with that URI.</p>
<p xmlns="http://www.w3.org/1999/xhtml">An exclusive transaction lock on a URI is automatically
and implcitly acquired when an update function is applied on that URI.
Similarly, a shared transaction lock on a URI is automatically and implicitly
acquired when a document with that URI is read by an update transaction.
If two update transactions concurrently read a document and
then apply an update function on it, a deadlock can occur, because each transaction
waits for the other to release its shared lock in order to escalate to
an exclusive lock. This deadlock is automatically detected by the system,
one of the transactions is restarted and its locks are released,
and the other transaction proceeds.</p>
<p xmlns="http://www.w3.org/1999/xhtml">Note that the lock acquired by this function is a relatively light transaction
lock for database consistency, not a relatively heavy persistent document
lock for file system emulation through WebDAV.</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
declareUpdate();
xdmp.lockForUpdate("/example.xml");
</pre></api:example></api:function></api:function-page>