Skip to content

Commit

Permalink
marklogic-community#492 verify parameters and use xdmp:value instead …
Browse files Browse the repository at this point in the history
…of try/catch and eval for path-namespaces
  • Loading branch information
dmcassel committed Jan 17, 2017
1 parent 5ac5a7c commit 3db0d31
Showing 1 changed file with 28 additions and 50 deletions.
78 changes: 28 additions & 50 deletions deploy/lib/xquery/setup.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -2005,26 +2005,16 @@ declare function setup:remove-existing-path-namespaces(
$admin-config as element(configuration),
$database as xs:unsignedLong) as element(configuration)
{
(: wrap in try catch because this function is new to 6.0 and will fail in older version of ML :)
try
{
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $database external;
declare variable $admin-config external;
admin:database-delete-path-namespace($admin-config, $database,
admin:database-get-path-namespaces($admin-config, $database))',
(xs:QName("database"), $database,
xs:QName("admin-config"), $admin-config))
}
catch($ex)
{
if ($ex/error:code = "XDMP-UNDFUN") then $admin-config
else if ($ex/error:code = "ADMIN-PATHNAMESPACEINUSE" and fn:not(setup:at-least-version("6.0-2"))) then
fn:error(xs:QName("VERSION_NOT_SUPPORTED"), "Roxy does not support path namespaces for this version of MarkLogic. Use 6.0-2 or later.")
else
xdmp:rethrow()
}
(: wrap in xdmp:value because this function is new to 6.0 and will fail in older version of ML :)
if (setup:at-least-version("6.0-2")) then
xdmp:value(
"admin:database-delete-path-namespace($admin-config, $database,
admin:database-get-path-namespaces($admin-config, $database))"
)
else
(: We don't need to complain if ML is too old to run this function; in
: that case, the path-namespaces won't have been built. :)
$admin-config
};

declare function setup:add-path-namespaces(
Expand All @@ -2033,18 +2023,21 @@ declare function setup:add-path-namespaces(
$db-config as element(db:database)) as element(configuration)
{
if ($db-config/db:path-namespaces/db:path-namespace) then
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare namespace db="http://marklogic.com/xdmp/database";
declare variable $admin-config external;
declare variable $database external;
declare variable $db-config external;
admin:database-add-path-namespace($admin-config, $database, $db-config/db:path-namespaces/db:path-namespace)',
(
xs:QName("admin-config"), $admin-config,
xs:QName("database"), $database,
xs:QName("db-config"), $db-config
))
if (setup:at-least-version("6.0-2")) then
xdmp:value(
"admin:database-add-path-namespace(
$admin-config,
$database,
for $path-ns in $db-config/db:path-namespaces/db:path-namespace
return
admin:database-path-namespace($path-ns/db:prefix, $path-ns/db:namespace-uri)
)"
)
else
fn:error(
xs:QName("VERSION_NOT_SUPPORTED"),
"Roxy does not support path namespaces for this version of MarkLogic. Use 6.0-2 or later."
)
else
$admin-config
};
Expand All @@ -2055,24 +2048,9 @@ declare function setup:validate-path-namespaces(
$db-config as element(db:database))
{
let $existing :=
try
{
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $admin-config external;
declare variable $database external;
admin:database-get-path-namespaces($admin-config, $database)',
(
xs:QName("admin-config"), $admin-config,
xs:QName("database"), $database
))
}
catch($ex)
{
if ($ex/error:code = "XDMP-UNDFUN") then ()
else
xdmp:rethrow()
}
if (setup:at-least-version("6.0-2")) then
xdmp:value("admin:database-get-path-namespaces($admin-config, $database)")
else ()
for $expected in $db-config/db:path-namespaces/db:path-namespace
return
if ($existing[fn:deep-equal(., $expected)]) then ()
Expand Down

0 comments on commit 3db0d31

Please sign in to comment.