Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.basex.data
Class Data

    java.lang.Object
      org.basex.data.Data

Direct Known Subclasses:
  DiskData, MemData

    public abstract class Data

extends Object

This class provides access to the database storage. Note that the methods of this class are optimized for performance. They will not check if correct data is requested, i.e. if a text is requested, a pre value must points to a text node. All nodes in the table are accessed by their implicit pre value. The following restrictions are imposed on the data:

- The table is limited to 2^31 entries (pre values are signed int's)
- A maximum of 2^15 different tag and attribute names is allowed
- A maximum of 2^8 different namespaces is allowed
- A tag can have a maximum of 32 attributes

Each node occupies 128 bits. The current storage layout looks as follows:

     COMMON ATTRIBUTES:
     - Byte     0:  KIND: Node kind (2-0)
     ELEMENT NODES:
     - Byte     0:  ATTS: Number of attributes (7-3)
     - Byte   1-2:  NAME: Namespace Flag (15), Name (14-0)
     - Byte     3:  NURI: Namespace URI
     - 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  3- 7:  TEXT: Text reference
     - Byte  8-11:  SIZE: Number of descendants
     - Byte 12-15:  UNID: Unique Node ID
     TEXT, COMMENT, PI NODES:
     - 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:  DIST: Distance to parent node (7-3)
     - Byte   1-2:  NAME: Namespace Flag (15), Name (14-0)
     - Byte  3- 7:  TEXT: Attribute value reference
     - Byte    11:  NURI: Namespace (7-3)
     - Byte 12-15:  UNID: Unique Node ID

Author:
  Workgroup DBIS, University of Konstanz 2005-10, ISC License, Christian Gruen

Nested Class Summary
`static class` | `Data.Type` Index types.

Field Summary
`static byte` | `ATTR` Node kind: Attribute.
`Names` | `atts` Attribute name index.
`static byte` | `COMM` Node kind: Comment.
`static byte` | `DOC` Node kind: Document.
`static byte` | `ELEM` Node kind: Element.
`DeepFS` | `fs` File system reference.
`MetaData` | `meta` Meta data.
`int` | `nameID` Index Reference for name tag.
`Namespaces` | `ns` Namespace index.
`PathSummary` | `path` Path Summary.
`static byte` | `PI` Node kind: Processing Instruction.
`int` | `sizeID` Index References.
`Names` | `tags` Tag index.
`static byte` | `TEXT` Node kind: Text.

Constructor Summary
`Data()`

Method Summary
`byte[]` | `atom(int pre)` Returns an atomized content for any node kind.
`void` | `attr(int pre, int d, int tn, byte[] vl, int u, boolean ne)` Adds an attribute entry to the internal update buffer.
`int` | `attSize(int pre, int k)` Returns a number of attributes.
`void` | `buffer(int s)` Sets the update buffer to a new size.
`void` | `close()` Closes the current database.
`abstract void` | `closeIndex(Data.Type index)` Closes the specified index.
`void` | `delete(int pre)` Deletes a node and its descendants.
`int[]` | `doc()` Returns the document nodes.
`void` | `doc(int pre, int s, byte[] vl)` Adds a document entry to the internal update buffer.
`void` | `elem(int d, int tn, int as, int s, int u, boolean ne)` Adds an element entry to the internal update buffer.
`abstract void` | `flush()` Flushes the table data.
`int` | `id(int pre)` Returns a unique node id.
`IndexIterator` | `ids(IndexToken token)` Returns the indexed id references for the specified token.
`byte[]` | `info(Data.Type type)` Returns info on the specified index structure.
`void` | `init()` Dissolves the references to often used tag names and attributes.
`void` | `insert(int pre)` Inserts the internal buffer to the storage without updating the table structure.
`void` | `insert(int ipre, int ipar, MemData md)` Inserts a data instance at the specified pre value.
`void` | `insertAttr(int pre, int par, MemData dt)` Inserts attributes.
`int` | `kind(int pre)` Returns a node kind.
`int` | `name(int pre)` Returns a reference to the tag or attribute name id.
`byte[]` | `name(int pre, int k)` Returns a tag, attribute or pi name.
`int` | `nrIDs(IndexToken token)` Returns the number of indexed id references for the specified token.
`Atts` | `ns(int pre)` Returns namespace key and value ids.
`boolean` | `nsFlag(int pre)` Returns a namespace flag.
`int` | `parent(int pre, int k)` Returns a pre value of the parent node.
`int` | `pre(int id)` Returns a pre value.
`void` | `rename(int pre, int k, byte[] nm, byte[] uri)` Renames (updates) an element, attribute or pi name.
`void` | `replace(int pre, int k, byte[] val)` Replaces (updates) a text, comment, pi or attribute value.
`abstract void` | `setIndex(Data.Type type, Index ind)` Assigns the specified index.
`int` | `size(int pre, int k)` Returns a size value (number of descendant table entries).
`void` | `size(int pre, int k, int v)` Sets the size value.
`abstract byte[]` | `text(int pre, boolean text)` Returns a text (text, comment, pi) or attribute value.
`void` | `text(int pre, int d, byte[] vl, int k)` Adds a text entry to the internal update buffer.
`abstract int` | `textLen(int pre, boolean text)` Returns a text (text, comment, pi) length.
`abstract double` | `textNum(int pre, boolean text)` Returns a text (text, comment, pi) as double value.
`String` | `toString()`
`String` | `toString(int s, int e)` Returns a string representation of the specified table range.
`int` | `uri(int pre, int k)` Returns a reference to the tag or attribute namespace URI.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### DOC

    public static final byte DOC

  Node kind: Document.

  See Also:
    Constant Field Values

### ELEM

    public static final byte ELEM

  Node kind: Element.

  See Also:
    Constant Field Values

### TEXT

    public static final byte TEXT

  Node kind: Text.

  See Also:
    Constant Field Values

### ATTR

    public static final byte ATTR

  Node kind: Attribute.

  See Also:
    Constant Field Values

### COMM

    public static final byte COMM

  Node kind: Comment.

  See Also:
    Constant Field Values

### PI

    public static final byte PI

  Node kind: Processing Instruction.

  See Also:
    Constant Field Values

### meta

    public MetaData meta

  Meta data.

### tags

    public Names tags

  Tag index.

### atts

    public Names atts

  Attribute name index.

### ns

    public Namespaces ns

  Namespace index.

### path

    public PathSummary path

  Path Summary.

### fs

    public DeepFS fs

  File system reference.

### nameID

    public int nameID

  Index Reference for name tag.

### sizeID

    public int sizeID

  Index References.

Constructor Detail

### Data

    public Data()

Method Detail

### init

    public void init()
              throws IOException

  Dissolves the references to often used tag names and attributes.

  Throws:
    `IOException` - I/O exception

### close

    public final void close()
                     throws IOException

  Closes the current database.

  Throws:
    `IOException` - I/O exception

### flush

    public abstract void flush()

  Flushes the table data.

### closeIndex

    public abstract void closeIndex(Data.Type index)
                             throws IOException

  Closes the specified index.

  Parameters:
    `index` - index to be closed
  Throws:
    `IOException` - I/O exception

### setIndex

    public abstract void setIndex(Data.Type type,
                                  Index ind)

  Assigns the specified index.

  Parameters:
    `type` - index to be opened
    `ind` - index instance

### ids

    public final IndexIterator ids(IndexToken token)

  Returns the indexed id references for the specified token.

  Parameters:
    `token` - index token reference
  Returns:
    id array

### nrIDs

    public final int nrIDs(IndexToken token)

  Returns the number of indexed id references for the specified token.

  Parameters:
    `token` - text to be found
  Returns:
    id array

### doc

    public final int[] doc()

  Returns the document nodes.

  Returns:
    root nodes

### info

    public final byte[] info(Data.Type type)

  Returns info on the specified index structure.

  Parameters:
    `type` - index type
  Returns:
    info

### atom

    public final byte[] atom(int pre)

  Returns an atomized content for any node kind. The atomized value can be an attribute value or XML content.

  Parameters:
    `pre` - pre value
  Returns:
    atomized value

### pre

    public final int pre(int id)

  Returns a pre value.

  Parameters:
    `id` - unique node id
  Returns:
    pre value or -1 if id was not found

### id

    public final int id(int pre)

  Returns a unique node id.

  Parameters:
    `pre` - pre value
  Returns:
    node id

### kind

    public final int kind(int pre)

  Returns a node kind.

  Parameters:
    `pre` - pre value
  Returns:
    node kind

### parent

    public final int parent(int pre,
                            int k)

  Returns a pre value of the parent node.

  Parameters:
    `pre` - pre value
    `k` - node kind
  Returns:
    pre value of the parent node

### size

    public final int size(int pre,
                          int k)

  Returns a size value (number of descendant table entries).

  Parameters:
    `pre` - pre value
    `k` - node kind
  Returns:
    size value

### attSize

    public final int attSize(int pre,
                             int k)

  Returns a number of attributes.

  Parameters:
    `pre` - pre value
    `k` - node kind
  Returns:
    number of attributes

### name

    public final int name(int pre)

  Returns a reference to the tag or attribute name id.

  Parameters:
    `pre` - pre value
  Returns:
    token reference

### name

    public final byte[] name(int pre,
                             int k)

  Returns a tag, attribute or pi name.

  Parameters:
    `pre` - pre value
    `k` - node kind
  Returns:
    name reference

### uri

    public final int uri(int pre,
                         int k)

  Returns a reference to the tag or attribute namespace URI.

  Parameters:
    `pre` - pre value
    `k` - node kind
  Returns:
    token reference

### nsFlag

    public final boolean nsFlag(int pre)

  Returns a namespace flag. Should be only called for element nodes.

  Parameters:
    `pre` - pre value
  Returns:
    namespace flag

### ns

    public final Atts ns(int pre)

  Returns namespace key and value ids. Should be only called for element nodes.

  Parameters:
    `pre` - pre value
  Returns:
    key and value ids

### text

    public abstract byte[] text(int pre,
                                boolean text)

  Returns a text (text, comment, pi) or attribute value.

  Parameters:
    `pre` - pre value
    `text` - text/attribute flag
  Returns:
    atomized value

### textNum

    public abstract double textNum(int pre,
                                   boolean text)

  Returns a text (text, comment, pi) as double value.

  Parameters:
    `pre` - pre value
    `text` - text/attribute flag
  Returns:
    numeric value

### textLen

    public abstract int textLen(int pre,
                                boolean text)

  Returns a text (text, comment, pi) length.

  Parameters:
    `pre` - pre value
    `text` - text/attribute flag
  Returns:
    length

### rename

    public final void rename(int pre,
                             int k,
                             byte[] nm,
                             byte[] uri)

  Renames (updates) an element, attribute or pi name.

  Parameters:
    `pre` - pre value
    `k` - node kind
    `nm` - new tag, attribute or pi name
    `uri` - uri

### replace

    public final void replace(int pre,
                              int k,
                              byte[] val)

  Replaces (updates) a text, comment, pi or attribute value.

  Parameters:
    `pre` - pre value
    `k` - node kind
    `val` - value to be updated (tag name, text, comment, pi)

### delete

    public final void delete(int pre)

  Deletes a node and its descendants.

  Parameters:
    `pre` - pre value of the node to delete

### insertAttr

    public final void insertAttr(int pre,
                                 int par,
                                 MemData dt)

  Inserts attributes.

  Parameters:
    `pre` - pre value
    `par` - parent of node
    `dt` - data instance to copy from

### insert

    public final void insert(int ipre,
                             int ipar,
                             MemData md)

  Inserts a data instance at the specified pre value. Note that the specified data instance must differ from this instance.

  Parameters:
    `ipre` - value at which to insert new data
    `ipar` - parent pre value of node
    `md` - data instance to copy from

### size

    public final void size(int pre,
                           int k,
                           int v)

  Sets the size value.

  Parameters:
    `pre` - pre reference
    `k` - node kind
    `v` - value to be stored

### buffer

    public final void buffer(int s)

  Sets the update buffer to a new size.

  Parameters:
    `s` - number of table entries

### insert

    public final void insert(int pre)

  Inserts the internal buffer to the storage without updating the table structure.

  Parameters:
    `pre` - insert position

### doc

    public void doc(int pre,
                    int s,
                    byte[] vl)

  Adds a document entry to the internal update buffer.

  Parameters:
    `pre` - pre value
    `s` - node size
    `vl` - document name

### elem

    public final void elem(int d,
                           int tn,
                           int as,
                           int s,
                           int u,
                           boolean ne)

  Adds an element entry to the internal update buffer.

  Parameters:
    `d` - parent distance
    `tn` - tag name index
    `as` - number of attributes
    `s` - node size
    `u` - namespace uri reference
    `ne` - namespace flag

### text

    public final void text(int pre,
                           int d,
                           byte[] vl,
                           int k)

  Adds a text entry to the internal update buffer.

  Parameters:
    `pre` - insert position
    `d` - parent distance
    `vl` - tag name or text node
    `k` - node kind

### attr

    public final void attr(int pre,
                           int d,
                           int tn,
                           byte[] vl,
                           int u,
                           boolean ne)

  Adds an attribute entry to the internal update buffer.

  Parameters:
    `pre` - pre value
    `d` - parent distance
    `tn` - attribute name
    `vl` - attribute value
    `u` - namespace uri reference
    `ne` - namespace flag

### toString

    public String toString(int s,
                           int e)

  Returns a string representation of the specified table range.

  Parameters:
    `s` - start pre value
    `e` - end pre value
  Returns:
    table

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD