[MarkLogic Dev General] RE: GUIDs, triggers and directories...
Danny Sokolsky
Danny.Sokolsky at marklogic.com
Fri Oct 16 10:56:12 PDT 2009
Hi Keith,
I have not tried this, so I am not positive it will work, but here is a thought.....
Directories are properties documents with the special "directory" property. So you can try creating a property update trigger on the directory property (using trgr:property-content), and specify the directory property as the one to watch. Then when that trigger fires (for example, if it is a create trigger, when the directory is created), you can perform whatever action you want on that directory properties document. So the create-trigger code might look something like this:
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:property-content(xs:QName("prop:directory")),
trgr:post-commit()),
trgr:trigger-module(xdmp:database("test"), "/modules/", "log.xqy"),
fn:true(), xdmp:default-permissions() )
It is worth a try.
-Danny
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Keith L. Breinholt
Sent: Friday, October 16, 2009 10:31 AM
To: general at developer.marklogic.com
Subject: [MarkLogic Dev General] GUIDs, triggers and directories...
I'm trying to set a unique ID on all files and directories when they are created; a UUID or GUID.
I setup a create trigger to set a <uuid>{$ guid}</uuid> property on the file/directory.
However, it would appear that triggers are not fired on directory operations.
Now, working around this, when files are created I check for this property on the file's parent directory and if it does not exist call xdmp:document-set-property( $parentUri, <uuid>{$parentUuid}</uuid> ). However, it would seem that xdmp:document-set-property() is not reentrant because I can end up with multiple copies of <uuid> on a parent directory. This has actually happened if I drop a directory with multiple children into a WebDAV folder.
Now we are talking about a concurrency issue and I need to lock the parent properties before I read and potentially update it. but I don't want to lock a directory for every file creation because that will cause all transactions in that directory and subdirectories to fail or be serialized.
If create triggers worked for directories this would not be an issue, we could set the property on directory creation and be done with it.
Has anyone run into this, and if so how did you solve this problem?
Thanks,
Keith L. Breinholt
ICS Content & Media
breinholtkl at ldschurch.org
"Do what you can, with what you have, where you are." Theodore Roosevelt
NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
More information about the General
mailing list