Copyright © 2007
Rights to the content of this publication
This publication contains proprietary information belonging to
Trademarks
1 Introduction
1.1 What is this?
1.2 Who is this manual for?
1.3 How is this manual structured?
1.4 How to use this manual?
1.5 Conventions
1.5.1 Terminology
1.5.2 Text usage
1.6 Support and feedback
2 Quickstart
2.1 Pre-installation
2.2 Installing
2.3 Creating a database
2.4 Running a sample
3 General information
3.1 What is
3.2 The technology behind
3.2.1 DOM support and data manipulation
3.2.2 Searching, linking and indexing
3.2.3 Session and transaction control
3.2.4 Administration features
3.2.5 Import from non-XML resources and storage of BLOBs
3.2.6 Transform XML into various outputs
3.2.7 Versioning
3.3
3.3.1 Federated database
3.3.2 Databases
3.3.3 Users and user lists
3.3.4 Groups and group lists
3.3.5 Indexes and index lists
3.3.6 Libraries
3.3.7 Catalogs and DTDs and XML Schemas
3.3.8 Documents
3.3.9 Super user
4 Installing
4.1 Installation requirements
4.1.1 Things to check before installation
4.1.1.1 Supported platforms
4.1.1.2 System requirements
4.1.1.3 Java settings
4.1.2 Things to do before installation
4.1.2.1 Log in as an administrator
4.2 Installation - Windows
4.2.1 Run the installation program
4.3 Installation - UNIX
4.3.1 Starting the installation
4.3.2 Entering installation parameters
4.3.3 Performing post-installation steps
4.4 Verify the installation
4.5 Running the samples
4.5.1 Create a database
4.5.2 Execute the samples
4.6 Uninstalling
4.7 Configuring the xhive.bootstrap property
4.8 Using the Java command line instead of xhive-ant
4.9 The
4.9.1 Configuration of the server
4.9.2 XHStartServer
4.9.3 XHStopServer
5 Creating applications
5.1 Introduction
5.2 Create a database
5.2.1 Creating a database using XHCreateDB
5.2.2 Creating a database using the adminclient
5.2.3 Creating a database using API functions
5.3 Connect to the database
5.4 Use sessions and transactions
5.5 Create libraries
5.6 Parse XML documents
5.7 Validate XML documents
5.8 Store XML documents
5.9 DOM configuration settings
5.9.1 Deviations from specification
5.9.2 Additional parameters
5.10 Parse documents with context
5.11 Store BLOBs
5.12 Import non-XML data
5.13 Create documents
5.14 Retrieve XML documents and document parts
5.14.1 Through DOM operations
5.14.2 By document ID
5.14.3 By document name
5.14.4 Using the executeFullPathXPointerQuery() method
5.14.5 Using XQuery, XPath and XPointer
5.14.6 Using a Context Conditioned Index
5.15 Use XQuery
5.16 Use XPath and XPointer
5.16.1 XPath
5.16.2 XPointer
5.16.3 Working with namespaces
5.17 Use indexes
5.17.1 Library id indexes
5.17.2 Library name indexes
5.17.3 Id attribute indexes
5.17.4 Element name indexes
5.17.5 Value indexes
5.17.6 Full text indexes
5.17.7 Context conditioned indexes
5.17.7.1 Creating index node filters
5.18 Traverse XML documents
5.18.1 Using DOM operations
5.18.2 Through DOM Traversal
5.18.3 Using function objects
5.19 Export XML documents
5.20 Publish XML documents
5.20.1 Publish using XSLT
5.20.2 Publish to PDF
5.21 Use XLink
5.22 Use abstract schemas
5.23 Revalidate documents with XML schema
5.24 Access PSVI information
5.25 Manage users and groups
5.26 Use versioning
5.26.1 Working with versioned documents
5.26.2 Retrieving (older) versions of documents
5.26.3 Branching
5.26.4 Node level versioning
5.27 Using metadata on library children
5.28 Using JAAS to connect to the database
6 Using Sessions & Locking
6.1 Working with sessions
6.1.1 The session lifecycle
6.1.1.1 XhiveDriverIf.createSession()
6.1.1.2 join()
6.1.1.3 leave()
6.1.1.4 connect()
6.1.1.5 begin()
6.1.1.6 commit()
6.1.1.7 rollback()
6.1.1.8 checkpoint()
6.1.1.9 disconnect()
6.1.1.10 terminate()
6.1.2 Sessions and references to database objects
6.2 Sessions and transaction isolation
6.3 Sessions and locking
6.3.1 What gets locked when?
6.3.2
6.3.3 Readonly transactions
6.4 The XHSessionInfo tool
7 Using XQuery
7.1 Executing queries
7.2 External variables and functions
7.3 Accessing documents and libraries
7.4 XQuery Error reporting
7.5 Data model discrepancies
7.6 Current implementation
7.6.1 XPath axes
7.6.2 Module Imports
7.6.3 Supported options and extension expressions (pragmata)
7.6.3.1
7.6.3.2 Examples
7.6.4 XQuery Update Syntax
7.6.5 Conditional Order By
7.6.6 Extension functions
7.6.7 Namespace declarations
7.6.8 Collation support
7.6.9 Limitations
7.7 Using indexes in XQuery
7.7.1 Value and element name indexes
7.7.2 Range queries
7.7.3 Indexes on metadata
7.7.4 Multiple indexes
7.7.5 Using indexes to enhance order by performance
7.7.6 Ignoring indexes
7.8 Type information and XQuery
7.9 Extending XQuery functionality using Java
7.9.1 Type marshalling
7.9.2 Java objects and instance methods
7.9.3 Type checking
7.9.4 Known limitations
7.10 Miscellaneous performance tips
7.11 Full text searching
7.11.1 xhive:fts function
7.11.2 Full text search query syntax
7.11.3 Boolean queries
7.11.4 Prefix search
7.11.5 Phrase search
7.11.6 Wildcards
7.11.7 Tokenization
7.11.8 The analyzer
7.11.9 Examples
7.11.10 Limitations
8 Using indexes
8.1 Library indexes
8.1.1 Library id indexes
8.1.2 Library name indexes
8.2 Id attribute indexes
8.3 Element name indexes
8.4 Value indexes
8.4.1 Value Index Types
8.5 Full text indexes
8.6 Path indexes
8.6.1 Path index specification syntax
8.7 Context conditioned indexes
8.8 Index performance
8.8.1 Index scope
8.8.2 Index selectiveness
8.8.3 Index property: sorted keys
8.8.4 Summary
8.9 Concurrent indexes
9 Using validation and the Catalog
9.1 Introduction
9.2 Catalog content
9.2.1 Catalog location
9.2.2 Identification of XML Schema and DTD models
9.2.3 Managing models
9.3 Linking models to documents
9.3.1 DTDs
9.3.2 XML Schema
9.4 Validated parsing
9.4.1 DTDs
9.4.2 XML Schema
9.5 Validation
9.5.1 DTDs
9.5.2 XML Schema
9.6 PSVI
10 Performance
10.1 Internal server
10.2 JVM settings and cache size
10.3 Database page size
10.4 Multiple disks
10.5 Linux filesystems
10.6 Disk write caches
11 Internal structure of
11.1 Segments and files
11.1.1 Segments
11.1.2 Files
11.1.3 Setting up database configurations
11.1.4 Log files
11.2 Database configuration files
11.2.1 xhive-clustering element
11.2.2 segment element
11.2.3 file element
12 Administering
12.1 Starting the adminclient
12.2 Importing data
12.3 Exporting and editing documents
12.4 Adding Indexes
12.5 Querying
12.6 Creating a new federation
12.7 Creating a backup
12.7.1 Online ("hot") backups
12.7.2 Incremental backups
12.7.3 The XHBackup tool
12.7.4 Performance considerations
12.7.5 Restoring backups
12.7.6 The XHRestore tool
12.7.7 Offline ("cold") backups
12.7.8 Snapshot backups
12.7.9 Storing individual libraries and documents
12.8 Using Secure Socket Layer (SSL)
12.8.1 Server side setup
12.8.2 Client side setup
12.9 Readonly federations (CDROM usage)
12.10 Federation sets
12.10.1 Creating federation sets
12.10.2 Using federation sets
13 Replication
13.1 Introduction
13.2 Creating a replica
13.3 Running a replicator
13.3.1 Dedicated server
13.3.2 Internal server
13.4 Readonly usage of replicators
13.4.1 Temporary data
13.5 Removing a replica
13.6 Federation metadata
13.6.1 Replicated metadata
13.6.2 Metadata not replicated
13.7 Moving the master copy
13.7.1 Failure of the master server
13.7.2 Scheduled moving of the master copy
14 Ant tasks
14.1 Introduction
14.2 Requirements:
14.3 Working with
14.4
14.5
14.5.1 <federation/>
14.5.2 <database/>
14.5.3 <library/>
14.5.4 <document/>
14.5.5 <user/>
14.5.6 <group/>
14.6 Referencing
14.7
14.7.1 <createdatabase/>
14.7.2 <copydatabase/>
14.7.3 <renamedatabase/>
14.7.4 <deletedatabase/>
14.7.5 <backup/>
14.7.6 <restore/>
14.7.7 <replicatefederation/>
14.7.8 <createlibrary/>
14.7.9 <deletelibrary/>
14.7.10 <parse/>
14.7.11 <libraryidindex/>
14.7.12 <idattributeindex/>
14.7.13 <pathvalueindex/>
14.7.14 <valueindex/>
14.7.15 <elementindex/>
14.7.16 <fulltextindex/>
14.7.17 <metadatavalueindex/>
14.7.18 <metadatafulltextindex/>
14.7.19 <listindexes/>
14.7.20 <deleteindex/>
14.7.21 <batchindexadder/>
14.7.22 <exportlibrary/>
14.7.23 <serialize/>
14.7.24 <deserialize/>
14.7.25 <serialize-users/>
14.7.26 <deserialize-users/>
14.7.27 <adduser/>
14.7.28 <deleteuser/>
14.7.29 <addgroup/>
14.7.30 <deletegroup/>
14.7.31 <session/>
14.7.32 <createfederation/>
14.7.33 <updatefederation/>
14.7.34 <registerreplicator/>
14.7.35 <unregisterreplicator/>
14.7.36 <closedriver/>
14.8 Notes
This manual is designed to provide a technical introduction to the
This manual contains the basic information on
This manual is for all users of
Java.
XML.
The operating system that you are using.
Basic database principles such as transactions, locking, and access rights.
Furthermore, some knowledge of the following subjects is recommended, but not necessary:
DOM.
XQuery
XSLT.
This manual is structured in a way that provides basic and essential information first, and then moves on to more advanced topics. This enables you to get started quickly with
Quickstart gives you an overview of the essential steps you need to perform to install and set up
General information describes the architecture of
Installing
Creating applications gives you instructions on how to develop
Using Sessions (and Locking) explains in detail the features and issues of the
Using XQuery explains in detail how to use XQuery within
Using Indexes describes how you can use one of
Using the Catalog and DTDs describes how
Internal Structure of
Administering
It is recommended that you read this manual chapter by chapter, as this provides you with a logical progression through the concepts and tasks involved in using
If you are an experienced user of XML and
If you are an administrator, the Administering
To ensure clarity and consistency, this manual uses various conventions in the areas of terminology and text usage.
Unless otherwise stated, the product and the application refer to the
The adminclient is a front-end component of
In general, the
Strings of literal code and command-line entries appear in courier font. When
requested to enter such a string, enter the string exactly as it appears in the manual.
Variable information appears in italicized text. Sometimes variables are located in the middle of a literal string, in which case you must replace the italicized part with a suitable value in that context.
Sample code appears in a text box, like this:
Here is where you find sample code.
Sample code is provided to illustrate various programming concepts and techniques in
We appreciate your feedback on this manual, and on any aspect of the
You can also access product information, browse FAQs, and submit questions through our Web site at www.x-hive.com. Up-to-date technical information, including newer versions of and updates to this manual, can be found at support.x-hive.com.
This section aims to get you started quickly with
Before installing
When installing on Windows 2000, you must be logged on as an administrator or a user with similar access.
On Windows, simply run the setup.exe file and follow the instructions on screen. Besides installing the files in the proper directories, your PATH environment variable is augmented, and a page server service is started. If you have previous versions of
On UNIX, start the distribution from the distribution directory, with the command
sh setup.sh /InstallationPath/xhive.
The UNIX installation requires some post-installation steps, which are described in the readme.txt file of the distribution. You can install the
The first step after installing
The easiest way to do this is through the AdminClient, as follows:
Start the AdminClient by running XHAdmin, which is located in the bin subdirectory of the
Create a database by selecting the menu option Databases->Create database.
Create a database named united_nations with the super user password as entered during installation of
northsea. This database will be used by default in all samples described in this manual.
After creating the database, you can close the administrator client. Note that you can also use the administrator client to view the data after you have run the samples, and to perform other actions.
Alternatively the command line tool XHCreateDB can be used to create databases.
ant build system. A command line tool called xhive-ant is provided which sets the proper CLASSPATH and other parameters. The samples are run as follows:
Open a command prompt and go (cd) to the XhiveDir\bin directory.
To run a sample which inserts two documents into the database, enter the command:
xhive-ant run-sample -Dname=manual.StoreDocuments
On successful completion of the sample, a message appears stating the number of documents stored in the database.
The sources of all the samples can be found in XhiveDir\src\samples\manual. You should check the values of the properties in SampleProperties.java, so that they match your settings, before running the samples.
Document Object Model (DOM) Level 1
DOM Level 2 (Core and Traversal)
DOM Level 3 (Core and Load/Save)
This section introduces the following technical aspects of
XML Query Language (XQuery) is a string syntax that you can use to address any piece of information in an XML document, make selections based on conditions, and even construct new structures based on queried information. This makes XQuery an extremely useful tool for searching in XML databases.
Besides XQuery, we also have support for XPath and XPointer queries. For information on using XPath and XPointer, see Use XPath and XPointer.
XLink is a W3C recommendation that enables links between XML documents. You can use XLink to create simple links equivalent to <a href> links in HTML, and to create more complex links, known as extended links. You can use extended links to, for example, create one-to-many links, and to add some semantic meaning to your links. For a complete and up-to-date description of XLink, refer to the XML Linking Language (XLink) Version 1.0
documentation at the W3C website.
Indexing enables faster access to parts of a library or document and increases the performance and scalability of
For instructions on how to use sessions and transactions in
The administration features of
More information on the import facilities of
Next to XML documents it is also possible to store Binary Large OBjects (BLOBs) in
com.xhive.util.interfaces.XhiveFormatterIf,
for producing formatted documents that are converted to PDF. You can either format an FO document as a PDF string, or can transform an XML file into a FO document and then format it as a PDF string. For a detailed specification of the formatAsPDF method, refer to the Publish XML documents section.
This section describes the logical architecture of
The following diagram provides an overview of the logical architecture of

