Java client cookbook
This document describes how to use the Java client API to interact with the Nxqd server. Two modes of operation exist, standard Nxqd mode, and Xml:Db mode. Support for the full Xml:Db specification is not completed yet, so your mileage may vary.
Dependencies
The easiest way to use the Nxqd Java API is via
Maven. Simply add the following to your
project.properties
file :
maven.repo.remote=http://nxqd.sourceforge.net/repository,http://www.ibiblio.org/maven
This will configure Maven to download the correct jars from the Nxqd Maven repository. Now add the dependency into your
project.xml
file :
<dependency>
<id>nxqd</id>
<groupId>nxqd</groupId>
<version>1.0</version>
<url>http://nxqd.sourceforge.net</url>
</dependency>
Alternatively, if you would like to use Ant or other build tools, you will need to manually download and configure all of the Nxqd dependencies listed
here.
Nxqd mode usage
This mode provides the tightest integration with existing
Sleepycat functionality, and in theory should provide slightly better XPath and XQuery performance.
For more comprehensive and up to date information of all functionality available, please browse the
Javadoc API.
Code snippets |
- Connecting to the Nxqd server
String host = "localhost";
int port = 8080;
NxqdManager client = new NxqdManager(host,port);
- Creating and deleting a Container
String containerName = "mycontainer";
// create the container
NxqdContainer container = client.createContainer(containerName);
// delete the container
client.deleteContainer(container.getName());
- Adding, retrieving and removing a document
String testDocument = "....";
String documentId = "mydocumentid";
org.w3c.dom.Document doc1 = net.sf.nxqd.Utils.docFromString(testDocument);
Document doc2 = null;
// add the document
container.putDocument(documentId,doc1);
// retrieve the document
org.w3c.dom.Document doc2;
doc2 = container.getDocument(documentId);
// delete the document
container.deleteDocument(documentId);
|
Xml:Db mode usage
This mode is written on top of the Nxqd-mode API, and provides a standard
Xml:Db API view for your code to interact transparently with the Nxqd server, or other
Xml:Db servers such as
eXist and
Apache.
Due to the fact that
Sleepycat does not natively support nested containers, some of the XPath and XQuery expressions have to be pre-processed to support nested recursion through this virtual recreation of nested containers, and possible performance issues may arise.
Xml:Db code examples |
- Configuring and loading the correct database driver
Class c = Class.forName("net.sf.nxqd.xmldb.NxqdDatabase");
String uriPrefix = "xmldb:nxqd://localhost:8080/db";
Database database = (Database) c.newInstance();
DatabaseManager.registerDatabase(database);
rootCollection = DatabaseManager.getCollection(uriPrefix, username, password);
- Creating and deleting a Container
String collectionName = rootCollection.createId();
Collection parentCollection = serviceParent.createCollection(collectionName);
String[] children = parentCollection.listChildCollections();
CollectionManagementService service = (CollectionManagementService)rootCollection.getService("CollectionManagementService", "1.0");
service.removeCollection(collectionName);
|