frames / elegant design

X-Hive/DB 8.0 - Manual

release 8.0.1 - November 14 2007

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Copyright © 2007  X-Hive Corporation B.V. ®, All Rights Reserved.

Rights to the content of this publication
This publication contains proprietary information belonging to X-Hive Corporation. It may not be reproduced without written permission.

Trademarks
X-Hive and X-Hive/DB are registered trademarks of X-Hive Corporation. All other company or product names used in this publication are trademarks of their respective owners.

X-Hive/DB includes software developed by the Apache Software Foundation (http://www.apache.org).

Table of Contents

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 X-Hive/DB
    2.3 Creating a database
    2.4 Running a sample
3 General information
    3.1 What is X-Hive/DB?
    3.2 The technology behind X-Hive/DB
        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 X-Hive/DB logical architecture
        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 X-Hive/DB
    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 X-Hive/DB
    4.7 Configuring the xhive.bootstrap property
    4.8 Using the Java command line instead of xhive-ant
    4.9 The X-Hive/DB dedicated server process
        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 X-Hive/DB behavior when a locking conflict occurs
        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 X-Hive/DB
    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 X-Hive/DB
    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 X-Hive/DB's Ant tasks:
    14.4 X-Hive/DB's Ant Types:
    14.5 X-Hive/DB Ant Types Reference:
        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 X-Hive/DB's Ant Types:
    14.7 X-Hive/DB's Ant Tasks:
        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

Appendix

1 Introduction

1.3 How is this manual structured?

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 X-Hive/DB.

Quickstart gives you an overview of the essential steps you need to perform to install and set up X-Hive/DB on your system. It gives you enough information to reach a point where you have installed X-Hive/DB, created your first database, and learned how to use the sample files provided with the product. These sample files illustrate the key concepts of X-Hive/DB functionality.

General information describes the architecture of X-Hive/DB, and provides information on the concepts that you need to understand when using the product. These concepts cover both XML in general and specific issues that relate to X-Hive/DB.

Installing X-Hive/DB gives instructions on how to prepare your system for installing the product, and describes the actions you need to perform when running the installation program.

Creating applications gives you instructions on how to develop X-Hive/DB applications, moving from basic tasks such as programming a transaction to advanced techniques such as using versioning, XLink and content models.

Using Sessions (and Locking) explains in detail the features and issues of the X-Hive/DB transaction model.

Using XQuery explains in detail how to use XQuery within X-Hive/DB.

Using Indexes describes how you can use one of X-Hive/DB's indexing methods to enhance the performance of your X-Hive/DB application.

Using the Catalog and DTDs describes how X-Hive/DB deals with DTDs.

Internal Structure of X-Hive/DB gives advanced information on the physical data-structure of X-Hive/DB.

Administering X-Hive/DB describes the tasks you need to perform as a database administrator in X-Hive/DB. The information provided includes basic tasks such as creating users, and also deals with more advanced topics such as backing up a database.

1.6 Support and feedback

X-Hive Corporation provides both telephone and e-mail technical support.

We appreciate your feedback on this manual, and on any aspect of the X-Hive/DB product. You can send your feedback by e-mail to product_strategy@x-hive.com.

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.

2 Quickstart

This section aims to get you started quickly with X-Hive/DB. It covers all the steps necessary to get X-Hive/DB running, from installation to creating a database to running your first sample. For more detailed information, consult the chapter Installing X-Hive/DB.

2.2 Installing X-Hive/DB

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 X-Hive/DB running, ensure you uninstall them in the proper way or choose other directories and port-numbers. For more information, see the Uninstalling X-Hive/DB section.

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 X-Hive/DB program under any account.

3 General information

3.2 The technology behind X-Hive/DB

This section introduces the following technical aspects of X-Hive/DB:

3.2.2 Searching, linking and indexing

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. X-Hive/DB includes an XQuery query engine implementation. For information on using XQuery, see Using XQuery.

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 X-Hive/DB applications. X-Hive/DB supports several different indexing methods: Context Conditioned Indexing, library id and library name indexing, id attribute indexing, element name indexing, value indexing and full text indexing.

3.2.4 Administration features

The administration features of X-Hive/DB enable the X-Hive/DB administrator to manage user and user group permissions for access to documents and queries. An administration tool (a.k.a. 'the adminclient') provides access to the administration features and also includes a data browser that displays the contents of the X-Hive/DB database using a tree-view. The administration features are also accessible through the API.

3.2.7 Versioning

X-Hive/DB provides linear versioning with branches. This feature enables the storage of multiple (older) versions of a document within the context of the document. Storing multiple versions of a document makes it easier to keep track of the changes in a document and to restore older versions when needed.

3.3 X-Hive/DB logical architecture

This section describes the logical architecture of X-Hive/DB. For an overview of the internal architecture of X-Hive/DB, go to the Internal X-Hive/DB architecture section.

The following diagram provides an overview of the logical architecture of X-Hive/DB:


      <nobr>
      <nobr>X-Hive/DB</nobr></nobr>'s logical architecture
Figure 1. X-Hive/DB's logical architecture

4 Installing X-Hive/DB

4.1 Installation requirements

Before running the installation program, you need to perform both checks and tasks to ensure that the installation is successful.

4.2 Installation - Windows

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 - X-Hive/DB is then ready for use.

4.2.1 Run the installation program

On Windows, the installation program you need to run is called setup.exe, located in the root directory of the X-Hive/DB CD or distribution file. Besides installing the files in the proper directories, your PATH environment variable is augmented. If you have previous versions of X-Hive/DB running, ensure you uninstall them in the proper way. For information on uninstalling X-Hive/DB, see the Uninstalling X-Hive/DB section.

When you run setup.exe, the installation process begins.

Figure 2.

You simply need to follow the instructions on screen to complete the installation. The installation program requires your input for the following steps:

  1. Accept the software license agreement. If you do not accept the license agreement, the installation is terminated.

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

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

    Figure 5.
  4. Enter the license key you received for the product. Note that there is a time limit on the validity of X-Hive software licenses. If in doubt about your license, contact X-Hive customer support.

    Figure 6.
  5. Specify the password of the super user. This password is later needed to create databases with X-Hive/DB and perform other super user tasks.

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

    Figure 8.

    If you proceed with a standard installation, the program files for X-Hive/DB are now installed on your host machine. If you proceed with an advanced installation, your input is needed for the following two additional steps.

  7. 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 X-Hive/DB 5, that makes a bigger difference then in previous X-Hive/DB versions).

    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.

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

    • The server can run on any port. A check is made whether the port is available. The port-number does determine what 'url' you have to use later to access the database.
    • The cache size determines the amount of pages cached by the server to speed up performance. You generally do not want to make this amount smaller, but if memory permits you can make it larger to improve performance.
    • By default, only processes running on the same machine can access the server for security reasons. If you want to have processes on multiple machines access the database, you can choose here to allow it here.
    Figure 10.
  9. 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.

    Figure 11.

After successful installation of X-Hive/DB, the installation program displays a message confirming that the installation completed without errors.

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).

4.3 Installation - UNIX

On UNIX platforms you can install X-Hive/DB as any user. Installation consists of three steps:

  1. Starting the installation.

  2. Entering installation parameters.

  3. Performing post-installation steps.

4.3.2 Entering installation parameters

After the installation files have been copied, you need to enter a number of parameters needed during installation. The format for these questions is:

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 X-Hive/DB license key.

  • You need a super-user password to administer X-Hive/DB databases. Note that this password needs to be typed twice and is displayed in clear text.

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:

4.4 Verify the installation

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 X-Hive/DB API. More information on each command can be found by running them without any parameters. Additional commands are described in the administration sections.

Important X-Hive/DB commands
XHAdmin Graphical administration client, for maintaining databases, users and content.
xhive-antCompile and run the samples, as well as other programs.
XHCreateDBCreate a new database.
XHDeleteDBRemove an existing database.
XHCreateFDCreate a new empty federation
XHInstallFDSet the superuser password and/ or license key on a federation.
XHBackupBackup a federation to a backup file
XHRestoreRestore a federation from a backup file
XHSessionInfoShows debug information on currently open transactions and their locks
XHServerStart or Shutdown a server process for a specific federation
XHStartServerStart the dedicated background server process for the default federation
XHStopServerStop the dedicated background server process for the default federation
XHCreateReplicaCreate a full replica (optionally including registering a replica id for it) of a federation at a given location.
XHSuspendDiskWritesEnsure the federation files are flushed to disk and suspend (or resume) writing to them

4.9 The X-Hive/DB dedicated server process

When you have installed X-Hive/DB, the system is configured to run with a dedicated page server that runs as a background process and to which other applications that want to access the database can connect.

It is important to realize that this process is not a required part for the X-Hive/DB architecture. Java applications could also access the database directly through the bootstrap file without making any network connection. However, when accessing database files directly, no other processes (including the dedicated server described here) may be accessing the database at the same time (but that does not need to be a problem, as long as the 'main application' starts a listener thread for other applications to connect to, see below).

What is also important to realize is that the server program is a very small Java program, accessing the X-Hive/DB API like any X-Hive/DB application you would write yourself. There are some different configuration possibilities, but apart from those options and the processing of the passed parameters the whole server process is essentially these five lines:

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 X-Hive/DB with a separate dedicated server such as configured after installation is not actually the best configuration for performance. The reason that it is configured by default with a separate server is because we feel that is is the more convenient way to get started, but for production applications where performance is essential it is a poor choice.

