Database Reference
In-Depth Information
configure method from org.exist.collections.triggers.Trigger will be called;
you may use this function to read any parameters from the trigger's configuration
and set up any initial state in a thread-safe manner. Should you decide to store some
state in member variables of your class, remember that the class instance is per collec‐
tion, so the values of these variables will not be globally consistent.
Also be aware that the calls to the trigger methods (e.g., beforeS
toreDocument ) are not thread-safe. This means that more than one
thread may be in any, or even all, of the event functions defined in
your trigger class! If you wish to keep state, it is up to you to man‐
age concurrent access to that state appropriately.
As they are simpler to implement than document triggers, we will look first at collec‐
tion triggers, which will show you how to implement event functions. We will then
look at document triggers, which have similar event functions and a whole lot more!
Java collection triggers
When you're implementing Java collection triggers your class must provide imple‐
mentations for all of the methods defined in org.exist.collections.trig
gers.Trigger and org.exist.collections.triggers.CollectionTrigger to
compile. However, triggers were designed in such a way that you really need only fill
out those methods that you wish to act upon.
The simplest collection trigger would only provide code for a single method, as
shown in Example 16-11 , where we log the username of a user creating a collection.
Example 16-11. Simplest collection trigger
package example ;
import org.apache.log4j.Logger ;
import org.exist.collections.triggers.CollectionTrigger ;
import org.exist.collections.triggers.TriggerException ;
import org.exist.storage.DBBroker ;
import org.exist.storage.txn.Txn ;
import org.exist.xmldb.XmldbURI ;
import java.util.List ;
import java.util.Map ;
public class SimplestCollectionTrigger implements CollectionTrigger {
private final static Logger LOG =
Logger . getLogger ( SimplestCollectionTrigger . class );
@Override
public void beforeCreateCollection ( DBBroker broker , Txn txn , XmldbURI uri )
throws TriggerException {
Search WWH ::




Custom Search