Changes

Jump to navigation Jump to search
53 bytes removed ,  17:33, 28 July 2020
=XQuery Locks=
By default, access to external resources (files on hard disk, HTTP requests, {{Mark|Updated with Version 9.4:}} Single lock option for reads and writes..) is not controlled by the transaction monitor of BaseX. You can use custom XQuery locks to do so:
==OptionsBy default, Pragmasaccess to external resources (files on hard disk, Annotations==HTTP requests, ...) is not controlled by the transaction monitor of BaseX. Custom locks can be assigned via annotations, pragmas or options:
* You can declare custom read and write locks via options, pragmas or function annotations.* The value of the A lock string may contain one consist of a single key or multiple lock keys (separated with commas). The default value is an empty string.* Similar to the internal database locks, write locks block all other operations while read locks allow parallel access.* The internal Internal locks and XQuery locks can co-exist (there will be no . No conflictsarise, even if your a lock string equals the name of a database that will be is locked by the transaction manager).* The lock is transformed into a write lock by making the corresponding expression updating. ==Annotations==
In the following module, lock annotations are used to prevent concurrent write operations on the same file:
module namespace config = 'config';
declare %basex:read-lock('CONFIG') function config:read() as xs:string {
file:read-text('config.txt')
};
declare %updating %basex:write-lock('CONFIG') function config:write($dataas xs:string) {
file:write-text('config.txt', $data)
};
* If a query calls the <code>config:read</code> function, a read lock will be acquired for the user-defined {{Code|CONFIG}} lock string before query evaluation.
* If <code>config:write</code> is called by a query, a write lock on this lock string will be set for this queryapplied.* If a another query calls <code>config:write</code>, it will be queued until there is no running query left that has {{Code|CONFIG}} locked.* If the writing first query will be is evaluated, all other queries that will set a {{Code|CONFIG}} lock (reading or writing) will have to wait==Pragmas==
Local locks Locks can also be declared via pragmas:
<syntaxhighlight lang="xquery">
update:output((# basex:write-lock CONFIG #) {
file:write('config.xml', <config/>)
})
</syntaxhighlight>
The write locks is enforced via the {{Code|Update|update:output}}. ==Options== Locks for the functions of a module can also be assigned via option declarations:
<syntaxhighlight lang="xquery">
declare option basex:write-lock 'CONFIG'; update:output(file:write('config.xml', <config/>))
</syntaxhighlight>
 
Once again, a write lock is enforced.
==Java Modules==
=Changelog=
 
;Version 9.4
* Updated: Single lock option for reads and writes.
;Version 9.1
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu