Database Reference
In-Depth Information
LOG
.
info
(
"User '"
+
broker
.
getSubject
().
getName
()
+
"' is creating the Collection '"
+
uri
+
"'..."
);
}
// Omitted: other empty function implementations here...
}
We must implement the
CollectionTrigger
interface.
We provide an implementation of the event method
beforeCreateCollection
.
Before the collection indicated by
uri
is created, we record the event in eXist's
logfile, attributing it to a specific user.
We must provide implementations of all the other functions from
Collection
Trigger
here for the code to compile; however, as we are not using them and
they are easily generated by an IDE, we have omitted them for brevity.
Just like in previous examples, to have the trigger fired on the database events that
you are interested in, you must add it to the collection configuration documents for
those collections that you wish your trigger to act upon. An example configuration
for the
SimplestCollectionTrigger
would look like:
<collection
xmlns=
"http://exist-db.org/collection-config/1.0"
>
<triggers>
<trigger
class=
"example.SimplestCollectionTrigger"
/>
</triggers>
</collection>
Remember that you must configure your collection triggers on the
parent
of the collection for those collection events that you wish
them to be triggered upon. For example, if you want to be made
aware when a new collection is created in
/db/myapp/data
, then
you must add your trigger to the collection configuration docu‐
ment for the collection
/db/myapp/data
. In this way, if a user were
to create, copy, move, or delete the collection
/db/myapp/data/
some-collection
, your trigger would receive the event. Likewise, it
would receive the events for any descendant collections—for exam‐
ple,
/db/myapp/data/some-collection/subcollection
—as collection
configuration is inherited!
No delete example collection trigger
An example class implementing
CollectionTrigger
called
exist.book.exam
ple.trigger.collection.NoDeleteCollectionTrigger
is supplied in the folder
Search WWH ::
Custom Search