找不到刚刚在触发器中创建的文档

时间:2015-10-20 15:45:32

标签: triggers xquery marklogic marklogic-8

我有以下问题。 我们使用MarkLogic的OBI框架 我在数据库中使用触发器来监控传感器数据。 一旦加载了新的OBI源,我就检查一些东西。 如果我找到了什么,我会创建一个"警报"宾语。 然后我想使用该对象生成一个"有效载荷"要发送到移动设备的消息......

现在触发工作。 在触发器中,我使用带有不同transcaction的xdmp:eval来确保我可以使用在相同触发器代码中创建的文档... 但是,如果我搜索新创建的对象,则无法找到...

我可以创建一个文档并在同一个触发器代码中使用它吗?

我担心在这里创建一个最小的工作示例很难,但这是一个尝试:

相关触发码:

(: fire trigger ALWAYS :)
let $_ := xdmp:log(fn:concat('TP-SENSORTRIGGER-ACTION : Source ', $trgr:uri, ' triggers base rule...')) 
(: create alert object plus link to source :)
let $object-id := xdmp:eval(concat('
    xquery version "1.0-ml";
    import module namespace scl = "http://example.com/sccs/lib" at "/lib/sccss-lib.xqy";

    declare variable $source-id external;

    let $object-id := scl:create-alert-object($source-id)
    let $_ := xdmp:log("***** test *****")      
    return $object-id 
    '), (xs:QName('source-id'), $source-id),
    <options xmlns="xdmp:eval"><isolation>different-transaction</isolation></options>)
let $_ := xdmp:log($object-id)
(: create payload from alert object :)
(:let $payload := scl:create-payload-from-alert-object($object-id)
:)
let $object := obj:find-object($object-id)
let $_ := xdmp:log($object)

创建OBI对象的函数位于lib中。如果需要我可以分享。 我添加了一个日志行&#34; test&#34;和&#34;测试B&#34;确保我使用正确的触发器。并确保在app-specific.rb中部署时重建它们。

然后从日志中可以看出无法找到该对象:

2015-10-20 15:33:02.860 Info: example-app: ******** Ingest transform Started ***************
2015-10-20 15:33:04.196 Info: TaskServer: TP-SENSORTRIGGER /marklogic.solutions.obi/source/81a3591a-a885-4f85-a781-b066e706ff41.xml was created, start trigger action...
2015-10-20 15:33:04.291 Info: TaskServer: TP-SENSORTRIGGER-ACTION : Source /marklogic.solutions.obi/source/81a3591a-a885-4f85-a781-b066e706ff41.xml triggers base rule...
2015-10-20 15:33:07.267 Info: TaskServer: ***** test B *****
2015-10-20 15:33:07.268 Info: TaskServer: ***** test *****
2015-10-20 15:33:07.273 Info: TaskServer: 4d1fd4e4-2911-40b0-848c-ccf8eaa39229
2015-10-20 15:33:07.277 Info: TaskServer: 

触发器运行后,我当然可以从QC找到ID为4d1fd4e4-2911-40b0-848c-ccf8eaa39229的对象。

所以这与MarkLogic的事务模型有关。我想。

所以再一个问题:为什么我找不到我刚刚在xdmp:eval中创建的对象?

1 个答案:

答案 0 :(得分:0)

事实证明你必须在xdmp:eval()中向下游包装所有函数才能使其工作。

(: fire trigger ALWAYS :)
let $_ := xdmp:log(fn:concat('TP-SENSORTRIGGER-ACTION : Source ', $trgr:uri, ' triggers base rule...')) 
(: create alert object plus link to source :)
let $object-id := xdmp:eval(concat('
    xquery version "1.0-ml";
    import module namespace scl = "http://example.com/sccs/lib" at "/lib/example-lib.xqy";

    declare variable $source-id external;
    declare variable $actions external;
    declare variable $lastseen external;

    let $object-id := scl:create-alert-object($source-id,$actions,$lastseen)

    return $object-id 
    '), (xs:QName('source-id'), $source-id,xs:QName('actions'), $actions,xs:QName('lastseen'), $lastseen),
    <options xmlns="xdmp:eval"><isolation>different-transaction</isolation></options>)
let $_ := xdmp:log($object-id)
(: create payload from alert object :)
(:let $payload := scl:create-payload-from-alert-object($object-id)
:)
let $payload := xdmp:eval(concat('
    xquery version "1.0-ml";
    import module namespace scl = "http://example.com/sccs/lib" at "/lib/sccss-lib.xqy";

    declare variable $object-id external;

    let $payload := scl:create-payload-from-alert-object($object-id)

    return $payload 
    '), (xs:QName('object-id'), $object-id),
    <options xmlns="xdmp:eval"><isolation>different-transaction</isolation></options>)
let $_ := xdmp:log("************* PAYLOAD ****************")
let $_ := xdmp:log($payload)
(: send alert to middletier :)

let $result := xdmp:eval(concat('
    xquery version "1.0-ml";
    import module namespace scl = "http://example.com/sccs/lib" at "/lib/sccss-lib.xqy";

    declare variable $payload external;

    let $res := scl:send-alert-notification($payload)

    return $res 
    '), (xs:QName('payload'), $payload),
    <options xmlns="xdmp:eval"><isolation>different-transaction</isolation></options>)
let $_ := xdmp:log("************* RESULT ****************")
let $_ := xdmp:log($result)

the documentation of the xdmp:eval()函数

不清楚这一点
  

&#34;设置为different-transaction时,将在a中计算语句   单独的事务与调用它的事务相同   可用于调用语句中后续表达式的更新   (假设调用语句是更新语句;如果调用   语句不是更新,然后后续表达式将看到   调用时系统时间戳的数据库版本   声明开始评估)。&#34;

相关问题