Database Reference
In-Depth Information
Storing an invalid XQuery trigger library module into the database
may cause any collections for which it is configured to reject all
database operations. This is because eXist will attempt to execute
the query for each database operation, and an exception will be
raised if the query is invalid, which will reject the operation.
Consequently, it is often better not to store your XQuery trigger
into the same collection as that on which you are configuring the
trigger. Otherwise, should you make a mistake in your trigger code,
you may be unable to save your updated trigger. This problem
occurs when you store an invalid XQuery trigger that is listening to
the
before-update-document
event; it will attempt to execute the
invalid query when you try to save your fixed trigger code, and as
the existing query is invalid, it will reject your update. To resolve
this you need to deconfigure the trigger in the appropriate collec‐
tion configuration document, fix the trigger XQuery code, and
then re-enable the trigger in the collection's configuration.
To implement an XQuery trigger you need to simply implement one or more of the
functions named in Tables
16-3
and
16-4
. Your implementation of each of these
functions must currently reside in the namespace
http://exist-db.org/xquery/
trigger
.
If you are placing your XQuery trigger in a stored XQuery library module, it is rec‐
ommended that your module have its own namespace, with the trigger functions just
calling your own functions (see
Example 16-10
). The majority of these functions take
a single argument,
$uri
(of type
xs:anyURI
), which provides you with the URI of the
document or collection that has caused the trigger event to fire. The exceptions are
the functions for copying and moving collection; these instead take two parameters,
$src
and
$dst
(both of type
xs:anyURI
), which describe the source and destination
URIs, respectively, of the database operation on the collection.
Table 16-5
lists the
parameters for the XQuery trigger configuration.
Table 16-5. Parameters for the XQuery trigger configuration
Parameter
Description
Mandatory/optional
You can directly place your XQuery code in this parameter.
Mandatory, unless
using
url
query
You can provide a URI to your XQuery library module in the database that
implements one or more functions from the
http://exist-db.org/
xquery/trigger
namespace.
This approach is preferred over using the
query
parameter.
Mandatory, unless
using
query
url
Search WWH ::
Custom Search