Database Reference
In-Depth Information
2014-01-14 11:10:44,561 [eXistThread-30] INFO (LogFunction.java [eval]:150) -
(Line: 14 /db/simple-example-trigger.xqm) XQuery Trigger called after
document '/db/test- trigger/blah3.xml' created.
A more complicated example that shows how to react to multiple trigger events and
send email notifications is provided in the file chapters/advanced-topics/journal-
notification-trigger.xqm of the book-code Git repository.
Java Triggers
When implementing database triggers in Java for eXist, you need to implement the
appropriate Java interfaces for the events that you wish to handle (see Figure 16-5 ).
The events are split between document events and collection events, as described in
Tables 16-3 and 16-4 . The interface for document events is org.exist.collec
tions.triggers.DocumentTrigger , while the interface for collection events is
org.exist.collections.triggers.CollectionTrigger . It is perfectly possible to
implement both interfaces in a single class if you wish to respond to both types of
events.
Omitted from the interfaces DocumentTrigger and Collection
Trigger are two methods, prepare and finish . These functions
are deprecated and can safely be ignored; in fact, they were
removed after the eXist 2.1 release. They provide the old infra‐
structure for triggers and have been replaced by the before* and
after* functions.
Once you have implemented the appropriate class you need to place your compiled
class onto eXist's classpath, which you typically do by placing a JAR file of your code
and any dependent JAR files into $EXIST_HOME/lib/user . Remember that you may
have to restart eXist for the JVM class loader to see your new JAR files!
When writing triggers in Java, you can assume that any Documen
tImpl or Collection objects that you are given are already locked.
However, if you open any other documents or collections you must
be sure to lock them correctly and, most importantly, to release
those locks when you are done with them. Failure to do so could
lead to deadlocks in eXist. It is strongly recommended to use the
Java try / catch / finally pattern to release any acquired locks in
the finally block.
Search WWH ::




Custom Search