A single
A federated database contains the following objects:
You can obtain an iterator for all the database names using the getDatabases()
method of XhiveFederationIf.
An
Blobs (binary large objects)
Every user of an
In addition to regular users, a super user account exists. This account is created automatically during installation, and enables initial database configuration. All other users have their accounts created by the database administrator (a regular user with extra privileges).
A group is an object in the database with which you can associate one or more users. The main purpose of a group is to enable you to assign the same access rights and privileges to a subset of users. By assigning rights to groups, you then only need to add and remove users from a group to change their privileges.
An index list provides a list of all the indexes of a library or document.
A library is a logical means of storing documents or other libraries. You can create as many libraries as you need to produce a hierarchy or storage architecture for your documents.
The nested structure of libraries within
The catalog is the part of the database that stores Document Type Definitions (DTDs) and XML Schemas. For information, see the Catalog section.
A document is the means of storage for XML data in an
A federated database has one super user, with username superuser. The super user has the right to create and delete databases, and to perform administration operations like setting the license key and backing up the database. The super user cannot access regular data like libraries and documents.
The super user is not represented by an object in the
Before running the installation program, you need to perform both checks and tasks to ensure that the installation is successful.
You need to check the following issues before installation:
The following table shows the system requirements for each supported platform.
| RAM | 256MB |
| Hard drive space for
| 30MB |
| Hard drive space per database | 1MB (minimum, real size depending on data loaded) |
| Java | JDK 5 or higher |
| Network | TCP/IP |
To install
When you have satisfied the installation requirements, you can run the installation program. Follow all the prompts in the installation program, then create a database. This completes the installation procedure -
On Windows, the installation program you need to run is called setup.exe, located in the root directory of the
PATH environment variable is augmented. If you have previous versions of
When you run setup.exe, the installation process begins.

