org.basex.data
Class DiskData

java.lang.Object
  extended by org.basex.data.Data
      extended by org.basex.data.DiskData

public final class DiskData
extends Data

This class stores and organizes the node table and the index structures for textual content. All nodes in the table are accessed by their implicit pre value. Some restrictions on the data are currently given:

Each node occupies 128 bits. The current storage layout looks like follows:
 ELEMENT NODES:
 - Byte     0:  KIND: Node kind (ELEM)
 - Byte   1-2:  NSPC: Namespace (4), NS Definition flag (1) and Name (11 bits)
 - Byte     3:  ATTS: Number of attributes
 - Byte  4- 7:  DIST: Distance to parent node
 - Byte  8-11:  SIZE: Number of descendants
 - Byte 12-15:  UNID: Unique Node ID
 DOCUMENT NODES:
 - Byte     0:  KIND: Node kind (DOC)
 - Byte  3- 7:  TEXT: Text reference
 - Byte  8-11:  SIZE: Number of descendants
 - Byte 12-15:  UNID: Unique Node ID
 TEXT NODES:
 - Byte     0:  KIND: Node kind (TEXT/COMM/PI)
 - Byte  3- 7:  TEXT: Text reference
 - Byte  8-11:  DIST: Distance to parent node
 - Byte 12-15:  UNID: Unique Node ID
 ATTRIBUTE NODES:
 - Byte     0:  KIND: Node kind (ATTR)
 - Byte   1-2:  NSPC: Namespace (4) and Name (11 bits)
 - Byte  3- 7:  TEXT: Attribute value reference
 - Byte    11:  DIST: Distance to parent node
 - Byte 12-15:  UNID: Unique Node ID
 

Author:
Workgroup DBIS, University of Konstanz 2005-08, ISC License, Christian Gruen, Tim Petrowsky

Field Summary
 
Fields inherited from class org.basex.data.Data
ATTR, atts, COMM, DOC, ELEM, fs, meta, nameID, ns, PI, size, sizeID, skel, tags, TEXT
 
Constructor Summary
DiskData(java.lang.String db)
          Default Constructor.
DiskData(java.lang.String db, boolean index)
          Constructor, specifying if indexes are to be opened as well.
 
Method Summary
 int attLen(int pre)
          Returns an attribute value length.
 int attNameID(int pre)
          Returns an attribute name id (reference to the attribute name index).
 int attNS(int pre)
          Returns an attribute namespace (reference to the attribute namespace).
 double attNum(int pre)
          Returns an attribute value as double value.
 int attSize(int pre, int kind)
          Returns a number of attributes.
 byte[] attValue(int pre)
          Returns an attribute value.
 void close()
          Closes the current database.
 void closeIndex(IndexToken.Type index)
          Closes the specified index.
 void cls()
          Closes the database without writing data back to disk.
 void delete(int pre)
          Deletes a node and its descendants.
 void flush()
          Flushes the table data.
 int id(int pre)
          Returns a unique node id.
 void insert(int pre, int par, byte[] name, byte[] val)
          Inserts an attribute.
 void insert(int pre, int par, byte[] val, int kind)
          Inserts a tag name, text node, comment or processing instruction.
 void insert(int pre, int par, Data dt)
          Insert a data instance at the specified pre value.
 int kind(int pre)
          Returns a node kind.
 int[] ns(int pre)
          Returns namespace key and value ids.
 int parent(int pre, int kind)
          Returns a pre value of the parent node.
 int pre(int id)
          Returns a pre value.
 void setIndex(IndexToken.Type type, Index index)
          Assigns the specified index.
 int size(int pre, int k)
          Returns a size value (number of descendant table entries).
 int tagID(int pre)
          Returns a tag id (reference to the tag index).
 int tagNS(int pre)
          Returns a tag namespace (reference to the tag namespace).
 byte[] text(int pre)
          Returns a text.
 int textLen(int pre)
          Returns a text length.
 double textNum(int pre)
          Returns a text as double value.
 void update(int pre, byte[] val)
          Updates a tag name, text node, comment or processing instruction.
 void update(int pre, byte[] name, byte[] val)
          Updates an attribute name and value.
 
Methods inherited from class org.basex.data.Data
atom, atomNum, attName, attNameID, attValue, doc, ids, info, initNames, nrIDs, tag, tagID, update
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiskData

public DiskData(java.lang.String db)
         throws java.io.IOException
Default Constructor.

Parameters:
db - name of database
Throws:
java.io.IOException - IO Exception

DiskData

public DiskData(java.lang.String db,
                boolean index)
         throws java.io.IOException
Constructor, specifying if indexes are to be opened as well.

Parameters:
db - name of database
index - open indexes
Throws:
java.io.IOException - IO Exception
Method Detail

flush

public void flush()
Description copied from class: Data
Flushes the table data.

Specified by:
flush in class Data

close

public void close()
           throws java.io.IOException
Description copied from class: Data
Closes the current database.

Specified by:
close in class Data
Throws:
java.io.IOException - in case the database could not be closed

cls

public void cls()
         throws java.io.IOException
Closes the database without writing data back to disk.

Throws:
java.io.IOException - I/O exception

closeIndex

public void closeIndex(IndexToken.Type index)
                throws java.io.IOException
Description copied from class: Data
Closes the specified index.

Specified by:
closeIndex in class Data
Parameters:
index - index to be closed
Throws:
java.io.IOException - in case the index could not be closed

setIndex

public void setIndex(IndexToken.Type type,
                     Index index)
Description copied from class: Data
Assigns the specified index.

Specified by:
setIndex in class Data
Parameters:
type - index to be opened
index - index instance

id

public int id(int pre)
Description copied from class: Data
Returns a unique node id.

Specified by:
id in class Data
Parameters:
pre - pre value
Returns:
node id

pre

public int pre(int id)
Description copied from class: Data
Returns a pre value.

Specified by:
pre in class Data
Parameters:
id - unique node id
Returns:
pre value or -1 if id was not found

kind

public int kind(int pre)
Description copied from class: Data
Returns a node kind.

Specified by:
kind in class Data
Parameters:
pre - pre value
Returns:
node kind

parent

public int parent(int pre,
                  int kind)
Description copied from class: Data
Returns a pre value of the parent node.

Specified by:
parent in class Data
Parameters:
pre - pre value
kind - node kind
Returns:
pre value of the parent node

attSize

public int attSize(int pre,
                   int kind)
Description copied from class: Data
Returns a number of attributes.

Specified by:
attSize in class Data
Parameters:
pre - pre value
kind - node kind
Returns:
number of attributes

size

public int size(int pre,
                int k)
Description copied from class: Data
Returns a size value (number of descendant table entries).

Specified by:
size in class Data
Parameters:
pre - pre value
k - node kind
Returns:
size value

tagID

public int tagID(int pre)
Description copied from class: Data
Returns a tag id (reference to the tag index).

Specified by:
tagID in class Data
Parameters:
pre - pre value
Returns:
token reference

tagNS

public int tagNS(int pre)
Description copied from class: Data
Returns a tag namespace (reference to the tag namespace).

Specified by:
tagNS in class Data
Parameters:
pre - pre value
Returns:
token reference

ns

public int[] ns(int pre)
Description copied from class: Data
Returns namespace key and value ids.

Specified by:
ns in class Data
Parameters:
pre - pre value
Returns:
key and value ids

attNameID

public int attNameID(int pre)
Description copied from class: Data
Returns an attribute name id (reference to the attribute name index).

Specified by:
attNameID in class Data
Parameters:
pre - pre value
Returns:
token reference

attNS

public int attNS(int pre)
Description copied from class: Data
Returns an attribute namespace (reference to the attribute namespace).

Specified by:
attNS in class Data
Parameters:
pre - pre value
Returns:
token reference

text

public byte[] text(int pre)
Description copied from class: Data
Returns a text.

Specified by:
text in class Data
Parameters:
pre - pre value
Returns:
atomized value

attValue

public byte[] attValue(int pre)
Description copied from class: Data
Returns an attribute value.

Specified by:
attValue in class Data
Parameters:
pre - pre value
Returns:
atomized value

textNum

public double textNum(int pre)
Description copied from class: Data
Returns a text as double value.

Specified by:
textNum in class Data
Parameters:
pre - pre value
Returns:
numeric value

attNum

public double attNum(int pre)
Description copied from class: Data
Returns an attribute value as double value.

Specified by:
attNum in class Data
Parameters:
pre - pre value
Returns:
numeric value

textLen

public int textLen(int pre)
Description copied from class: Data
Returns a text length.

Specified by:
textLen in class Data
Parameters:
pre - pre value
Returns:
length

attLen

public int attLen(int pre)
Description copied from class: Data
Returns an attribute value length.

Specified by:
attLen in class Data
Parameters:
pre - pre value
Returns:
length

update

public void update(int pre,
                   byte[] val)
Description copied from class: Data
Updates a tag name, text node, comment or processing instruction.

Specified by:
update in class Data
Parameters:
pre - pre of the text node to change
val - value to be updated

update

public void update(int pre,
                   byte[] name,
                   byte[] val)
Description copied from class: Data
Updates an attribute name and value.

Specified by:
update in class Data
Parameters:
pre - pre of node to insert after
name - attribute name
val - attribute value

delete

public void delete(int pre)
Description copied from class: Data
Deletes a node and its descendants.

Specified by:
delete in class Data
Parameters:
pre - pre value of the node to delete

insert

public void insert(int pre,
                   int par,
                   byte[] val,
                   int kind)
Description copied from class: Data
Inserts a tag name, text node, comment or processing instruction.

Specified by:
insert in class Data
Parameters:
pre - pre value
par - parent of node
val - value to be inserted
kind - node kind

insert

public void insert(int pre,
                   int par,
                   byte[] name,
                   byte[] val)
Description copied from class: Data
Inserts an attribute.

Specified by:
insert in class Data
Parameters:
pre - pre value
par - parent of node
name - attribute name
val - attribute value

insert

public void insert(int pre,
                   int par,
                   Data dt)
Description copied from class: Data
Insert a data instance at the specified pre value. Note that the specified data instance must differ from this instance.

Specified by:
insert in class Data
Parameters:
pre - pre value
par - parent of node
dt - data instance to copy from