Reputation: 33
Is there a way to call xqy or sjs from my java application, just like I can call a stored procedure in oracle DB?
Another question I have about the xqy or sjs is how to debug them?
Thanks in advance.
Upvotes: 1
Views: 127
Reputation: 66783
Yes, there are multiple ways to invoke JavaScript and XQuery modules in MarkLogic from Java.
Depending upon the type of MarkLogic application server, if it's an HTTP or XDBC, if the modules are installed or if you are sending code to be evaluated, and whether you prefer to use MarkLogic Java APIs or make your own HTTP calls.
You could use the MarkLogic Java Client API to invoke a resource service extension or to evaluate your own JavaScript or XQuery with ServerEvaluationCall:
String javascript = "'hello world'";
String response = client.newServerEval()
.javascript(javascript)
.evalAs(String.class);
assertEquals("hello world", response);
DataServices can be used to expose functionality and build Java client stubs to invoke them.
With XCC you can invoke an installed module with ModuleInvoke() or ModuleSpawn, or eval JavaScript or XQuery with an AdhocQuery
You could also make your own calls to the REST /v1/eval or /v1/invoke endpoints.
As for debugging, you can use Visual Studio code to connect to a debug enabled appserver set breakpoints and step through your JavaScript and XQuery modules.
Upvotes: 4