You simply need to follow the instructions on screen to complete the installation. The installation program requires your input for the following steps:
Accept the software license agreement. If you do not accept the license agreement, the installation is terminated.

Specify the target installation directory. The default on Microsoft Windows is C:\Program Files\Xhive.

Browse for the base directory of the applicable Java Development Kit. For example, C:\jdk1.5.

Enter the license key you received for the product. Note that there is a time limit on the validity of

Specify the password of the super user. This password is later needed to create databases with

Choose whether to proceed with a standard installation (recommended), or to perform some additional advanced installation steps.

If you proceed with a standard installation, the program files for
Specify the database directories. The installation program provides defaults for all
database directories, based on the installation directory. You should never put
database files on remote file servers, like NFS servers or MS Windows shares.
For performance, it's best to place the log files on another disk then the database files
(in
It is also possible to change the default page size. Ideally, the page size should match the page size of the filesystem where the database shall reside. You should not pick larger sizes than the file system one. See the section on page sizes for more information.

During installation, a service is installed and started that acts as a page-server. There are some settings to specify for this service:

Finally, you can set some JVM properties, that only relate to with what JVM options client applications like the samples through ant and the Adminclient are run.

After successful installation of
To have all settings take effect you will need to do log off and log in (a reboot is not necessary, only the PATH variable change needs to be registered).
On UNIX platforms you can install
Starting the installation.
Entering installation parameters.
Performing post-installation steps.
You must start the installation from the directory that contains the distribution files. Furthermore, a valid JVM must be available in the PATH variable before you run the installation. Both of these conditions are checked at the start of installation.
To install
sh setup.sh InstallationPath/xhive
sh setup.sh /opt/xhive
/opt/xhive/bin
/lib
/docOf course, to install X-Hive, you must have write access to the installation directory. When you start setup, the
After the installation files have been copied, you need to enter a number of parameters needed during installation. The format for these questions is:
Question [default] :
For most questions a default answer is provided. If that default is okay, press the Enter-key, otherwise type a new value (and press Enter) to override that default. If information you enter is incorrect, a message is displayed, and the question is asked again.
The basic questions are:
A base directory to the JDK - the installation program attempts to identify where the JDK resides based on the JAVA_HOME and PATH environment variables, but it is wise to check whether that directory really contains the full JDK.
Your valid
You need a super-user password to administer
After this you are asked whether you want to alter advanced settings. If you select no (the default) the installation is completed using default values for the advanced settings. If you select yes you can set the following parameters:
The database directory, where your data will reside.
The directory for journal files, for performance reasons you could place the journal files on a different harddisk from your database files.
The page size in bytes, ideally this should be equal to the block-size of the filesystem where the databases will be located (and never larger than that size). See the section on page sizes for more information.
The portnumber where the
The amount of pages the page server will cache. More means more memory usage but better performance.
Whether or not applications on other machines may access the pageserver on this machine.
The minimum and maximum amount of memory passed to the JVM (-Xms and -Xmx). These values are only used in scripts to start up client applications like the Adminclient and xhive-ant.
Other Java command line options (we try to default to some useful options here for certain platforms, usually you do not need to change them).
After you have installed
Add the XhiveDir/bin directory to your path, for example:
bash$ export PATH=${PATH}:XhiveDir/bin
tcsh> setenv PATH ${PATH}:XhiveDir/bin
Start the page server with the command XHStartServer. This will start a background process for the page server that
can then be accessed from e.g. the Administrator client.

The following are the most important commands that are available
after installation. Note that everything that can be done with
these commands can also be done by programing your own application
using the
| XHAdmin | Graphical administration client, for maintaining databases, users and content. |
| xhive-ant | Compile and run the samples, as well as other programs. |
| XHCreateDB | Create a new database. |
| XHDeleteDB | Remove an existing database. |
| XHCreateFD | Create a new empty federation |
| XHInstallFD | Set the superuser password and/ or license key on a federation. |
| XHBackup | Backup a federation to a backup file |
| XHRestore | Restore a federation from a backup file |
| XHSessionInfo | Shows debug information on currently open transactions and their locks |
| XHServer | Start or Shutdown a server process for a specific federation |
| XHStartServer | Start the dedicated background server process for the default federation |
| XHStopServer | Stop the dedicated background server process for the default federation |
| XHCreateReplica | Create a full replica (optionally including registering a replica id for it) of a federation at a given location. |
| XHSuspendDiskWrites | Ensure the federation files are flushed to disk and suspend (or resume) writing to them |
After you have installed
To create a database:
Start the AdminClient by running XHAdmin, which is located in the bin subdirectory of the
Create a database by selecting the menu option Databases->Create database.
Create a database named united_nations with the super user password as entered during installation of
northsea. This database will be used by default in all samples described in this manual.
After creating the database, you can close the administrator client. Note that you can also use the administrator client to view the data after you have run the samples, and to perform other actions.
You can also create databases using the command line tool XHCreateDB. For more details on creating databases, see the section Create a database in the Creating applications chapter.
ant tool:
Open a command prompt and go (cd) to the XhiveDir\bin directory.
To run a sample which inserts two documents into the database, enter the command:
xhive-ant run-sample -Dname=manual.StoreDocuments
On successful completion of the sample, a message appears stating the number of documents stored in the database.
The sources of all the samples can be found in XhiveDir\src\samples\manual.
In the (hypothetical) event that you would like to uninstall
uninstalling.txt file.
Uninstalling
On Unix, you should first stop the page server if running, with the command XHStopServer. Then, you can remove the installation and data directories.
A property called xhive.bootstrap specifies the location of the
If the property is a URL of the form
xhive://host:port, the
If the property is the complete (or relative) path to an XhiveDatabase.bootstrap file, an
If you are using xhive-ant to run
xhive.bootstrap property automatically points to the location of the
The syntax of the xhive.bootstrap property as used with xhive-ant
is:
java
-Dxhive.bootstrap=xhive://host:port
or
java
-Dxhive.bootstrap=PathName/XhiveDatabase.bootstrap
Where PathName is the complete path to the XhiveDatabase.bootstrap file.
It is also possible to specify the path to XhiveDatabase.bootstrap or the URL to
connect to in your Java application, as an argument to getDriver() on
XhiveDriverFactory.
If you use the Java command line, you first need to configure the CLASSPATH variable to include the following JAR files:
antlr.jar
fop.jar
icu4j.jar
jsr173_api.jar
lucene.jar
serializer.jar
xalan.jar
xbean.jar
xercesImpl.jar
xml-apis.jar
xhive.jar
For example, the following commands run the application myapp (assuming the
C:\xhive):
C:\xhive\bin>java -classpath C:\xhive\lib\antlr.jar;
C:\xhive\lib\fop.jar;
C:\xhive\lib\icu4j.jar;
C:\xhive\lib\jsr173_api.jar;
C:\xhive\lib\lucene.jar;
C:\xhive\lib\serializer.jar;
C:\xhive\lib\xalan.jar;
C:\xhive\lib\xbean.jar;
C:\xhive\lib\xercesImpl.jar;
C:\xhive\lib\xml-apis.jar;
C:\xhive\lib\xhive.jar;
-Dxhive.bootstrap=C:\xhive\data\XhiveDatabase.bootstrap
test.myapp
When you have installed
It is important to realize that this process is not a required part for the
What is also important to realize is that the server program is a very small Java program, accessing
the
XhiveDriverIf driver = XhiveDriverFactory.getDriver(bootstrapPath); // Get a driver for a bootstrap-location driver.init(cachePages); // Initialize the cache of the driver ServerSocket socket = new ServerSocket(port); // Create a listen socket driver.startListenerThread(socket); // Start accepting remote connections wait(); // Wait forever in this main thread
Only the lines related to startListenerThread are specific to accepting remote connections, adding
these lines to your own application will make it accept connections from other applications.
As mentioned in the performance section, running
The default configuration of a server is determined during the installation. The settings are the port-number to
accept connections on (default is '1235'), the size of the page-cache to use in the server (default is '1024'),
and from what address(es) to accept connections ('localhost' means only connections from the same
machine are accepted, '*' means that connections from every machine are accepted).
You can change these configuration parameters after installation, by changing the parameters in the
'configuration' files. For the windows service, this file is wrapper.conf, for Unix the parameters
need to be changed in the XHStartServer script directly. The files are located in XhiveDir/bin.
You will have to stop and start the server
process after any changes (see below). Please note that when enlarging the cache size, you will also have to
allocate more memory to the process, configured through the -Xmx parameter in the same configuration file
(in the installer, the calculation of the -Xmx parameter is based on 16MB+(pageSize*cachePages)), your selected
page size can be found in the XhiveDatabase.bootstrap file).
The dedicated process is not configured for SSL connections by default. However, examination of the configuration
files should show that that the server process is essentially the Java class com.xhive.tools.XhiveServer,
which matches the XHServer command. So examining the options of the XHServer command and reading
the SSL section should get you started on how to change the configuration file.
As explained, it is not required to use a server process at all. If you want to configure
FullPath/XhiveDatabase.bootstrap instead of xhive://hostname:portname as
the bootstrap path in your application.net stop xhive-server instsrv xhive-server remove
wrapper -i wrapper.conf (run from XhiveDir\bin) net start xhive-server
XHStartServer starts a background server process for the default federation, to which
other processes can connect. The log output of any errors is redirected to a file named server.log
which by is placed in the same directory where the XhiveDatabase.bootstrap file resides.
On Windows, this background server is implemented as a service, so this command consists only of starting
the service named 'xhive-server', which in turn runs the Java program com.xhive.tools.XhiveServer.
The service starts automatically when the machine boots. Note that since this is a service, the SYSTEM
account must have access to all involved resources (jars and database files).
On Unix, the background server is implemented as simply a Java process running in the background, so the command
consists of a script that starts a background Java process for the class com.xhive.tools.XhiveServer.
If you would want to run a server at startup, you
should add this command to your system startup configuration (be aware of the user under which the command is started in
that case, that user must have full access to all involved resources).
XHStopServer stops the background server process for the default federation.
On Windows, this means simply stopping the 'xhive-server' service.
On Unix, this involves killing the background process whose pid was registered in the file server.pid
placed in the same directory as where the XhiveDatabase.bootstrap file resides, by XHStartServer.
If there are any unexpected terminations of the process, you will have to remove this pid-file manually.
This chapter describes how to create
When developing an
We provide samples for most of the important functions. One of the ways to run a sample is through the xhive-ant tool. For example, you can use
xhive-ant run-sample -Dname=manual.StoreDocuments
StoreDocuments sample.
Before you run the samples, it is wise to adjust the values in src/samples/manual.SampleProperties.java to match your system.
When you install
As an
The command-line utility XHCreateDB.
The adminclient.
The Application Programming Interface (API) functions.
XHCreateDB
The command line utility XHCreateDB is located in the
XhiveDir
/bin directory. When creating a new database using XHCreateDB, you must give the name of the new database, the super user password, and the administrator password, as follows:
XHCreateDB
SuperUserPassword AdminPassword DatabaseName
Note:
Xhive and XHIVE are regarded as different database names. Passwords must be between three and eight characters long, and must be alphanumeric.
The default administrator password used in all samples is northsea. Make the appropriate changes to SampleProperties.java if a different password is used.
To create a database using the adminclient:
Start the adminclient.
Select Databases->Create database. The Create database window is displayed.

