org.exist.storage
Class NativeElementIndex

java.lang.Object
  extended by java.util.Observable
      extended by org.exist.storage.ElementIndex
          extended by org.exist.storage.NativeElementIndex
All Implemented Interfaces:
ContentLoadingObserver

public class NativeElementIndex
extends ElementIndex
implements ContentLoadingObserver

The indexing occurs in this class. That is, during the loading of a document into the database, the process of associating a long gid with each element, and the subsequent storing of the NodeProxy on disk.


Constructor Summary
NativeElementIndex(DBBroker broker, BFile dbNodes)
           
 
Method Summary
 void addNode(QName qname, NodeProxy proxy)
          Store the given node in the node index.
 boolean close()
           
 void consistencyCheck(DocumentImpl document)
           
 void dropIndex(Collection collection)
          Drop all index entries for the given collection.
 void dropIndex(DocumentImpl document)
          Drop all index entries for the given document.
 void endElement(int xpathType, ElementImpl node, java.lang.String content)
          store and index given element (called storeElement before)
 NodeSet findDescendantsByTagName(byte type, QName qname, int axis, DocumentSet docs, ExtArrayNodeSet contextSet, int contextId)
          Optimized lookup method which directly implements the ancestor-descendant join.
 NodeSet findElementsByTagName(byte type, DocumentSet docs, QName qname, NodeSelector selector)
          Lookup elements or attributes in the index matching a given QName and NodeSelector.
 void flush()
          writes the pending items, for the current document's collection
 void printStatistics()
           
 void reindex(DocumentImpl document, StoredNode node)
          Reindexes all pending items for the specified document.
 void remove()
          remove all pending modifications, for the current document.
 void removeElement(ElementImpl node, NodePath currentPath, java.lang.String content)
          Mark given Element for removal; added entries are written to the list of pending entries.
 Occurrences[] scanIndexedElements(Collection collection, boolean inclusive)
           
 void startElement(ElementImpl impl, NodePath currentPath, boolean index)
          corresponds to SAX function of the same name
 void storeAttribute(AttrImpl node, NodePath currentPath, boolean fullTextIndexSwitch)
          store and index given attribute
 void storeText(TextImpl node, NodePath currentPath, boolean fullTextIndexSwitch)
          store and index given text node
 void sync()
          triggers a cache sync, i.e.
 java.lang.String toString()
           
 
Methods inherited from class org.exist.storage.ElementIndex
setDocument, setInUpdateMode
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.exist.storage.ContentLoadingObserver
setDocument
 

Constructor Detail

NativeElementIndex

public NativeElementIndex(DBBroker broker,
                          BFile dbNodes)
Method Detail

addNode

public void addNode(QName qname,
                    NodeProxy proxy)
Store the given node in the node index.

Parameters:
qname - The node's identity
proxy - The node's proxy

storeAttribute

public void storeAttribute(AttrImpl node,
                           NodePath currentPath,
                           boolean fullTextIndexSwitch)
Description copied from interface: ContentLoadingObserver
store and index given attribute

Specified by:
storeAttribute in interface ContentLoadingObserver

storeText

public void storeText(TextImpl node,
                      NodePath currentPath,
                      boolean fullTextIndexSwitch)
Description copied from interface: ContentLoadingObserver
store and index given text node

Specified by:
storeText in interface ContentLoadingObserver

startElement

public void startElement(ElementImpl impl,
                         NodePath currentPath,
                         boolean index)
Description copied from interface: ContentLoadingObserver
corresponds to SAX function of the same name

Specified by:
startElement in interface ContentLoadingObserver

endElement

public void endElement(int xpathType,
                       ElementImpl node,
                       java.lang.String content)
Description copied from interface: ContentLoadingObserver
store and index given element (called storeElement before)

Specified by:
endElement in interface ContentLoadingObserver

removeElement

public void removeElement(ElementImpl node,
                          NodePath currentPath,
                          java.lang.String content)
Description copied from interface: ContentLoadingObserver
Mark given Element for removal; added entries are written to the list of pending entries. ContentLoadingObserver.flush() is called later to flush all pending entries.
Notes: changed name from storeElement()

Specified by:
removeElement in interface ContentLoadingObserver

sync

public void sync()
Description copied from interface: ContentLoadingObserver
triggers a cache sync, i.e. forces to write out all cached pages. sync() is called from time to time by the background sync daemon.

Specified by:
sync in interface ContentLoadingObserver

flush

public void flush()
Description copied from interface: ContentLoadingObserver
writes the pending items, for the current document's collection

Specified by:
flush in interface ContentLoadingObserver

remove

public void remove()
Description copied from interface: ContentLoadingObserver
remove all pending modifications, for the current document.

Specified by:
remove in interface ContentLoadingObserver

dropIndex

public void dropIndex(Collection collection)
Description copied from interface: ContentLoadingObserver
Drop all index entries for the given collection.

Specified by:
dropIndex in interface ContentLoadingObserver

dropIndex

public void dropIndex(DocumentImpl document)
               throws ReadOnlyException
Description copied from interface: ContentLoadingObserver
Drop all index entries for the given document.

Specified by:
dropIndex in interface ContentLoadingObserver
Throws:
ReadOnlyException

reindex

public void reindex(DocumentImpl document,
                    StoredNode node)
Description copied from interface: ContentLoadingObserver
Reindexes all pending items for the specified document. Similar to the normal index process, items to be reindexed are added to the internal pending list via methods #addNode(QName, NodeProxy), #storeElement(int, ElementImpl, String), and {@link #storeAttribute(RangeIndexSpec, AttrImpl)}. Method reindex then scans this list and updates the items in the index to reflect the reindexed document.

Specified by:
reindex in interface ContentLoadingObserver
Parameters:
document - the document to be reindexed.
node - if != null, only nodes being descendants of the specified node will be reindexed. Other nodes are not touched. This is used for a partial reindex.

findElementsByTagName

public NodeSet findElementsByTagName(byte type,
                                     DocumentSet docs,
                                     QName qname,
                                     NodeSelector selector)
Lookup elements or attributes in the index matching a given QName and NodeSelector. The NodeSelector argument is optional. If selector is null, all elements or attributes matching qname will be returned.

Specified by:
findElementsByTagName in class ElementIndex
Parameters:
type - either ElementValue.ATTRIBUTE, ElementValue.ELEMENT or ElementValue.ATTRIBUTE_ID
docs - the set of documents to look up in the index
qname - the QName of the attribute or element
selector - an (optional) NodeSelector
Returns:

findDescendantsByTagName

public NodeSet findDescendantsByTagName(byte type,
                                        QName qname,
                                        int axis,
                                        DocumentSet docs,
                                        ExtArrayNodeSet contextSet,
                                        int contextId)
Optimized lookup method which directly implements the ancestor-descendant join. The algorithm does directly operate on the input stream containing the potential descendant nodes. It thus needs less comparisons than findElementsByTagName(byte, DocumentSet, QName, NodeSelector).

Specified by:
findDescendantsByTagName in class ElementIndex
Parameters:
type - either ElementValue.ATTRIBUTE, ElementValue.ELEMENT or ElementValue.ATTRIBUTE_ID
docs - the set of documents to look up in the index
contextSet - the set of ancestor nodes for which the method will try to find descendants
contextId - id of the current context expression as passed by the query engine
qname - the QName to search for

scanIndexedElements

public Occurrences[] scanIndexedElements(Collection collection,
                                         boolean inclusive)
                                  throws PermissionDeniedException
Specified by:
scanIndexedElements in class ElementIndex
Throws:
PermissionDeniedException

consistencyCheck

public void consistencyCheck(DocumentImpl document)
                      throws EXistException
Throws:
EXistException

close

public boolean close()
              throws DBException
Throws:
DBException

printStatistics

public void printStatistics()

toString

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


Copyright (C) Wolfgang Meier. All rights reserved.