eXist-db

Introduction

The eXist-db XML database is a third party NoSQL database written in Java. A good overview is available on Wikipedia

The software is available for download here and we have an instance running in the lab on 192.168.1.180:8081 for the console (admin/cdsreflab)

The main documentation page is here

I particular I recommend reading the development and quick start pages.

Health E-Decision

New Application named as HeD is created in instance running in the lab : http://192.168.1.180:8081/exist/apps/HeD/index.html which can also be found in the Exist DB Dashboard. This application contains schema and data folders for keeping Schema and Instance Data files respectively under the root directory : /db/apps/HeD/modules/schema/ and /db/apps/HeD/modules/data/

Order Service Exist DB Implementation

For Integrating Exist DB into our existing codebase following steps are followed : 

  • Downloaded required JARs (Unmanaged third party JARs) and created In-Project repository into vacds-order-service/order-service-engine-ri/repo/ and added repository in vacds-order-service/order-service-engine-ri/pom.xml

    In Project Repo
    	<repositories>
    		<!-- In-Project Repository -->
    	    <repository>
    			<id>in-project</id>
    			<name>In Project Repo</name>
    			<url>file://${project.basedir}/repo/</url>
    		</repository>
    	</repositories>
  • Included following dependencies into vacds-order-service/order-service-engine-ri/pom.xml

    Exist DB Dependencies
    		<!-- Exist DB Dependencies -->
    		<dependency>
    			<groupId>exist</groupId>
    			<artifactId>exist</artifactId>
    			<version>1.1.1</version>
    		</dependency>
    		<dependency>
    			<groupId>exist</groupId>
    			<artifactId>exist-xmldb</artifactId>
    			<version>1.0</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.ws.xmlrpc</groupId>
    			<artifactId>xmlrpc</artifactId>
    			<version>2.0.1</version>
    			<exclusions>
    				<exclusion>
    					<groupId>commons-logging</groupId>
    					<artifactId>commons-logging</artifactId>
    				</exclusion>
    			</exclusions>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.xmlrpc</groupId>
    			<artifactId>xmlrpc-client</artifactId>
    			<version>3.1.3</version>
    		</dependency>
  • Created ExistDatabaseManager class in package org.socraticgrid.hl7.services.orders.functional of vacds-order-service/order-service-engine-ri/ project which will be used to initialize the database connection and returns org.xmldb.api.base.Collection. Any class in which Exist DB Query or Update functionality is required this class can be autowired to that class and can be used for performing Exist DB operation.
  • A property file named as exist-db.properties is created under src/main/resources of vacds-order-service/order-service-engine-ri/ project which contains following important properties and used by ExistDatabaseManager class to create database connection.

    exist-db.properties
    url=xmldb:exist://192.168.1.180:8081/exist/xmlrpc
    collection=/db/apps/HeD/modules/data/
    username=admin
    password=cdsreflab

    The property collection contains absolute path of the folder which contains our XML Instance data files. As of now for data we created /db/apps/HeD/modules/data/ collection.

Examples

Example 1 : RetrieveExample

This example simply retrieves the content of provided data instance file. It takes 2 run time arguments as shown below : 

args[0] Should be the name of the collection to access

args[1] Should be the name of the resource to read from the collection

Example : java RetrieveExample /db/apps/HeD/modules/data/ books.xml

Example 2 : XPathExample

This example compiles the provided XPath and retrieves the content from the provided collection. It takes 2 run time arguments as shown below : 

args[0] Should be the name of the collection to access

args[1] Should be the XPath expression to execute

Example : java XPathExample /db/apps/HeD/modules/data/ /bookstore/book[price>30.00]

Example 3 : XQueryExample

This example compiles the provided XQuery and retrieves the content from the provided collection. It takes 2 run time arguments as shown below : 

args[0] Should be the name of the collection to access

args[1] Should be the XQuery to execute

Example : java XQueryExample /db/apps/HeD/modules/data/ doc(\"books.xml\")/bookstore/book[price>30.00]

Example 4 : CreateUpdateExample

This example reads the input data instance file and write into the provided collection into Exist DB. If the provided collection does not exist it will create one. It takes 2 run time arguments as shown below : 

args[0] Should be the name of the collection to access

args[1] Should be the name of the file to read and store in the collection

Example : java CreateUpdateExample /db/apps/HeD/modules/data/ D://StoreData.xml