Enter the database name, super user password, and administrator password.
If you are a super user, you can create a database using the API.
The method for creating a database is called createDatabase(), and is located in the com.xhive.core.interfaces.XhiveFederationIf interface.
To create a new database using the API:
Start a session and open a connection to the database as super user. The databaseName parameter of the connect() call should be null:
XhiveDriverIf driver = XhiveDriverFactory.getDriver();
if (!driver.isInitialized()) {
driver.init(1024);
}
XhiveSessionIf session = driver.createSession();
session.connect(superUserName, superUserPassword, null);
Note:
By default, sample CreateDatabase.java uses northsea as the super user password. If you entered a different super user password during
Get a handle to the database federation:
XhiveFederationIf federation = session.getFederation();
Call createDatabase() with the name of the new database and the administrator password. You can specify a configuration
file or use a default configuration (null):
federation.createDatabase(newDbName, administratorPassword, null, System.out);
More information on the physical (file) structure of a database can be found in a separate section.
Note:
A super user can only create (and delete) a database. Therefore, after creating a database using the createDatabase() method, you need to disconnect and reconnect as an administrator to perform actions on the new database.
See also:
To connect to an
Obtain an
XhiveDriverIf xhiveDriver = XhiveDriverFactory.getDriver();
If you do not specify the bootstrap location in the environment of the JVM, you can also pass it as an argument to getDriver:
XhiveDriverIf xhiveDriver = XhiveDriverFactory.getDriver("xhive://localhost:1235");XhiveDatabase.bootstrap)Initialize the local page cache shared by the sessions for this driver:
xhiveDriver.init(1024);
(You should only initialize a specific driver once in your application, you can check with isInitialized()).
Create a new XhiveSessionIf:
XhiveSessionIf session = xhiveDriver.createSession();
Connect to the database, supplying a user name, password, and database name:
session.connect(UserName, UserPassword, DatabaseName);
See also:
There is also a separate chapter with background information on sessions.
In
To create a session in
Establish a connection to the database, as described in the Connect to the database section.
Create a session using the createSession() method, which you can find in the com.xhive.core.interfaces.XhiveSessionIf interface.
XhiveDriverIf driver = XhiveDriverFactory.getDriver();
if (!driver.isInitialized()) {
driver.init(1024);
}
XhiveSessionIf session = driver.createSession();
session.connect( userName, userPassword, databaseName );
Within a session one or more transactions can occur. A transaction is a group of operations that accesses and updates one or more XML documents or parts of XML documents in a database. Uniting a group of operations in a transaction enables you to make that group of operations 'atomic', that is, either all the instructions are executed to (successful) completion, or none are performed. This ensures that a database is never left in an inconsistent state.
To use transactions within
Start the transaction with the begin() method of com.xhive.core.interfaces.XhiveSessionIf.
Enter the instructions you want executed during the transaction.
End the transaction using either the commit() or rollback()
method. Use the commit() method when you actually want to execute your
transaction. Use the rollback()method when, because of some kind of
failure during the transaction, you want to reverse all the instructions within the
transaction. You should take care to always roll back the transaction if you get an
unexpected exception. If for instance the disk becomes full while loading a document,
modifications may have been done only partially. Committing such partial
modifications can result in an inconsistent data structure in the database.
Within the scope of the transaction, an application could, for example, parse external XML documents and append them to a library. If an error occurs during parsing or appending, the complete transaction is rolled back and none of the files are appended:
session.begin();
try {
LSParser parser = rootLibrary.createLSParser();
for ( int i=1; i<=numFiles; i++ ) {
Document newDocument = parser.parseURI( new File(baseFileName + i + ".xml").toURL().toString());
rootLibrary.appendChild(newDocument);
}
session.commit();
} catch (Exception e) {
// in case of an error: do a rollback
session.rollback();
e.printStackTrace();
}
// remove the session
session.disconnect();
session.terminate();
In addition to commit(),
checkpoint(), which you can use to commit all persistent operations executed since the last begin() or checkpoint(). One advantage of using checkpoint() instead of commit() is that the transaction remains active after the checkpoint() call, another is that references to database variables remain usable.
After a commit has been performed and you begin a new transaction on the same session, you must re-get all database variables on the session. This means that for instance the code
session.begin(); XhiveLibraryIf library = session.getDatabase().getRoot(); session.commit(); session.begin(); System.out.println(library.getName()); session.commit();
XhiveException with error code
XhiveException.OBJECT_DEAD when you access the library after the second
begin. The reason is that another concurrent session may have removed the
database objects that you have references to. You have to get a new reference to the
library after the second begin, e.g.:
session.begin(); XhiveLibraryIf library = session.getDatabase().getRoot(); session.commit(); session.begin(); library = session.getDatabase().getRoot(); System.out.println(library.getName()); session.commit();
The following sections discuss some of the possible persistent operations, including creating a library and storing a document.
Note:
Although disconnect() marks the end of the scope of a session, it does not
free all the resources allocated by the session. To improve performance, you should use
the terminate() method to terminate a session when you no longer need
it. If this is a remote session, this will terminate the TCP connection to the
See also:
In
The nested structure of libraries within
To create a library, perform the following steps:
Obtain a handle to the parent library. If the root library is the parent library, use the getRoot() method to get a handle. Otherwise, use a previously instantiated variable.
Create the library using the createLibrary() method.
Give the new library a unique name using the setName() method (optional).
Append the new library to its parent using the appendChild()
method.
The following code creates a library structure in the sample database with one top-level library called Publications. This top-level library has one sub-library called General Info.
// get a handle to the root library
XhiveLibraryIf rootLibrary = united_nations_db.getRoot();
// create a library
XhiveLibraryIf newLibA = rootLibrary.createLibrary();
// give the new library a name
newLibA.setName("Publications");
// append the new library to its parent
rootLibrary.appendChild(newLibA);
// create a library which is a sublibrary of newLibA
XhiveLibraryIf newLibA1 = newLibA.createLibrary();
// give the new library a name
newLibA1.setName("General Info");
// append the new library to its parent
newLibA.appendChild(newLibA1);
The created library hierarchy looks like this:

Note:
Although naming a library is optional, it is strongly recommended as several access and indexing methods only work with named libraries.See also:
To import an XML document from an external source, the XML document needs to be parsed. You can parse documents using the parseURI method of the DOM Load/ Save LSParser interface.
The XhiveLibraryIf interface extends DOMImplementationLS, which can be used to create LSParser and LSSerializer objects. You must create LSParsers on the library where you want to store the document.
When parsing succeeds, a DOM Document is returned.
LSParser builder = rootLibrary.createLSParser(); Document firstDocument = builder.parseURI( new File(fileName).toURL().toString());
To store a parsed document in the database, you also need to perform an explicit appendChild. Otherwise, the document is only parsed and not stored. See the Store XML documents section for more information on storing documents.
The parse documents sample uses the default LSParser configuration settings. Section Using DOM configuration provides more information on builder configuration options and how to change them.
For more documentation, see the Load/ Save specification.
See also:
Validation consists of two main steps:
The document is validated.
The DTD/ XML Schema information is stored in the catalog as an abstract schema.
As described in the catalog section, each time a document is validated, the application checks whether a abstract schema with the PUBLIC id of that document for DTDs, or the XML Schema with the namespace and file id, is already in the catalog. If so, the validation process uses this abstract schema instead of the external DTD. However, setting LSParser configuration parameter 'xhive-ignore-catalog' to true during parsing overrides catalog checking and always creates a new abstract schema for each document being validated. This is an important note, if there is only a system ID referring to a DTD, and you parse with validation, then a DTD is stored for every document you parse (this does not happen for XML Schemas)! By setting configuration parameter 'xhive-store-schema' to false it is possible to parse with validation without storing the schema
The 'validate' configuration parameter default value is false. Therefore, to parse a file with validation, you need to set this parameter:
LSParser parser = charterLib.createLSParser();
parser.getDomConfig().setParameter("validate", Boolean.TRUE);
Document firstDocument = parser.parseURI( new File(fileName).toURL().toString());
The parsed document contains a reference to a DTD. This DTD is stored as an ASModel within the catalog of the library on which the document is parsed.
The XhiveCatalogIf interface (in the com.xhive.dom.interfaces package) contains several methods for updating and querying the abstract schema models stored:
// retrieve the catalog of the "UN Charter" library
XhiveCatalogIf unCharterCatalog = charterLib.getCatalog();
// get the abstract schema models that exist in the root library catalog
Iterator iter = unCharterCatalog.getASModels();
ASModel asModel;
while ( iter.hasNext() ) {
asModel = (ASModel)iter.next();
System.out.println(" asModel = " + asModel.getLocation());
}
See also:
To store XML documents in an
appendChild() method. Before you can use the appendChild() method, you need to get a handle to the library where the document should be stored. Every database has a root library by default. To store a document in the root library of the sample database, you could use the following code:
XhiveLibraryIf rootLibrary = united_nations_db.getRoot(); rootLibrary.appendChild(firstDocument);
Alternatively, you can store a document using the insertBefore() method, which is also a standard DOM method. The second parameter to specify with insertBefore() is the document in front of which you want to insert the new document:
rootLibrary.insertBefore(secondDocument, firstDocument);
See also:
The DOM level 3 DOMConfiguration interface is used to set configuration
settings. XhiveDocumentIf, LSParser and LSSerializer objects each
have their own configuration object.
DOMConfiguration can be used to set boolean parameters like "validate",
"namespaces" and "cdata-sections". Furthermore, the configuration can be used to set
string parameters like "schema-location" and user object parameters like
error-handler.
The boolean configuration settings and string parameters of a document are stored in the database.
These settings are used by XhiveDocumentIf function normalizeDocument.
The complete list of options can be found in the JavaDOC documentation of DOMConfiguration,
and getDomConfig() of LSParser and LSSerializer (all linked below).
the following piece of code shows how to set a boolean parameter and user object parameter on the document configuration:
XhiveDocumentIf document = (XhiveDocumentIf) builder.parseURI(new File(fileName).toURL().toString());
DOMConfiguration config = document.getDomConfig();
config.setParameter("validate", Boolean.TRUE);
config.setParameter("error-handler", new SimpleDOMErrorPrinter());
In
config.canSetParameter("validate", Boolean.TRUE);
According to the specification, LSParser default value of boolean parameter
"element-content-whitespace" is "Boolean.TRUE". Documents parsed with this setting and
stored in
LSParser default value of this setting is set to
"Boolean.FALSE"
LSParser and/or
Document.
| Parameter name | Purpose | Value type | Supported by interface |
|---|---|---|---|
"xhive-ignore-catalog" | During validated parsing, the corresponding DTD's and XML schemas in the catalog are ignored. | XhiveDocumentIf, LSParser | Boolean.FALSE |
"xhive-store-schema" | During validated parsing, the corresponding DTD's or XML schemas are stored in the catalog. | XhiveDocumentIf, LSParser | is equal to the value of parameter "validate" but this value can but can be overridden
after setting parameter "validate". |
"xhive-psvi" | Store psvi information on elements and attributes. Documents parsed with this feature turned on, give access to psvi information and enable support of data types by XQuery queries. | LSParser | Boolean.FALSE |
"xhive-store-schema-only-internal-subset" | Store only the internal subset of the document (not any external subset).
Modifier for xhive-store-schema (only has a function when that parameter is set to true,
and when DTDs are involved).
Use this option if you only want to
store the internal subset of the document (not the external subset). | LSParser | Boolean.FALSE |
"xhive-sync-features" | Convenience setting. With this setting turned on, parameter settings of XhiveDocumentIf are
synchronized with the parameter settings of LSParser. Note that parameter settings
"xhive-psvi" and "schema-location" are always synchronized.
| LSParser | Boolean.FALSE |
"xhive-schema-ids" | Identification of XML schema ids used by the document. | readonly parameter of XhiveDocumentIf. It is not supported. | null |
See also:
You can use function parseWithContext on LSParser to parse complete documents.
LSParser parser = charterLib.createLSParser();
// Using null, null, null as arguments here means the document will be completely empty
Document document = charterLib.createDocument(null, null, null);
// Other actions on document...
LSInput source = charterLib.createLSInput();
source.setSystemId("file:///c:/docs/document.xml");
parser.parseWithContext(source, document, LSParser.ACTION_REPLACE);This involves more code than a simple parse, but has the advantage that you can first create the documents, then set the indexes on them (at the 'other actions on document' line), and then parse the data on it. Especially for large documents, there may be some performance gained if you index the document during parsing.
See also:
BLOBs are stored in
createBlob() creates a BLOB node. After creating a BLOB node, the content of the node must be filled through the setContents() method. To actually add the BLOB node, the normal methods for adding nodes can be used: appendChild() or insertBefore():
String imgFileName = "un_flags.gif"; String imgName = "Flags of UN members"; FileInputStream imgFile = new FileInputStream(SampleProperties.baseDir + imgFileName) // create BLOB node XhiveBlobNodeIf img = charterLib.createBlob(); // set the contents and name of the BLOB node img.setContents(imgFile); img.setName(imgName); // append the BLOB node to the library charterLib.appendChild(img);
BLOBs stored in
getContents()
method in XhiveBlobNodeIf. This method returns an InputStream.
The getSize() method returns the size of the BLOB in bytes:
// retrieve the contents of the BLOB node InputStream in = img.getContents(); // retrieve the size of the BLOB node int imgSize = (int)img.getSize();
A FileOutputStream can be used to output the contents of the BLOB node to a file:
// output the image to a new file
FileOutputStream out = new FileOutputStream(SampleProperties.baseDir + "copy_of_" + imgFileName);
byte[] buffer = new byte[imgSize];
int length;
while((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
in.close();
When iterating over the child nodes of a library, BLOB nodes can be distinguished from other
nodes by their node type which is XhiveNodeIf.BLOB_NODE:
Node n = charterLib.getFirstChild();
while (n != null) {
if (n instanceof XhiveBlobNodeIf) {
System.out.println( "BLOB node found: " + ((XhiveLibraryChildIf)n).getName());
}
n = n.getNextSibling();
}
See also:
com.xhive.util.interfaces.XhiveSqlLoaderIf interface contains the methods used for importing non-XML data. For a detailed specification of these methods, refer to the XhiveSqlLoaderIf Javadoc.
In this example, data is imported in CSV format into
The data to import looks like this:
"Member", "Date of Admission", "Additional Notes" "Iceland", 19 Nov. 1946, "" "India", 30 Oct. 1945, "" "Indonesia", 28 Sep. 1950, "By letter of 20 January ..." "Iran (Islamic Republic of)", 24 Oct. 1945, ""
You can import the data with an XhiveSqlLoaderIf object, using the loadSqlData() method:
Document un_members_doc = loader.loadSqlData(Impl,
FileName,
',',
'\\',
'"',
true,
"UN_members",
XhiveSqlLoaderIf.IGNORE_HEADER,
"member",
new String[] {"name","admission_date","additional_note"},
new boolean[] {false, false, false});
This command specifies the following information:
The DOM implementation used: Impl.
File name: variable FileName.
Separator: ,
Escape character: \
Encloser: ". The encloser is the character that specifies the start and end of a string.
Column names: true. This specifies that the first row in the data file gives column names
and not data.
Document element name: UN_members. This specifies the name of the root element.
Mode: IGNORE_HEADER. This specifies that column headers are not used as element names.
Row element name: member. This is the name of the element used to enclose each row.
Column element names: new String[] {"name", "admission_date", "additional_note"}. This specifies the names to use for each of the elements.
Column element ignore: new boolean[] {false, false, false});. This specifies whether to ignore (that is, not import) columns.
This command produces the following XML:
<UN_members>
<member>
<name>Iceland</name>
<admission_date>19 Nov. 1946</admission_date>
<additional_note></additional_note>
</member>
<member>
<name>India</name>
<admission_date>30 Oct. 1945</admission_date>
<additional_note></additional_note>
</member>
<member>
<name>Indonesia</name>
<admission_date>28 Sep. 1950</admission_date>
<additional_note>By letter of 20 January 1965...</additional_note>
</member>
<member>
<name>Iran (Islamic Republic of)</name>
<admission_date>24 Oct. 1945</admission_date>
<additional_note></additional_note>
</member>
</UN_members>
In a similar way, you can use the loadSqlData() method to import data from a JDBC-compliant relational database. See the API documentation for more details.
The loadSqlData() method has several variations. See the API documentation for all the possible parameters.
See also: