Setting up triggers in eXist
eXist is an open source XML database.
di Lorenzo Clementi |
Commenti |
Immagini |
Tempo di lettura: 1 - 2 min
I've been facing an annoying problem for several days and today I finally figured out how you can have triggers working in eXist.
Problem
I'm using eXist, an open source XML database and I need to enforce a key reference integrity constraint (i.e. if one XML document contains a reference to another document's id, this id must exist in the database).
eXist provides no method to automatically verify this constraint, but it is possible to do the verification by hand, using a trigger.
Now, this took me quite a long time because of the lack of documentation!
Solution
The only documentation I could find is this XML file, plus some mail in the eXist mailing list.
In order to make a Java trigger work in eXist do the following:
1. Create a file named collection.xconf and place it in the /db/system/table, where table corresponds to the collection's path where you want to set up the trigger.
2. The content of collection.xconf must look like:
Note that the event attribute can have several values (see below).
3. Create a package.TriggerClass class that implements the interface org.exist.triggers.Trigger (see the eXist Java API) and create a jar file containing it.
4. Copy the jar file into EXIST_HOME/libs/user
5. If the database is running, stop it and start it again
6. That's it. The trigger shall work properly, executing the methods in the package.TriggerClass according to the events listed in the collection.xconf file (possible values are: remove, rename, store, update, more info here).
Why do I blog this?
I've been working several hours (read: days) to understand the eXist's triggers functioning. I hope this short 'how to' can be helpful to someone.