XCC/J 6.0-3

com.marklogic.xcc.examples
Class ModuleRunner

java.lang.Object
  extended by com.marklogic.xcc.examples.ModuleRunner

public class ModuleRunner
extends Object

This is a very simple class that will invoke a named XQuery module on the server and return the result.

Click here for the source code for this class

The main() method looks for two command-line args, a URL for the server ( ContentSourceFactory.newContentSource(java.net.URI)) and theURI of a module to invoke. This URI should be relative to the "Library" path set in the XDBC server configuration for the content server you're connection to (arg #1). This program invokes the named module and then prints the result sequence to stdout, one item per line.

The class has methods the could be used to set request options and to obtain the results as an array of Strings or as a real ResultSequence.

If you want to set external variables for a request, you can call getRequest() to obtain a reference to the internal Request object and set the variable values on it before calling invoke(String).

ToDo: Accept variable names and values on the command line.


Constructor Summary
ModuleRunner(URI serverUri)
          Construct an instance that will invoke modules on the server represented by the given URI.
 
Method Summary
 Request getRequest()
          Returns the Request object used internally to submit requests.
 ResultSequence invoke(String moduleUri)
          Invoke the module with the given URI and return the resulting ResultSequence.
 String invokeToSingleString(String moduleUri, String separator)
           
 String[] invokeToStringArray(String moduleUri)
           
static void main(String[] args)
           
 void setRequestOptions(RequestOptions options)
          Set (or clear) the RequestOptions instance to associate with submitted queries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModuleRunner

public ModuleRunner(URI serverUri)
             throws XccConfigException
Construct an instance that will invoke modules on the server represented by the given URI. Note that the URI will not be validated at this time.

Parameters:
serverUri - A URI that specifies a server per ( ContentSourceFactory.newContentSource(java.net.URI)).
Throws:
XccConfigException - If the URI is not a valid XCC server URL.
Method Detail

invoke

public ResultSequence invoke(String moduleUri)
                      throws RequestException
Invoke the module with the given URI and return the resulting ResultSequence.

Parameters:
moduleUri -
Returns:
An instance ResultSequence, possibly with size zero.
Throws:
RequestException - If an unrecoverable error occurs when submitting or evaluating the request.

invokeToStringArray

public String[] invokeToStringArray(String moduleUri)
                             throws RequestException
Throws:
RequestException

invokeToSingleString

public String invokeToSingleString(String moduleUri,
                                   String separator)
                            throws RequestException
Throws:
RequestException

getRequest

public Request getRequest()
Returns the Request object used internally to submit requests. This object can be used to set external variables that will be bound to the query when submitted. You should not set your own RequestOptions object, use setRequestOptions(com.marklogic.xcc.RequestOptions) instead.

Returns:
An instance of Request.

setRequestOptions

public void setRequestOptions(RequestOptions options)
Set (or clear) the RequestOptions instance to associate with submitted queries.

Parameters:
options - An instance of RequestOptions or null.

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

XCC/J 6.0-3

Copyright © 2013 MarkLogic Corporation. All Rights Reserved.

Complete online documentation for MarkLogic Server, XQuery and related components may be found at developer.marklogic.com