Changes

Jump to navigation Jump to search
768 bytes added ,  22:44, 18 August 2017
===Query Options===
* The You can declare custom locks are declared as options via the {{Code|query:read-lock}} and {{Code|query:write-lock}} options in the query prolog.* Multiple The value of the option declarations can be specified in a modulecontains the lock string, or values can also be multiple ones (separated with commas in a single declaration).* XQuery locks are in a separate namespace, such that there will be no conflicts with Similar to the internal database locks.* Similar to internal locks, write locks block all other operations while read locks allow parallel access.* The internal locks and XQuery locks can co-exist (there will be no conflicts, even if your lock string equals the name of a database that will be locked by the transaction manager).
In the following moduletwo example modules, a locks have been added to prevent concurrent write lock is declared to avoid multiple clients reading or writing to a config file at operations on the same timefile:
<pre class="brush:xquery">
module namespace config read = 'configread';
(:~ Write Read lock for all functions of the moduleon CONFIG key. :)declare option query:writeread-lock "files";(:~ Config file. :)declare variable $config:file := 'config.txtCONFIG';
declare function read:config:write($config) { file:writeread-text($config:file, $'config.txt')
};
</pre>
 
<pre class="brush:xquery">
module namespace write = 'write';
(:~ Write lock on CONFIG key. :)declare option query:write-lock 'CONFIG'; declare function configwrite:readfile($data) { file:readwrite-text('config.txt', $config:filedata)
};
</pre>
 
Some explanations:
 
* If a query is parsed that is going to call the <code>read:file</code> function, a read lock will be acquired for the user-defined {{Code|CONFIG}} lock string before query evaluation.
* If <code>write:file</code> is referenced by a query, a write lock on this lock string will be set for this query.
* If a query references <code>write:file</code>, it will be queued until there is no running query left that has {{Code|files}} locked.
* If the writing query will be evaluated, all other queries that will set a {{Code|files}} lock (reading or writing) will have to wait.
 
In practice, it’s often sufficient to only work with (exclusive) write locks.
===Java Modules===
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu