|
XCC/J 3.2-9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.marklogic.xcc.examples.SimpleQueryRunner
This is a very simple class that will submit an XQuery string to 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 a filename to read a query from. It loads the file, submits
its contents to the server for evaluation 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
invoking execute(String).
| Constructor Summary | |
SimpleQueryRunner(URI serverUri)
Construct an instance that will submit query requests to the server represented by the given URI. |
|
| Method Summary | |
ResultSequence |
execute(String query)
Submit the given query string and return a ResultSequence object. |
String |
executeToSingleString(String query,
String separator)
Submit the given query string and return a single String which is the concatenation of all the ResultItems, separated
by the given separator string. |
String[] |
executeToStringArray(String query)
Submit the given query string and return an array of Strings, possibly of length zero, which contains the String value of each ResultItem (see XdmValue.asString()) |
Request |
getRequest()
Returns the Request object used internally to submit
requests. |
static void |
main(String[] args)
Simple command-line driver that will read a query from a file and submit it to the server at the given URL. |
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 |
public SimpleQueryRunner(URI serverUri)
throws XccConfigException
serverUri - A URI that specifies a server per
(ContentSourceFactory.newContentSource(java.net.URI)).
XccConfigException - If the URI is not a valid XCC server URL.| Method Detail |
public ResultSequence execute(String query)
throws RequestException
ResultSequence object.
query - XQuery code as a String, to be evaluated by the server.
ResultSequence, possibly with size zero.
RequestException - If an unrecoverable error occurs when submitting
or evaluating the request.
public String[] executeToStringArray(String query)
throws RequestException
ResultItem (see XdmValue.asString())
query - XQuery code as a String, to be evaluated by the server.
ResultSequence.
RequestException - If an unrecoverable error occurs when submitting
or evaluating the request.
public String executeToSingleString(String query,
String separator)
throws RequestException
ResultItems, separated
by the given separator string.
query - XQuery code as a String, to be evaluated by the server.separator - A String value which will be inserted in the
final string between each item of the sequence. A value of null
is equivalent to the empty string.
XdmValue.asString() value of each item
with the separator string inserted between each instance.
RequestException - If an unrecoverable error occurs when submitting
or evaluating the request.public Request getRequest()
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.
Request.public void setRequestOptions(RequestOptions options)
RequestOptions instance to associate
with submitted queries.
options - An instance of RequestOptions or null.
public static void main(String[] args)
throws Exception
args - First arg: a URL as per
ContentSourceFactory.newContentSource(java.net.URI).
Second arg: a filename to read XQuery text from.
Exception - No exceptions are handled, anything that
goes wrong will spew out a stack trace and exit.
|
XCC/J 3.2-9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Complete online documentation for MarkLogic Server, XQuery and related components may be found at developer.marklogic.com