Chcę wersji dokumentu, dla którego jesteśmy przestrzegane poniżej podejście do wymeldowania i check-in dokumentu w pojedynczej transakcji.
(:--------------------------- XQuery Starts ---------------------------:)
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";
declare function local:ManageDocument($docUri)
{
let $query := fn:concat("
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";
declare variable $docUri as xs:string external;
dls:document-manage($docUri,fn:false(),fn:concat("First Version of ", $docUri))"
)
return xdmp:eval(
$query,
(xs:QName("docUri"), $docUri),
<options xmlns="xdmp:eval">
<prevent-deadlocks>true</prevent-deadlocks>
</options>
)
};
let $docUri := "/searchable/as-2018-1981_standard.pdf.xml"
let $isManaged := dls:document-is-managed($docUri)
let $manageDoc := if($isManaged) then() else local:ManageDocument($docUri)
let $chechoutStatus := dls:document-checkout-status($docUri)
let $checkOut := if($chechoutStatus and $isManaged) then (fn:error(xs:QName("Error"), "Already Editing")) else dls:document-checkout-update-checkin($docUri, element {"ROOT"} {"HELLO WORLD!"}, "document-checkout-update-checkin", fn:true())
return $manageDoc
(:--------------------------- XQuery Ends ---------------------------:)
Jednak rzuca poniżej wyjątku:
[1.0-ml] XDMP-PREVENTDEADLOCKS: xdmp:eval(" xquery version "1.0-
ml"; declare ...", (fn:QName("","docUri"), "/searchable
/as-2018-1981_standard.pdf.xml"), <options xmlns="xdmp:eval"><prevent-
deadlocks>true</prevent-deadlocks></options>) -- Processing an update from an
update with different-transaction isolation could deadlock
Aby temu zaradzić, zmodyfikowałem XQuery, aby rozwiązać nasz cel:
(:--------------------------- New XQuery Starts ---------------------------:)
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";
declare function local:ManageDocument($docUri)
{
let $query := fn:concat("
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";
declare variable $docUri as xs:string external;
dls:document-manage($docUri,fn:false(),fn:concat("First Version of ", $docUri))"
)
return xdmp:eval(
$query,
(xs:QName("docUri"), $docUri),
<options xmlns="xdmp:eval">
<prevent-deadlocks>true</prevent-deadlocks>
</options>
)
};
declare function local:CheckouotDocument($docUri)
{
let $query := fn:concat("
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";
declare variable $docUri as xs:string external;
(: dls:document-checkout($docUri, fn:true(), "updating doc", 3600) :)
dls:document-checkout-update-checkin($docUri, element {"ROOT"} {"HELLO WORLD!"}, "document-checkout-update-checkin", fn:true())
")
return xdmp:eval(
$query,
(xs:QName("docUri"), $docUri),
<options xmlns="xdmp:eval">
<prevent-deadlocks>true</prevent-deadlocks>
</options>
)
};
let $docUri := "/searchable/as-2018-1981_standard.pdf.xml"
let $isManaged := dls:document-is-managed($docUri)
let $manageDoc := if($isManaged) then() else local:ManageDocument($docUri)
let $chechoutStatus := dls:document-checkout-status($docUri)
let $checkOut := if($chechoutStatus and $isManaged) then (fn:error(xs:QName("Error"), "Already Editing")) else local:CheckouotDocument($docUri)
return $manageDoc
(:--------------------------- New XQuery Ends ---------------------------:)
Powyżej XQuery działa zgodnie z oczekiwaniami, jednak byłoby świetnie, gdyby ktoś mógł mi pomóc w rozwiązaniu mojego celu w bardziej wydajny i uproszczony sposób.
Odpowiedzi:
2 dla odpowiedzi № 1Możesz nieco uprościć swój kod przy użyciu xdmp:invoke-function()
zamiast budować ciągi dla xdmp:eval()
i unikaj powtarzania opcji przez deklarowanie zmiennej:
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import module namespace dls = "http://marklogic.com/xdmp/dls" at "/MarkLogic/dls.xqy";
declare variable $OPTIONS :=
<options xmlns="xdmp:eval">
<prevent-deadlocks>true</prevent-deadlocks>
</options>;
declare function local:ManageDocument($docUri)
{
xdmp:invoke-function(function() {
dls:document-manage($docUri, fn:false(), "First Version of "||$docUri)
}, $OPTIONS)
};
declare function local:CheckouotDocument($docUri)
{
xdmp:invoke-function(function() {
(: dls:document-checkout($docUri, fn:true(), "updating doc", 3600) :)
dls:document-checkout-update-checkin($docUri, element {"ROOT"} {"HELLO WORLD!"}, "document-checkout-update-checkin", fn:true())
}, $OPTIONS)
};
let $docUri := "/searchable/as-2018-1981_standard.pdf.xml"
let $isManaged := dls:document-is-managed($docUri)
let $manageDoc := if ($isManaged) then() else local:ManageDocument($docUri)
let $chechoutStatus := dls:document-checkout-status($docUri)
let $checkOut := if ($chechoutStatus and $isManaged) then (fn:error(xs:QName("Error"), "Already Editing")) else local:CheckouotDocument($docUri)
return $manageDoc