Database Reference
In-Depth Information
only be implemented in Java. You can implement trigger actions before or after data‐
base operations performed for both documents and collections in either XQuery or
Java, but you can only modify documents or examine the content of documents dur‐
ing store or update operations by using Java triggers.
Triggers that take action on database operations for documents are called document
triggers ; likewise, those that act on collection actions are called collection triggers .
Triggers that modify documents or examine them as they are being stored are called
document filtering triggers . Triggers are configured on a per-collection basis in the
collection's configuration document ( collection.xconf ), and like all aspects of collec‐
tion configuration (see “Configuring Indexes” on page 275 for related detail), triggers
are inherited or overridden from their parent collection.
As triggers are configured in collection configuration documents,
and these are inherited downward or overridden, if you define trig‐
gers in a collection configuration document—for example, on the
collection /db/a/b —then any triggers defined in collection configu‐
ration documents on /db/a or /db will not be inherited by /db/a/b .
If you define your triggers in a collection configuration document,
you must also include any other triggers that you wish to use.
For example, the RESTXQ trigger is defined in the collection con‐
figuration for /db . Thus, if you define your own triggers in any
other collection configuration documents and wish to use RESTXQ
in those collections, you will also need to include a definition for
the RESTXQ trigger in your lower-level collection configuration
documents.
Whether implementing a trigger in XQuery or Java, you are required to implement a
function for each event that you wish to act before or after . You may only reject
changes to the database during before actions. Your function, which must follow a
naming convention (see Table 16-3 and Table 16-4 for documents and collections,
respectively), will be called each time that event occurs within the database.
Table 16-3. Naming convention for document trigger events
Event
XQuery function name
Java function name
Create document
before-create-document beforeCreateDocument
after-create-document
afterCreateDocument
Update document
before-update-document beforeUpdateDocument
after-update-document
afterUpdateDocument
Update document metadata
n/a
beforeUpdateDocumentMetadata
n/a
afterUpdateDocumentMetadata
Copy document
before-copy-document
beforeCopyDocument
Search WWH ::




Custom Search