org.exist.storage.store
Class DOMFile

java.lang.Object
  extended byorg.dbxml.core.filer.Paged
      extended byorg.dbxml.core.filer.BTree
          extended byorg.exist.storage.store.DOMFile
All Implemented Interfaces:
Lockable

public class DOMFile
extends org.dbxml.core.filer.BTree
implements Lockable

DOMFile represents the central storage file for DOM nodes. Nodes are stored in sequential order to allow fast access when serializing a document or fragment. Pages have previous-page/next-page links. Each node has a virtual address, which consists of a page-number/tid pair. The tid is a virtual offset into the page. A node may be moved to a new page on node insertions. However, the tid will always remain the same.

Author:
Wolfgang Meier

Nested Class Summary
protected  class DOMFile.ClockPageBuffer
          Cache for data pages.
protected  class DOMFile.DOMFilePageHeader
          Description of the Class
protected  class DOMFile.DOMPage
          Description of the Class
protected  class DOMFile.OverflowDOMPage
           
protected static class DOMFile.RecordPos
           
 
Nested classes inherited from class org.dbxml.core.filer.BTree
org.dbxml.core.filer.BTree.BTreeFileHeader, org.dbxml.core.filer.BTree.BTreeNode, org.dbxml.core.filer.BTree.BTreePageHeader, org.dbxml.core.filer.BTree.ClockNodeBuffer
 
Nested classes inherited from class org.dbxml.core.filer.Paged
org.dbxml.core.filer.Paged.FileHeader, org.dbxml.core.filer.Paged.Page, org.dbxml.core.filer.Paged.PageHeader
 
Field Summary
static byte FREE_LIST
           
static byte LOB
           
protected static short OVERFLOW
           
static byte RECORD
           
 
Fields inherited from class org.dbxml.core.filer.BTree
BRANCH, KEY_NOT_FOUND, LEAF, STREAM
 
Fields inherited from class org.dbxml.core.filer.Paged
DELETED, PAGE_SIZE, UNUSED
 
Constructor Summary
DOMFile(java.io.File file)
          Constructor for the DOMFile object
DOMFile(java.io.File file, int buffers)
          Constructor for the DOMFile object
DOMFile(java.io.File file, int buffers, int dataBuffers)
          Constructor for the DOMFile object
DOMFile(java.io.File file, int buffers, short keyLen)
          Constructor for the DOMFile object.
DOMFile(int buffers, int dataBuffers)
          Constructor for the DOMFile object
 
Method Summary
 long add(byte[] value)
          Append a value to the current page
 void addToBuffer(DOMFile.DOMPage page)
           
 boolean close()
          Description of the Method
 void closeDocument()
           
 boolean create()
          Description of the Method
 org.dbxml.core.filer.Paged.FileHeader createFileHeader()
          Description of the Method
 org.dbxml.core.filer.Paged.FileHeader createFileHeader(boolean read)
          Description of the Method
 org.dbxml.core.filer.Paged.FileHeader createFileHeader(long pageCount)
          Description of the Method
 org.dbxml.core.filer.Paged.FileHeader createFileHeader(long pageCount, int pageSize)
          Description of the Method
protected  org.dbxml.core.filer.Paged.Page createNewPage()
          Description of the Method
 org.dbxml.core.filer.Paged.PageHeader createPageHeader()
          Description of the Method
 java.util.ArrayList findKeys(org.dbxml.core.indexer.IndexQuery query)
          Description of the Method
 java.util.ArrayList findRange(org.dbxml.core.data.Value first, org.dbxml.core.data.Value last)
          Retrieve a range of nodes, starting at first and including last.
protected  long findValue(java.lang.Object lock, NodeProxy node)
          Find a node by searching for a known ancestor in the index.
