|
|
trgr:create-trigger(
|
|
$trigger-name as xs:string,
|
|
$description as xs:string?,
|
|
$event as element(),
|
|
$module as element(trgr:module),
|
|
$enabled as xs:boolean,
|
|
$permissions as element(sec:permission)*,
|
|
[$recursive as xs:boolean?]
|
| ) as xs:unsignedLong |
|
 |
Summary:
Creates a new trigger in the context database.
Returns the trigger ID of the created trigger.
|
Parameters:
$trigger-name
:
A unique name.
If $trigger-name is not unique, an error is returned.
|
$description
:
A description of the
trigger.
|
$module
:
The module to execute when the triggering event occurs. Use
trgr:trigger-module
to construct this element.
|
$enabled
:
Set to true if the trigger is enabled.
|
$permissions
:
A sequence of permissions for the trigger. These permissions will determine
which roles are permitted to modify the trigger.
|
$recursive
(optional):
Set to true if the trigger should be allowed to trigger itself for
recursive changes on the same document. Set to false to prevent
the trigger from triggering itself. If this parameter is not
present, then its value is true.
|
|
Required Privilege:
http://marklogic.com/xdmp/privileges/create-trigger
|
Usage Notes:
Triggers must be created in the triggers database associated with the
the content database to which the triggers apply. To determine the
triggers database programatically, use xdmp:triggers-database
in the evaluation context of the content database, or
xdmp:database with the database name listed as the
triggers database value in the Admin Interface under
Databases > content_db_name.
Triggers are created in the
http://marklogic.com/xdmp/triggers/ directory, with
the trigger ID completing the URI. This is the ID returned by
trgr:create-trigger.
If a trigger named $trigger-name already exists, the exception
TRGR-TNEXISTS is raised. You must use
trgr:remove-trigger
to delete an existing trigger before recreating it.
Once a trigger is created, you can view it in the Admin Interface
under the content database, in the Triggers Summary page
(Databases > content_db_name > Triggers). If your
trigger does not appear in Triggers Summary,
trgr:create-trigger was probably evaluated in the
wrong database context.
|
Example:
(: Run in the context of the triggers database of the content database :)
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
trgr:create-trigger("myTrigger", "Simple trigger example",
trgr:trigger-data-event(
trgr:directory-scope("/myDir/", "1"),
trgr:document-content("create"),
trgr:post-commit()),
trgr:trigger-module(xdmp:database("test"), "/modules/", "log.xqy"),
fn:true(), xdmp:default-permissions() )
=> The ID of the newly created trigger. This
trigger fires whenever a document is created in the
/myDir/ directory. The action module, /modules/log.xqy,
is stored in the modules database of the App Server
against which the content document is created. When
the trigger fires, a task to evaluate /modules/log.xqy
is spawned on the task server queue.
|
|
|
|
trgr:property-content(
|
|
$property-name as xs:QName
|
| ) as element(trgr:property-content) |
|
 |
Summary:
Returns the XML representation of a property part to a triggering event,
usable as the content parameter of a trigger
event constructor such as
trgr:trigger-data-event.
|
Parameters:
$property-name
:
The QName of the property.
|
|
Usage Notes:
Adding, changing or removing the $property-name document property matches
this event part.
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
trgr:trigger-data-event(
trgr:directory-scope("/myDir/", "1"),
trgr:property-content(
fn:qname("", "myInterestingProperty")),
trgr:post-commit())
=> A property modification trigger event that can
be used to create a trigger which fires whenever
the property myInterestingProperty is added, modified
or removed from a document in /myDir/.
|
|
|
|
trgr:trigger-data-event(
|
|
$scope as element(),
|
|
$content as element(),
|
|
$when as element(trgr:when)
|
| ) as element(trgr:data-event) |
|
 |
Summary:
Returns the XML representation of a triggering eventa, usable as the
event parameter of
trgr:create-trigger.
|
Parameters:
|
Usage Notes:
The scope parameter describes the set of documents to which
the trigger event applies. The content parameter describes
the interesting activity within scope, such as document
creation or document property modification. The when
parameter describes when the event should be acted on, relative to the
triggering transaction.
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
trgr:trigger-data-event(
trgr:directory-scope("/myDir/", "1"),
trgr:document-content("create"),
trgr:post-commit()
)
=> A trigger event suitable for use with trgr:create-trigger.
The triggering event occurs at post-commit whenever a document
is created in the database directory "/myDir/".
|
|
|
|
trgr:trigger-database-online-event(
|
|
$user-name as xs:string
|
| ) as element(trgr:database-online-event) |
|
 |
Summary:
Returns the XML representation of a database coming online event, usable
as the event parameter of
trgr:create-trigger.
|
Parameters:
$user-name
:
The user used to execute the trigger module.
|
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
trgr:trigger-database-online-event("database-admin")
=> A trigger event suitable for use with trgr:create-trigger.
The triggering event occurs whenever a (unspecified) database
comes online. The trigger module associated with this event
executes as user "database-admin".
|
|
|
|
trgr:trigger-module(
|
|
$database-id as xs:unsignedLong,
|
|
$root as xs:string,
|
|
$path as xs:string
|
| ) as element(trgr:module) |
|
 |
Summary:
Returns the XML representation of a trigger module which can be used
as the module parameter of
trgr:create-trigger.
|
Parameters:
$database-id
:
A database-id.
|
$root
:
The root path within the database.
|
$path
:
The path to the module relative to $root within the database
identified by $database-id.
|
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
trgr:trigger-module(
xdmp:database("Documents"),
"/modules/",
"log-create.xqy")
=> An internal XML representation of the trigger module,
usable as the module parameter of trgr:create-trigger().
|
|
|
|
trgr:trigger-remove-permissions(
|
|
$trigger-name as xs:string,
|
|
$permissions as element(sec:permission)*
|
| ) as empty-sequence() |
|
 |
Summary:
Removes a set of permissions from the set of permissions on the named trigger.
|
Parameters:
$trigger-name
:
The trigger name.
|
$permissions
:
A sequence of permission nodes.
|
|
Usage Notes:
This function must be run in the context of the database containing
the trigger to be modified.
Any permissions on $trigger-name not listed in
$permissions are unchanged.
Any permissions in $permissions not associated with
$trigger-name are ignored.
If the named trigger does not exist, the exception
TRGR-TRIGGERDNE is raised.
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
(: Run in the context of the database containing the trigger :)
trgr:trigger-remove-permissions(
"myTrigger",
(xdmp:permission("some-role", "modify"))
)
|
|
|
|
trgr:trigger-set-event(
|
|
$trigger-name as xs:string,
|
|
$event as element()
|
| ) as empty-sequence() |
|
 |
Summary:
Assigns a triggering event to the named trigger.
|
Parameters:
$trigger-name
:
The trigger name.
|
|
Usage Notes:
A trigger event describes the conditions under which the trigger
fires. After calling this function, any previous event associated
with the trigger is replaced.
This function must be run in the context of the database containing
the trigger to be modified.
If the named trigger does not exist, the exception
TRGR-TRIGGERDNE is raised.
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
(: Run in the context of the database containing the trigger :)
trgr:trigger-set-event(
"myTrigger",
trgr:trigger-data-event(
trgr:directory-scope("/myDir/", "1"),
trgr:document-content("create"),
trgr:post-commit()) )
=> Empty sequence. The trigger "myTrigger" is set to fire
whenever a document is created in "/myDir/". The trigger
module runs after the creating transaction is committed.
|
|
|
|
trgr:trigger-set-module(
|
|
$trigger-name as xs:string,
|
|
$module as element(trgr:module)
|
| ) as empty-sequence() |
|
 |
Summary:
Sets or replaces the action module associated with the named trigger.
|
Parameters:
$trigger-name
:
The trigger name.
|
|
Usage Notes:
When $trigger fires, $module is evaluated. Any module previously
associated with $trigger is replaced when this function is called.
This function must be run in the context of the database containing
the trigger to be modified.
If the named trigger does not exist, the exception
TRGR-TRIGGERDNE is raised.
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
(: Run in the context of the database containing the trigger :)
trgr:trigger-set-module(
"myTrigger",
trgr:trigger-module(
xdmp:database("trigger_module_database"),
"/modules/",
"the-new-action.xqy") )
=> Empty sequence. When "myTrigger" fires, "the-new-action.xqy"
is evaluated.
|
|
|
|
trgr:trigger-set-name(
|
|
$trigger-name as xs:string,
|
|
$new-trigger-name as xs:string
|
| ) as empty-sequence() |
|
 |
Summary:
Changes the name of a trigger.
|
Parameters:
$trigger-name
:
The current trigger name.
|
$new-trigger-name
:
The new trigger name.
|
|
Usage Notes:
Changes the name of a trigger from $trigger-name to $new-trigger-name.
This function must be run in the context of the database containing
the trigger whose name is to be changed.
If no trigger trigger named $trigger-name exists, the exception
TRGR-TRIGGERDNE is raised.
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
(: In the context of the database containing the trigger :)
trgr:trigger-set-name("currentName", "newName")
|
|
|
|
trgr:trigger-set-permissions(
|
|
$trigger-name as xs:string,
|
|
$permissions as element(sec:permission)*
|
| ) as empty-sequence() |
|
 |
Summary:
Sets the permissions that determine which roles are permitted to modify
the named trigger.
|
Parameters:
$trigger-name
:
The trigger name.
|
$permissions
:
A sequence of permission nodes.
|
|
Usage Notes:
Any permissions previously associated with the trigger are replaced.
This function must be run in the context of the database containing
the trigger to be modified.
If the named trigger does not exist, the exception
TRGR-TRIGGERDNE is raised.
|
Example:
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
(: Run in the context of the database containing the trigger :)
trgr:trigger-set-permissions(
"myTrigger",
xdmp:default-permissions() )
=> Empty sequence. The trigger "myTrigger" may be modified
roles which have the default permissions.
|
|
|