Database Reference
In-Depth Information
Implementation of your business logic.
Example 16-10
shows how to implement a simple XQuery library module that imple‐
ments the
after-create-document
function that eXist will call when a document is
stored into a collection on which the trigger has been configured. The collection con‐
figuration for that example might look like:
<collection
xmlns=
"http://exist-db.org/collection-config/1.0"
>
<triggers>
<trigger
class=
"org.exist.collections.triggers.XQueryTrigger"
>
<parameter
name=
"url"
value=
"xmldb:exist:///db/simple-example-trigger.xqm"
/>
<parameter
name=
"bindingPrefix"
value=
"et"
/>
<parameter
name=
"log-level"
value=
"INFO"
/>
</trigger>
</triggers>
</collection>
The URI to the XQuery library module in the database that provides the XQuery
trigger
The binding prefix, which must be the same as the XQuery library module's
namespace prefix
A parameter that is passed into the XQuery library module by binding to the
external variable named
$example:log-level
To install the example:
1. Store the XQuery trigger into the database in a document located at
/db/simple-
example-trigger.xqm
.
2. Create the collection
/db/test-trigger
.
3. Create the collection
/db/system/config/db/test-trigger
.
4. Store the collection configuration document (see the preceding code block) into
the database in a document located at
/db/system/config/db/test-trigger/collec‐
tion.xconf
. This configures the trigger on the
/db/test-trigger
collection.
To test the example:
1. Store
any
document into
/db/test-trigger
.
2. Check the logfile
$EXIST_HOME/webapp/WEB-INF/logs/exist.log
. If everything
succeeded you should see a message in the log that looks similar to:
Search WWH ::
Custom Search