protected  DOMFile.RecordPos findValuePosition(long p)
           
 java.util.ArrayList findValues(org.dbxml.core.indexer.IndexQuery query)
          Find matching nodes for the given query.
 boolean flush()
          Flush all buffers to disk.
 org.dbxml.core.data.Value get(long p)
          Retrieve node at virtual address p.
 org.dbxml.core.data.Value get(NodeProxy node)
          Retrieve a node described by the given NodeProxy.
 org.dbxml.core.data.Value get(org.dbxml.core.data.Value key)
          Retrieve a node by key
protected  DOMFile.DOMPage getCurrentPage(long p)
          Retrieve the page with page number p
 BufferStats getDataBufferStats()
           
 Lock getLock()
          Get the active Lock object for this file.
 java.lang.String getNodeValue(NodeProxy proxy)
           
protected  byte[] getOverflowValue(long pnum)
           
protected  DOMFile.ClockPageBuffer getPageBuffer()
           
 long insertAfter(DocumentImpl doc, long address, byte[] value)
          Insert a new node after the node located at the specified address.
 long insertAfter(DocumentImpl doc, org.dbxml.core.data.Value key, byte[] value)
          Insert a new node after the specified node.
 boolean open()
          Open the file.
 void printStatistics()
           
 long put(org.dbxml.core.data.Value key, byte[] value)
          Put a new key/value pair.
 void releaseOwner(java.lang.Object obj)
           
 void remove(long p)
           
 void remove(org.dbxml.core.data.Value key)
          Remove a key/value pair.
 void remove(org.dbxml.core.data.Value key, long p)
          Remove the value at address p.
protected  void removeOverflowValue(long pnum)
           
protected  void reportSplit(DocumentImpl doc, DOMFile.DOMPage oldPage, DOMFile.DOMPage newPage)
          Report the new position of nodes after a page has been split.
 void setLocation(java.lang.String location)
          Set the file location for this DOMFile.
 void setOwnerObject(java.lang.Object obj)
          The current object owning this file.
 void sync()
           
protected  void unlinkPages(org.dbxml.core.filer.Paged.Page page)
           
 boolean update(org.dbxml.core.data.Value key, byte[] value)
          Update the key/value pair.
 void update(org.dbxml.core.data.Value key, long p, byte[] value)
          Update the key/value pair where the value is found at address p.
 
Methods inherited from class org.dbxml.core.filer.BTree
addValue, clear, create, createRootNode, drop, findValue, getFixedKeyLen, getIndexBufferStats, getRootNode, query, remove, remove, removeValue, setRootNode
 
Methods inherited from class org.dbxml.core.filer.Paged
deleteArrayInt, deleteArrayLong, deleteArrayShort, deleteArrayValue, exists, getFile, getFileHeader, getFreePage, getPage, getPageSize, insertArrayInt, insertArrayLong, insertArrayShort, insertArrayValue, isOpened, isReadOnly, setFile, setPageSize, unlinkPages, writeValue, writeValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FREE_LIST

public static final byte FREE_LIST
See Also:
Constant Field Values

LOB

public static final byte LOB
See Also:
Constant Field Values

RECORD

public static final byte RECORD
See Also:
Constant Field Values

OVERFLOW

protected static final short OVERFLOW
See Also:
Constant Field Values
Constructor Detail

DOMFile

public DOMFile(int buffers,
               int dataBuffers)
Constructor for the DOMFile object

Parameters:
buffers - the number of btree buffers to use
dataBuffers - the number of data page buffers

DOMFile

public DOMFile(java.io.File file)
Constructor for the DOMFile object

Parameters:
file - the file to use

DOMFile

public DOMFile(java.io.File file,
               int buffers)
Constructor for the DOMFile object

Parameters:
file - the file to use
buffers - size of the data page buffer

DOMFile

public DOMFile(java.io.File file,
               int buffers,
               int dataBuffers)
Constructor for the DOMFile object

Parameters:
file - the file to use
buffers - size of the buffer for btree pages
dataBuffers - size of the buffer for data pages

DOMFile

public DOMFile(java.io.File file,
               int buffers,
               short keyLen)
Constructor for the DOMFile object. Use this constructor if all keys have the same length.

Parameters:
file - the file to use
buffers - size of the data page buffer
keyLen - key size if all keys have the same length
Method Detail

getPageBuffer

protected final DOMFile.ClockPageBuffer getPageBuffer()

add

public long add(byte[] value)
         throws ReadOnlyException
Append a value to the current page

Parameters:
value - the value to append
Returns:
the virtual storage address of the value
Throws:
ReadOnlyException

insertAfter

public long insertAfter(DocumentImpl doc,
                        org.dbxml.core.data.Value key,
                        byte[] value)
Insert a new node after the specified node.

Parameters:
key -
value -
Returns:

insertAfter

public long insertAfter(DocumentImpl doc,
                        long address,
                        byte[] value)
Insert a new node after the node located at the specified address.

Parameters:
doc - the document to which the new node belongs.
address - the storage address of the node after which the new value should be inserted.
value - the value of the new node.
Returns:

reportSplit

protected final void reportSplit(DocumentImpl doc,
                                 DOMFile.DOMPage oldPage,
                                 DOMFile.DOMPage newPage)
Report the new position of nodes after a page has been split.

Parameters:
doc -
oldPage -
newPage -

close

public boolean close()
              throws org.dbxml.core.DBException
Description of the Method

Returns:
Description of the Return Value
Throws:
org.dbxml.core.DBException - Description of the Exception

create

public boolean create()
               throws org.dbxml.core.DBException
Description of the Method

Returns:
Description of the Return Value
Throws:
org.dbxml.core.DBException - Description of the Exception

createFileHeader

public org.dbxml.core.filer.Paged.FileHeader createFileHeader()
Description of the Method

Returns:
Description of the Return Value

createFileHeader

public org.dbxml.core.filer.Paged.FileHeader createFileHeader(boolean read)
                                                       throws java.io.IOException
Description of the Method

Parameters:
read - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

createFileHeader

public org.dbxml.core.filer.Paged.FileHeader createFileHeader(long pageCount)
Description of the Method

Parameters:
pageCount - Description of the Parameter
Returns:
Description of the Return Value

createFileHeader

public org.dbxml.core.filer.Paged.FileHeader createFileHeader(long pageCount,
                                                              int pageSize)
Description of the Method

Parameters:
pageCount - Description of the Parameter
pageSize - Description of the Parameter
Returns:
Description of the Return Value

createNewPage

protected org.dbxml.core.filer.Paged.Page createNewPage()
Description of the Method

Returns:
Description of the Return Value

unlinkPages

protected void unlinkPages(org.dbxml.core.filer.Paged.Page page)
                    throws java.io.IOException
Throws:
java.io.IOException

createPageHeader

public org.dbxml.core.filer.Paged.PageHeader createPageHeader()
Description of the Method

Returns:
Description of the Return Value

findKeys

public java.util.ArrayList findKeys(org.dbxml.core.indexer.IndexQuery query)
                             throws java.io.IOException,
                                    org.dbxml.core.filer.BTreeException
Description of the Method

Parameters:
query - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception
org.dbxml.core.filer.BTreeException - Description of the Exception

findRange

public java.util.ArrayList findRange(org.dbxml.core.data.Value first,
                                     org.dbxml.core.data.Value last)
                              throws java.io.IOException,
                                     org.dbxml.core.filer.BTreeException
Retrieve a range of nodes, starting at first and including last.

Parameters:
first - the first node to retrieve
last - the last node to retrieve
Returns:
list of nodes
Throws:
java.io.IOException - Description of the Exception
org.dbxml.core.filer.BTreeException - Description of the Exception

findValue

protected long findValue(java.lang.Object lock,
                         NodeProxy node)
                  throws java.io.IOException,
                         org.dbxml.core.filer.BTreeException
Find a node by searching for a known ancestor in the index. If an ancestor is found, it is traversed to locate the specified descendant node.

Parameters:
lock -
node -
Returns:
Throws:
java.io.IOException
org.dbxml.core.filer.BTreeException

findValues

public java.util.ArrayList findValues(org.dbxml.core.indexer.IndexQuery query)
                               throws java.io.IOException,
                                      org.dbxml.core.filer.BTreeException
Find matching nodes for the given query.

Parameters:
query - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception
org.dbxml.core.filer.BTreeException - Description of the Exception

flush

public boolean flush()
              throws org.dbxml.core.DBException
Flush all buffers to disk.

Returns:
Description of the Return Value
Throws:
org.dbxml.core.DBException - Description of the Exception

sync

public void sync()
          throws org.dbxml.core.DBException
Throws:
org.dbxml.core.DBException

printStatistics

public void printStatistics()

getDataBufferStats

public BufferStats getDataBufferStats()

get

public org.dbxml.core.data.Value get(org.dbxml.core.data.Value key)
Retrieve a node by key

Parameters:
key -
Returns:
Description of the Return Value

get

public org.dbxml.core.data.Value get(NodeProxy node)
Retrieve a node described by the given NodeProxy.

Parameters:
node - Description of the Parameter
Returns:
Description of the Return Value

get

public org.dbxml.core.data.Value get(long p)
Retrieve node at virtual address p.

Parameters:
p - Description of the Parameter
Returns:
Description of the Return Value

getOverflowValue

protected byte[] getOverflowValue(long pnum)

removeOverflowValue

protected void removeOverflowValue(long pnum)

getCurrentPage

protected final DOMFile.DOMPage getCurrentPage(long p)
Retrieve the page with page number p

Parameters:
p - Description of the Parameter
Returns:
The currentPage value

closeDocument

public void closeDocument()

open

public boolean open()
             throws org.dbxml.core.DBException
Open the file.

Returns:
Description of the Return Value
Throws:
org.dbxml.core.DBException - Description of the Exception

put

public long put(org.dbxml.core.data.Value key,
                byte[] value)
         throws ReadOnlyException
Put a new key/value pair.

Parameters:
key - Description of the Parameter
value - Description of the Parameter
Returns:
Description of the Return Value
Throws:
ReadOnlyException

remove

public void remove(org.dbxml.core.data.Value key)
Remove a key/value pair.

Parameters:
key - Description of the Parameter

remove

public void remove(long p)

remove

public void remove(org.dbxml.core.data.Value key,
                   long p)
Remove the value at address p.

Parameters:
p - Description of the Parameter

getLock

public final Lock getLock()
Get the active Lock object for this file.

Specified by:
getLock in interface Lockable
See Also:
Lockable.getLock()

setLocation

public void setLocation(java.lang.String location)
Set the file location for this DOMFile.

Parameters:
location - The new location value

setOwnerObject

public final void setOwnerObject(java.lang.Object obj)
The current object owning this file.

Parameters:
obj - The new ownerObject value

releaseOwner

public final void releaseOwner(java.lang.Object obj)

update

public boolean update(org.dbxml.core.data.Value key,
                      byte[] value)
               throws ReadOnlyException
Update the key/value pair.

Parameters:
key - Description of the Parameter
value - Description of the Parameter
Returns:
Description of the Return Value
Throws:
ReadOnlyException

update

public void update(org.dbxml.core.data.Value key,
                   long p,
                   byte[] value)
            throws ReadOnlyException
Update the key/value pair where the value is found at address p.

Parameters:
key - Description of the Parameter
p - Description of the Parameter
value - Description of the Parameter
Throws:
ReadOnlyException

getNodeValue

public java.lang.String getNodeValue(NodeProxy proxy)

findValuePosition

protected final DOMFile.RecordPos findValuePosition(long p)

addToBuffer

public final void addToBuffer(DOMFile.DOMPage page)


Copyright (C) Wolfgang Meier. All rights reserved.