deegree 2.5 (2011/06/29 09:44 build-8-official)

org.deegree.io.dbaseapi
Class DBaseIndex

java.lang.Object
  extended by org.deegree.io.dbaseapi.DBaseIndex

public class DBaseIndex
extends java.lang.Object

A class for reading from and writing to DBase index files (*.ndx), maybe not 100% xbase compatible!

The fileformat is described at http://www.e-bachmann.dk/computing/databases/xbase/index.html

This index is suitable for indexing both unique and non-unique columns. Unique indexing is much faster than non-unique because it use a faster algorithm.

The index file is a B+tree (sometimes called a paged B-tree) that consist of pages. There are two page types, leaves and non-leafs. The starting page (eg. the page the search algorithm starts) is the root page.

Searching goes as follows:

Above algorithm is implemented in two different methods, one for unique indexes and one for non-unique indexes. Searching unique indexes is easier because the algorithm is finished as soon as it has found a key, the non-unique version of the algorithm has to find all keys present in the index.

Inserting goes as follows:

If a page that splits does not have a parent page then a new page is created. This page is the new starting page

Handling different data types: The index can handle strings and numbers. Numbers are always stored als IEEE doubles. The method addKey checks the given key and throws an exception if the datatype of the key doesn't suit the index

Author:
Reijer Copier, email: reijer.copier@idgis.nl

Nested Class Summary
 class DBaseIndex.Cache
          Inner class for the cache.
 
Field Summary
protected  byte[] b
           
protected  int cacheSize
           
protected  java.io.RandomAccessFile file
           
protected  byte[] keyBytes
           
protected  int keyLength
           
protected  int keyType
           
protected  int noOfKeysPerPage
           
protected  int numberOfPages
           
protected  byte[] page
           
protected  int sizeOfKeyRecord
           
protected  int startingPageNo
           
 
Constructor Summary
DBaseIndex(java.lang.String name)
          Open an existing .ndx file
 
Method Summary
 void addKey(java.lang.Comparable key, int record)
          Add a key to the index
 void close()
          Close the index file
static DBaseIndex createIndex(java.lang.String name, java.lang.String column, int keyLength, boolean uniqueFlag, boolean numbers)
          Create a new index
 void flush()
          Flush all the buffers
 int getDepth()
          Calculate the depth for the index
protected  org.deegree.io.dbaseapi.DBaseIndex.Page getPage(int number)
          Get a page
 boolean isUnique()
          Contains this index unique values?
protected  org.deegree.io.dbaseapi.DBaseIndex.Page newPage()
          Create a new page
 int[] search(java.lang.Comparable key)
           
protected  void setRoot(org.deegree.io.dbaseapi.DBaseIndex.Page page)
          Set the root page
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

file

protected java.io.RandomAccessFile file

startingPageNo

protected int startingPageNo

numberOfPages

protected int numberOfPages

sizeOfKeyRecord

protected int sizeOfKeyRecord

keyLength

protected int keyLength

noOfKeysPerPage

protected int noOfKeysPerPage

keyType

protected int keyType

b

protected byte[] b

page

protected byte[] page

keyBytes

protected byte[] keyBytes

cacheSize

protected int cacheSize
Constructor Detail

DBaseIndex

public DBaseIndex(java.lang.String name)
           throws java.io.IOException
Open an existing .ndx file

Throws:
java.io.IOException
Method Detail

getPage

protected org.deegree.io.dbaseapi.DBaseIndex.Page getPage(int number)
                                                   throws java.io.IOException
Get a page

Throws:
java.io.IOException

newPage

protected org.deegree.io.dbaseapi.DBaseIndex.Page newPage()
                                                   throws java.io.IOException
Create a new page

Throws:
java.io.IOException

setRoot

protected void setRoot(org.deegree.io.dbaseapi.DBaseIndex.Page page)
Set the root page


createIndex

public static DBaseIndex createIndex(java.lang.String name,
                                     java.lang.String column,
                                     int keyLength,
                                     boolean uniqueFlag,
                                     boolean numbers)
                              throws java.io.IOException
Create a new index

Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flush all the buffers

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close the index file

Throws:
java.io.IOException

search

public int[] search(java.lang.Comparable key)
             throws java.io.IOException,
                    KeyNotFoundException,
                    InvalidKeyTypeException
Throws:
java.io.IOException
KeyNotFoundException
InvalidKeyTypeException

addKey

public void addKey(java.lang.Comparable key,
                   int record)
            throws java.io.IOException,
                   KeyAlreadyExistException,
                   InvalidKeyTypeException,
                   KeyTooLongException
Add a key to the index

Throws:
java.io.IOException
KeyAlreadyExistException
InvalidKeyTypeException
KeyTooLongException

getDepth

public int getDepth()
             throws java.io.IOException
Calculate the depth for the index

Throws:
java.io.IOException

isUnique

public boolean isUnique()
Contains this index unique values?


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

deegree 2.5 (2011/06/29 09:44 build-8-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org