4.9.1 Configuration of the server

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 X-Hive/DB for use without a server, you have to:

  • Use FullPath/XhiveDatabase.bootstrap instead of xhive://hostname:portname as the bootstrap path in your application.
  • Stop the server (since only one process is allowed access to the federation). On Unix, the server is simply not started if you don't run it. On Windows you may want to uninstall the service alltogether by running the commands
    net stop xhive-server
    instsrv xhive-server remove
    (Should you ever want to reinstall the service, you can run the commands
    wrapper -i wrapper.conf        (run from XhiveDir\bin)
    net start xhive-server
    )

5 Creating applications

5.2 Create a database

When you install X-Hive/DB on a system, one database, called a federated database, is created by default. This federated database acts as a holder for one or more "regular" X-Hive/DB databases. The federated database also contains super user information. For more information on X-Hive/DB architecture, see the X-Hive/DB architecture section.

As an X-Hive/DB user, you can choose to create as many "regular" databases as you need. You can create a database in X-Hive/DB using any of the following means:

  • The command-line utility XHCreateDB.

  • The adminclient.

  • The Application Programming Interface (API) functions.

5.2.3 Creating a database using API functions

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:

  1. Start a session and open a connection to the database as super user. The databaseName parameter of the connect() call should be null:

  2. Get a handle to the database federation:

  3. 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):

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:

samples:

API documentation:

5.4 Use sessions and transactions

There is also a separate chapter with background information on sessions.

In X-Hive/DB all operations to databases take place within a session. The developer can determine the scope of a session.

To create a session in X-Hive/DB:

  1. Establish a connection to the database, as described in the Connect to the database section.

  2. 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 X-Hive/DB do the following:

  1. Start the transaction with the begin() method of com.xhive.core.interfaces.XhiveSessionIf.

  2. Enter the instructions you want executed during the transaction.

  3. 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(), X-Hive/DB offers an alternative method, called 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();
will not execute. You will get a 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 X-Hive/DB server. If you do not call terminate(), the TCP connection will be closed when the session is finalized after it has been garbage collected.

See also:

samples:

API documentation:

5.5 Create libraries

In X-Hive/DB, a library is a 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 X-Hive/DB is very similar to the nested structure of directories or folders within your file system: any library can contain other libraries and there is exactly one root library. The root library is automatically created when the database is created but otherwise behaves like an ordinary library.

To create a library, perform the following steps:

  1. 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.

  2. Create the library using the createLibrary() method.

  3. Give the new library a unique name using the setName() method (optional).

  4. 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.

The created library hierarchy looks like this:

See also:

samples:

API documentation:

5.7 Validate XML documents

Validation consists of two main steps:

  1. The document is validated.

  2. 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:

samples:

API documentation:

5.9 DOM configuration settings

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:

In X-Hive/DB, the default configuration settings conform to the default settings as defined by the DOM level 3 Core Specification and the Load/ Save Specification. A parameter is supported if it can be set to another value. The following piece of code shows how to test if a boolean parameter value is supported by a configuration:

config.canSetParameter("validate", Boolean.TRUE);
The following section shows deviations to the default values and additional X-Hive/DB specific settings.

5.9.2 Additional parameters

X-Hive/DB has added a number of parameters that can used by the LSParser and/or Document.

Parameter namePurposeValue typeSupported by interface
"xhive-ignore-catalog"During validated parsing, the corresponding DTD's and XML schemas in the catalog are ignored.XhiveDocumentIf, LSParserBoolean.FALSE
"xhive-store-schema"During validated parsing, the corresponding DTD's or XML schemas are stored in the catalog.XhiveDocumentIf, LSParseris 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.LSParserBoolean.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).LSParserBoolean.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. LSParserBoolean.FALSE
"xhive-schema-ids"Identification of XML schema ids used by the document.readonly parameter of XhiveDocumentIf. It is not supported.null

See also:

samples:

API documentation:

5.11 Store BLOBs

X-Hive/DB enables the storage of Binary Large OBjects (BLOBs) within a database. Examples of BLOBs are: image files (GIF, JPEG, PNG, BMP etc.), sound files (MP3, WAV etc.) and Microsoft Office files (DOC, XLS, PPT etc.). The advantage of storing BLOBs next to XML documents within X-Hive/DB is the fact that this allows the management of all resources for a specific project or product in one uniform way.

BLOBs are stored in X-Hive/DB as a special type of node, the BLOB node. The method 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():

BLOBs stored in X-Hive/DB can be retrieved using the getContents() method in XhiveBlobNodeIf. This method returns an InputStream. The getSize() method returns the size of the BLOB in bytes:

A FileOutputStream can be used to output the contents of the BLOB node to a file:

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:

See also:

samples:

API documentation:

5.12 Import non-XML data

X-Hive/DB can import data from non-XML files, provided you supply information on how the data fields are separated and arranged in the source file. The 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 X-Hive/DB, and stored as an XML document.

The data to import looks like this:

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:

samples:

API documentation: