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 database table and the index structures for textual content in a compressed disk structure. The table mapping is documented in Data.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen, Tim Petrowsky

Field Summary
 
Fields inherited from class org.basex.data.Data
atnindex, ATTR, atvindex, cache, COMM, DOC, ELEM, ftxindex, meta, nspaces, paths, PI, pins, resources, tagindex, TEXT, txtindex
 
Constructor Summary
DiskData(MetaData md, Names nm, Names at, PathSummary ps, Namespaces n)
          Internal database constructor, called from DiskBuilder.build().
DiskData(java.lang.String db, Context ctx)
          Default constructor, called from Open.open(java.lang.String, org.basex.core.Context).
 
Method Summary
 void close()
          Closes the database.
 void closeIndex(IndexType type)
          Closes the specified index.
protected  void delete(int pre, boolean text)
          Deletes the specified text entry.
 void finishUpdate()
          Finishes an update operation: removes the update file and the exclusive lock.
protected  long index(int pre, int id, byte[] value, int kind)
          Indexes a text and returns the reference.
protected  void indexBegin()
          Notify the index structures that an update operation is started.
protected  void indexDelete(int pre, int size)
          Delete a node and its descendants from the corresponding indexes.
protected  void indexEnd()
          Notify the index structures that an update operation is finished.
 void init()
          Initializes the database.
 void setIndex(IndexType type, Index index)
          Assigns the specified index.
 boolean startUpdate()
          Starts an update operation: writes a file to disk to indicate that an update is going on, and exclusively locks the table.
 byte[] text(int pre, boolean text)
          Returns a text (text, comment, pi) or attribute value.
 double textDbl(int pre, boolean text)
          Returns a text (text, comment, pi) or attribute value as double value.
 long textItr(int pre, boolean text)
          Returns a text (text, comment, pi) or attribute value as integer value.
 int textLen(int pre, boolean text)
          Returns the byte length of a text (text, comment, pi).
 IOFile updateFile()
          Returns a file that indicates ongoing updates.
protected  void updateText(int pre, byte[] value, int kind)
          Updates the specified text or attribute value.
 
Methods inherited from class org.basex.data.Data
atom, attr, attSize, attValue, count, delete, dist, dist, doc, elem, id, info, inMemory, insert, insert, insertAttr, iter, kind, name, name, ns, nsFlag, nsFlag, parent, pre, pre, replace, size, size, text, toString, update, update, uri
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DiskData

public DiskData(java.lang.String db,
                Context ctx)
         throws java.io.IOException
Default constructor, called from Open.open(java.lang.String, org.basex.core.Context).

Parameters:
db - name of database
ctx - database context
Throws:
java.io.IOException - I/O Exception

DiskData

public DiskData(MetaData md,
                Names nm,
                Names at,
                PathSummary ps,
                Namespaces n)
         throws java.io.IOException
Internal database constructor, called from DiskBuilder.build().

Parameters:
md - meta data
nm - tags
at - attributes
ps - path summary
n - namespaces
Throws:
java.io.IOException - I/O Exception
Method Detail

init

public void init()
          throws java.io.IOException
Initializes the database.

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

close

public void close()
Description copied from class: Data
Closes the database.

Specified by:
close in class Data

closeIndex

public void closeIndex(IndexType type)
Description copied from class: Data
Closes the specified index.

Specified by:
closeIndex in class Data
Parameters:
type - index to be closed

setIndex

public void setIndex(IndexType 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

startUpdate

public boolean startUpdate()
Description copied from class: Data
Starts an update operation: writes a file to disk to indicate that an update is going on, and exclusively locks the table.

Specified by:
startUpdate in class Data
Returns:
success flag

finishUpdate

public void finishUpdate()
Description copied from class: Data
Finishes an update operation: removes the update file and the exclusive lock.

Specified by:
finishUpdate in class Data

updateFile

public IOFile updateFile()
Returns a file that indicates ongoing updates.

Returns:
updating file

text

public byte[] text(int pre,
                   boolean text)
Description copied from class: Data
Returns a text (text, comment, pi) or attribute value.

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

textItr

public long textItr(int pre,
                    boolean text)
Description copied from class: Data
Returns a text (text, comment, pi) or attribute value as integer value.

Specified by:
textItr in class Data
Parameters:
pre - pre value
text - text/attribute flag
Returns:
numeric value

textDbl

public double textDbl(int pre,
                      boolean text)
Description copied from class: Data
Returns a text (text, comment, pi) or attribute value as double value.

Specified by:
textDbl in class Data
Parameters:
pre - pre value
text - text/attribute flag
Returns:
numeric value

textLen

public int textLen(int pre,
                   boolean text)
Description copied from class: Data
Returns the byte length of a text (text, comment, pi).

Specified by:
textLen in class Data
Parameters:
pre - pre value
text - text/attribute flag
Returns:
length

delete

protected void delete(int pre,
                      boolean text)
Description copied from class: Data
Deletes the specified text entry.

Specified by:
delete in class Data
Parameters:
pre - pre value
text - text (text, comment or pi) or attribute flag

updateText

protected void updateText(int pre,
                          byte[] value,
                          int kind)
Description copied from class: Data
Updates the specified text or attribute value.

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

indexBegin

protected void indexBegin()
Description copied from class: Data
Notify the index structures that an update operation is started.


indexEnd

protected void indexEnd()
Description copied from class: Data
Notify the index structures that an update operation is finished.


index

protected long index(int pre,
                     int id,
                     byte[] value,
                     int kind)
Description copied from class: Data
Indexes a text and returns the reference.

Specified by:
index in class Data
Parameters:
pre - pre value
id - id value
value - text to be indexed
kind - node kind
Returns:
reference

indexDelete

protected void indexDelete(int pre,
                           int size)
Description copied from class: Data
Delete a node and its descendants from the corresponding indexes.

Specified by:
indexDelete in class Data
Parameters:
pre - pre value of the node to delete
size - number of descendants