任何人都试图使用XCC java类连接到Marklogic - 我想连接并进行查询但不使用' adhocquery' (xquery) - 这可能吗?使用XCC Session或Request类?
答案 0 :(得分:1)
您可以使用请求调用模块,而不是执行adhocQuery。newModuleInvoke()
String connectionUri = "xcc://user:password@localhost:8888";
String moduleUri = "/some/module.xqy";
ContentSource contentSource = ContentSourceFactory.newContentSource(connectionUri);
ResultSequence resultSequence = null;
try (Session session = contentSource.newSession()) {
Request request = session.newModuleInvoke(moduleUri);
/*
*if you need to set request parameters, look at the setXXXVariable methods
* https://docs.marklogic.com/javadoc/xcc/com/marklogic/xcc/Request.html
* i.e.
* request.setNewStringVariable("foo", "bar");
* request.setVariable(xdmVariable); //see also: ValueFactory.newVariable()
*/
resultSequence = session.submitRequest(request);
//do stuff with the result sequence
} catch (RequestException exc) {
//Determine if the exception is retryable or should fail
} catch (Exception exc) {
//Determine what to do with other exceptions
} finally {
//unfortunately, ResultSequence doesn't implement closable...
if (null != resultSequence && !resultSequence.isClosed()) {
resultSequence.close();
resultSequence = null;
}
}