Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 4c0bbe6

Browse files
committed
#92 qconsole import works in ML9 now
1 parent 6eaf67c commit 4c0bbe6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/main/java/com/marklogic/client/ext/qconsole/impl/DefaultWorkspaceManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ public List<File> importWorkspaces(String user, String... workspaceNames) {
7777
return files;
7878
}
7979

80+
final String importQuery = determineImportScriptToUse();
81+
8082
for (String workspace : workspaceNames) {
8183
File f = new File(userDir, workspace + ".xml");
8284
if (f.isFile() && f.exists()) {
8385
client.newServerEval()
8486
.addVariable("user", user)
8587
.addVariable("exported-workspace", new FileHandle(f).withFormat(Format.XML))
86-
.xquery(QconsoleScripts.IMPORT).eval();
88+
.xquery(importQuery).eval();
8789

8890
if (logger.isInfoEnabled()) {
8991
logger.info(format("Imported workspace from %s", f.getAbsolutePath()));
@@ -96,6 +98,15 @@ public List<File> importWorkspaces(String user, String... workspaceNames) {
9698
return files;
9799
}
98100

101+
protected String determineImportScriptToUse() {
102+
String version = client.newServerEval().xquery("xdmp:version()").evalAs(String.class);
103+
String xquery = QconsoleScripts.IMPORT;
104+
if (version != null && version.startsWith("8")) {
105+
return xquery.replace("qconsole-model:default-database()", "qconsole-model:default-content-source()");
106+
}
107+
return xquery;
108+
}
109+
99110
/**
100111
* Defaults to ~/.qconsole/workspaces.
101112
*

src/main/java/com/marklogic/client/ext/qconsole/impl/QconsoleScripts.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*/
77
public class QconsoleScripts {
88

9+
/**
10+
* This relies on internal APIs in the qconsole-model function that have changed between MarkLogic 8 and 9.
11+
* Specifically, qconsole-model:default-content-source() in ML8 was removed and qconsole-model:default-database()
12+
* can be used instead.
13+
*/
914
public static final String IMPORT = "xquery version \"1.0-ml\";\n" +
1015
"\n" +
1116
"declare namespace qconsole=\"http://marklogic.com/appservices/qconsole\";\n" +
@@ -73,7 +78,7 @@ public class QconsoleScripts {
7378
" let $content-source :=\n" +
7479
" if ( exists($q/@content-source) )\n" +
7580
" then string($q/@content-source)\n" +
76-
" else qconsole-model:default-content-source()\n" +
81+
" else qconsole-model:default-database()\n" +
7782
" let $mode := string($q/@mode)\n" +
7883
" let $query-text := text { $q }\n" +
7984
" let $q-uri := concat(\"/queries/\", $qid, \".txt\")\n" +

0 commit comments

Comments
 (0)