Database Reference
In-Depth Information
There are just four main concepts that you need to understand in the XQJ API to
make requests to eXist— data sources , connections , expressions , and result sequences :
XQDataSource
The data source provides the main driver of XQJ and defines how you connect to
the server. With the net.xqj.exist.ExistXQDataSource implementation from
xqj.net , you need to set two properties to be able to connect to eXist (see
Example 13-16 ):
serverName
This is the hostname or IP address of the eXist server that you wish to con‐
nect to. If you are running your XQJ client on the same machine as eXist,
you may use either localhost or 127.0.0.1 .
port This is the TCP port that the eXist server you wish to connect to is listening
on. If you have not reconfigured this setting in eXist, it will be 8080 by
default.
Example 13-16. Setting up the XQDataSource for connecting to eXist
final XQDataSource xqs = new ExistXQDataSource ();
xqs . setProperty ( "serverName" , "localhost" );
xqs . setProperty ( "port" , "8080" );
XQConnection
The connection represents an XQJ-connected session with the server and is
obtained from the data source. When requesting the connection from the data
source, you should provide your username and password for accessing eXist. The
eXist XQJ implementation uses REST, so there is no persistent connection;
rather, HTTP calls are made as needed by the XQConnection object. However,
you should always call close on the XQConnection object to clean up any
retained objects. See Example 13-17 .
Example 13-17. Opening an authenticated XQConnection to eXist
XQConnection connection = dataSource . getConnection ( "admin" , "mypassword" );
XQExpression
The expression represents an XQuery expression that may be sent to the server
and executed. It is also possible to use XQPreparedExpression if you wish to exe‐
cute the same expression multiple times with different parameters (e.g., external
variable bindings).
Search WWH ::




Custom Search