org.exist.storage
Class NativeBroker

java.lang.Object
  extended byjava.util.Observable
      extended byorg.exist.storage.DBBroker
          extended byorg.exist.storage.NativeBroker

public class NativeBroker
extends DBBroker

NativeBroker.

Author:
Wolfgang Meier

Nested Class Summary
static class NativeBroker.NodeRef
           
 
Field Summary
protected static int BUFFERS
           
protected  CollectionStore collectionsDb
           
protected  org.apache.oro.text.regex.PatternCompiler compiler
           
protected  int defaultIndexDepth
           
protected  DOMFile domDb
           
protected  NativeElementIndex elementIndex
           
protected  ElementPool elementPool
           
protected  BFile elementsDb
           
protected  java.util.Map idxPathMap
           
protected  org.apache.oro.text.regex.PatternMatcher matcher
           
protected static int MEM_LIMIT_CHECK
           
protected  int memMinFree
           
protected  BFile namespacesDb
           
protected  int nodesCount
           
protected  boolean readOnly
           
protected static SymbolTable symbols
           
protected  NativeTextEngine textEngine
           
protected  Serializer xmlSerializer
           
 
Fields inherited from class org.exist.storage.DBBroker
caseSensitive, config, DBM, MATCH_EXACT, MATCH_REGEXP, MATCH_WILDCARDS, MYSQL, NATIVE, ORACLE, pool, POSTGRESQL
 
Constructor Summary
NativeBroker(BrokerPool pool, Configuration config)
          Constructor for the NativeBroker object
 
Method Summary
 void addDocument(Collection collection, DocumentImpl doc)
           
 void addObserver(java.util.Observer o)
           
 void closeDocument()
           
 void endRemove()
           
 NodeSet findElementsByTagName(DocumentSet docs, java.lang.String tagName)
          find elements by their tag name.
 void flush()
          flush all data that has not been written before.
 DocumentSet getAllDocuments(User user)
          get all the documents in this database repository.
 NodeSet getAttributesByName(DocumentSet docs, java.lang.String name)
          Attributes are stored in the element-index (with a leading "@" in the name).
 Collection getCollection(java.lang.String name)
          Gets the collection attribute of the DBBroker object
 Collection getCollection(java.lang.String name, long addr)
          get collection object.
 int getDatabaseType()
          return the type of database this broker is connected to.
 org.w3c.dom.Document getDocument(User user, java.lang.String fileName)
          get a document by it's file name.
 DocumentSet getDocumentsByCollection(User user, java.lang.String collection)
          Gets the documentsByCollection attribute of the DBBroker object
 DocumentSet getDocumentsByCollection(User user, java.lang.String collection, boolean inclusive)
          Gets the documentsByCollection attribute of the DBBroker object
 DocumentSet getDocumentsByDoctype(User user, java.lang.String doctypeName)
          get all the documents in this database matching the given document-type's name.
 java.util.Iterator getDOMIterator(NodeProxy proxy)
          Gets the dOMIterator attribute of the DBBroker object
 java.lang.String getNamespacePrefix(java.lang.String namespace)
          get a common prefix for a namespace URI.
 java.lang.String getNamespaceURI(java.lang.String prefix)
          get the namespace associated with the given prefix.
protected  short getNextCollectionId()
           
 int getNextDocId(Collection collection)
          get the number of documents in the repository this is used to determine a free document-id for the document to be stored.
 java.util.Iterator getNodeIterator(NodeProxy proxy)
           
 NodeSet[] getNodesContaining(DocumentSet docs, java.lang.String[] termList)
          get all the nodes containing the search terms given by the array expr using the fulltext-index.
 NodeSet[] getNodesContaining(DocumentSet docs, java.lang.String[] termList, int type)
          get all the nodes containing the search terms given by the array expr using the fulltext-index.
 NodeSet getNodesEqualTo(NodeSet context, DocumentSet docs, int relation, java.lang.String expr)
          This method handles left or left-and-right truncated search terms.
 java.lang.String getNodeValue(NodeProxy proxy)
          Gets the nodeValue attribute of the DBBroker object
 Collection getOrCreateCollection(User user, java.lang.String name)
          get collection object If the collection does not yet exists, it is created automatically.
 org.w3c.dom.NodeList getRange(org.w3c.dom.Document doc, long first, long last)
          Gets a range of nodes, starting with first, ending with last
 Serializer getSerializer()
          get an instance of the Serializer used for converting nodes back to XML.
static SymbolTable getSymbols()
           
 TextSearchEngine getTextEngine()
          get the TextSearchEngine associated with this broker.
 void index(NodeImpl node)
           
 void insertAfter(NodeImpl previous, NodeImpl node)
           
 boolean isReadOnly()
          Is the database running read-only? Returns false by default.
protected static SymbolTable loadSymbols(BFile namespacesDb)
           
 Serializer newSerializer()
          Description of the Method
protected static java.lang.String normalizeCollectionName(java.lang.String name)
           
 org.w3c.dom.Node objectWith(org.w3c.dom.Document doc, long gid)
          get a node with given owner document and id from the database.
 org.w3c.dom.Node objectWith(NodeProxy p)
           
 void readDocumentMetadata(DocumentImpl doc)
           
 void registerNamespace(java.lang.String namespace, java.lang.String prefix)
          associate a prefix with a given namespace.
 void reindex(DocumentImpl oldDoc, DocumentImpl doc, NodeImpl node)
           
 boolean removeCollection(User user, java.lang.String name)
          Description of the Method
 void removeDocument(User user, java.lang.String docName)
          remove the document with the given document name.
 void removeNode(NodeImpl node, java.lang.String currentPath)
           
 void saveCollection(Collection collection)
          Store a collection into the database.
static void saveSymbols(BFile namespacesDb)
           
 Occurrences[] scanIndexedElements(User user, Collection collection, boolean inclusive)
           
protected  NodeSet scanSequential(NodeSet context, DocumentSet doc, int relation, int truncation, java.lang.String expr)
          Do a sequential search through the DOM-file.
 void shutdown()
          shutdown the broker.
 void store(NodeImpl node, java.lang.CharSequence currentPath)
          Store a node into the database.
 void storeDocument(DocumentImpl doc)
          Store a document into the database.
 void sync()
          Description of the Method
 void update(NodeImpl node)
          Update a node's data.
 
Methods inherited from class org.exist.storage.DBBroker
getAllDocuments, getBrokerPool, getConfiguration, getDocument, getDocumentsByCollection, getDocumentsByDoctype, getDOMIterator, getOrCreateCollection, isCaseSensitive, removeCollection, removeDocument
 
Methods inherited from class java.util.Observable
clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFERS

protected static final int BUFFERS
See Also:
Constant Field Values

MEM_LIMIT_CHECK

protected static int MEM_LIMIT_CHECK

collectionsDb

protected CollectionStore collectionsDb

domDb

protected DOMFile domDb

elementIndex

protected NativeElementIndex elementIndex

elementPool

protected ElementPool elementPool

elementsDb

protected BFile elementsDb

namespacesDb

protected BFile namespacesDb

textEngine

protected NativeTextEngine textEngine

xmlSerializer

protected Serializer xmlSerializer

symbols

protected static SymbolTable symbols

compiler

protected org.apache.oro.text.regex.PatternCompiler compiler

matcher

protected org.apache.oro.text.regex.PatternMatcher matcher

defaultIndexDepth

protected int defaultIndexDepth

idxPathMap

protected java.util.Map idxPathMap

readOnly

protected boolean readOnly

memMinFree

protected int memMinFree

nodesCount

protected int nodesCount
Constructor Detail

NativeBroker

public NativeBroker(BrokerPool pool,
                    Configuration config)
             throws EXistException
Constructor for the NativeBroker object

Parameters:
config - Description of the Parameter
Throws:
EXistException - Description of the Exception
Method Detail

normalizeCollectionName

protected static final java.lang.String normalizeCollectionName(java.lang.String name)

addObserver

public void addObserver(java.util.Observer o)

scanIndexedElements

public Occurrences[] scanIndexedElements(User user,
                                         Collection collection,
                                         boolean inclusive)
                                  throws PermissionDeniedException
Overrides:
scanIndexedElements in class DBBroker
Throws:
PermissionDeniedException

findElementsByTagName

public NodeSet findElementsByTagName(DocumentSet docs,
                                     java.lang.String tagName)
find elements by their tag name. This method is comparable to the DOM's method call getElementsByTagName. All elements matching tagName and belonging to one of the documents in the DocumentSet docs are returned.

Specified by:
findElementsByTagName in class DBBroker
Parameters:
docs - Description of the Parameter
tagName - Description of the Parameter
Returns:
Description of the Return Value

flush

public void flush()
Description copied from class: DBBroker
flush all data that has not been written before.

Overrides:
flush in class DBBroker

endRemove

public void endRemove()
Overrides:
endRemove in class DBBroker

getAllDocuments

public DocumentSet getAllDocuments(User user)
get all the documents in this database repository. The documents are returned as a DocumentSet.

Specified by:
getAllDocuments in class DBBroker
Parameters:
user - Description of the Parameter
Returns:
The allDocuments value

getAttributesByName

public NodeSet getAttributesByName(DocumentSet docs,
                                   java.lang.String name)
Attributes are stored in the element-index (with a leading "@" in the name). So simply call findElementsByTagName()

Specified by:
getAttributesByName in class DBBroker
Parameters:
docs - Description of the Parameter
name - Description of the Parameter
Returns:
The attributesByName value

getCollection

public Collection getCollection(java.lang.String name)
Description copied from class: DBBroker
Gets the collection attribute of the DBBroker object

Specified by:
getCollection in class DBBroker
Parameters:
name - Description of the Parameter
Returns:
The collection value

getCollection

public Collection getCollection(java.lang.String name,
                                long addr)
get collection object. If the collection does not exist, null is returned.

Overrides:
getCollection in class DBBroker
Parameters:
name - Description of the Parameter
Returns:
The collection value

getSymbols

public static SymbolTable getSymbols()

loadSymbols

protected static SymbolTable loadSymbols(BFile namespacesDb)

getDOMIterator

public java.util.Iterator getDOMIterator(NodeProxy proxy)
Description copied from class: DBBroker
Gets the dOMIterator attribute of the DBBroker object

Overrides:
getDOMIterator in class DBBroker
Parameters:
proxy - Description of the Parameter
Returns:
The dOMIterator value

getNodeIterator

public java.util.Iterator getNodeIterator(NodeProxy proxy)
Overrides:
getNodeIterator in class DBBroker

getDatabaseType

public int getDatabaseType()
Description copied from class: DBBroker
return the type of database this broker is connected to.

Specified by:
getDatabaseType in class DBBroker
Returns:
one of the constants defined above.

getDocument

public org.w3c.dom.Document getDocument(User user,
                                        java.lang.String fileName)
                                 throws PermissionDeniedException
get a document by it's file name. The document's file name is used to identify a document. File names are stored without the leading path.

Specified by:
getDocument in class DBBroker
Parameters:
fileName - Description of the Parameter
user - Description of the Parameter
Returns:
The document value
Throws:
PermissionDeniedException - Description of the Exception

getDocumentsByCollection

public DocumentSet getDocumentsByCollection(User user,
                                            java.lang.String collection)
                                     throws PermissionDeniedException
Description copied from class: DBBroker
Gets the documentsByCollection attribute of the DBBroker object

Specified by:
getDocumentsByCollection in class DBBroker
Parameters:
collection - Description of the Parameter
user - Description of the Parameter
Returns:
The documentsByCollection value
Throws:
PermissionDeniedException - Description of the Exception

getDocumentsByCollection

public DocumentSet getDocumentsByCollection(User user,
                                            java.lang.String collection,
                                            boolean inclusive)
                                     throws PermissionDeniedException
Description copied from class: DBBroker
Gets the documentsByCollection attribute of the DBBroker object

Specified by:
getDocumentsByCollection in class DBBroker
Parameters:
collection - Description of the Parameter
inclusive - Description of the Parameter
user - Description of the Parameter
Returns:
The documentsByCollection value
Throws:
PermissionDeniedException - Description of the Exception

getDocumentsByDoctype

public DocumentSet getDocumentsByDoctype(User user,
                                         java.lang.String doctypeName)
get all the documents in this database matching the given document-type's name.

Specified by:
getDocumentsByDoctype in class DBBroker
Parameters:
doctypeName - Description of the Parameter
user - Description of the Parameter
Returns:
The documentsByDoctype value

getNamespacePrefix

public java.lang.String getNamespacePrefix(java.lang.String namespace)
Description copied from class: DBBroker
get a common prefix for a namespace URI. It should be guaranteed that only one prefix is associated with one namespace URI throughout the database.

Overrides:
getNamespacePrefix in class DBBroker
Parameters:
namespace - Description of the Parameter
Returns:
The namespacePrefix value

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)
Description copied from class: DBBroker
get the namespace associated with the given prefix. Every broker subclass should keep an internal map, where it stores the prefixes used for different namespaces. It should be guaranteed that only one prefix is associated with one namespace URI.

Overrides:
getNamespaceURI in class DBBroker
Parameters:
prefix - Description of the Parameter
Returns:
The namespaceURI value

getNextCollectionId

protected short getNextCollectionId()
                             throws ReadOnlyException
Throws:
ReadOnlyException

getNextDocId

public int getNextDocId(Collection collection)
get the number of documents in the repository this is used to determine a free document-id for the document to be stored.

Specified by:
getNextDocId in class DBBroker
Parameters:
collection - Description of the Parameter
Returns:
The nextDocId value

index

public void index(NodeImpl node)
Overrides:
index in class DBBroker

reindex

public void reindex(DocumentImpl oldDoc,
                    DocumentImpl doc,
                    NodeImpl node)
Overrides:
reindex in class DBBroker

getNodeValue

public java.lang.String getNodeValue(NodeProxy proxy)
Description copied from class: DBBroker
Gets the nodeValue attribute of the DBBroker object

Overrides:
getNodeValue in class DBBroker
Parameters:
proxy - Description of the Parameter
Returns:
The nodeValue value

getNodesContaining

public NodeSet[] getNodesContaining(DocumentSet docs,
                                    java.lang.String[] termList,
                                    int type)
get all the nodes containing the search terms given by the array expr using the fulltext-index. Calls to this method are normally delegated to the associated instance of class TextSearchEngine.

Overrides:
getNodesContaining in class DBBroker
Parameters:
docs - Description of the Parameter
termList - Description of the Parameter
type - Description of the Parameter
Returns:
NodeSet[] an array of node sets, one for each search term

getNodesContaining

public NodeSet[] getNodesContaining(DocumentSet docs,
                                    java.lang.String[] termList)
Description copied from class: DBBroker
get all the nodes containing the search terms given by the array expr using the fulltext-index. Calls to this method are normally delegated to the associated instance of class TextSearchEngine.

Specified by:
getNodesContaining in class DBBroker
Parameters:
docs - the set of documents to search through
termList - an array of search terms. a query is executed for each of them
Returns:
NodeSet[] an array of node sets, one for each search term

getNodesEqualTo

public NodeSet getNodesEqualTo(NodeSet context,
                               DocumentSet docs,
                               int relation,
                               java.lang.String expr)
This method handles left or left-and-right truncated search terms. In these cases it is not possible to use the cdata-index, since it contains just the first 8 bytes of every cdata-string.

Specified by:
getNodesEqualTo in class DBBroker
Parameters:
context - Description of the Parameter
docs - Description of the Parameter
relation - Description of the Parameter
expr - Description of the Parameter
Returns:
The nodesEqualTo value

getOrCreateCollection

public Collection getOrCreateCollection(User user,
                                        java.lang.String name)
                                 throws PermissionDeniedException
get collection object If the collection does not yet exists, it is created automatically.

Overrides:
getOrCreateCollection in class DBBroker
Parameters:
name - the collection's name
user - Description of the Parameter
Returns:
The orCreateCollection value
Throws:
PermissionDeniedException - Description of the Exception

getRange

public org.w3c.dom.NodeList getRange(org.w3c.dom.Document doc,
                                     long first,
                                     long last)
Gets a range of nodes, starting with first, ending with last

Specified by:
getRange in class DBBroker
Parameters:
doc - the document
first - node-id of the first node
last - node-id of the last node
Returns:
a list of nodes

getSerializer

public Serializer getSerializer()
Description copied from class: DBBroker
get an instance of the Serializer used for converting nodes back to XML. Subclasses of DBBroker may have specialized subclasses of Serializer to convert a node into an XML-string

Specified by:
getSerializer in class DBBroker
Returns:
The serializer value

getTextEngine

public TextSearchEngine getTextEngine()
Description copied from class: DBBroker
get the TextSearchEngine associated with this broker. Every subclass of DBBroker will have it's own implementation of TextSearchEngine.

Specified by:
getTextEngine in class DBBroker
Returns:
The textEngine value

newSerializer

public Serializer newSerializer()
Description copied from class: DBBroker
Description of the Method

Specified by:
newSerializer in class DBBroker
Returns:
Description of the Return Value

objectWith

public org.w3c.dom.Node objectWith(org.w3c.dom.Document doc,
                                   long gid)
Description copied from class: DBBroker
get a node with given owner document and id from the database.

Specified by:
objectWith in class DBBroker
Parameters:
doc - the document the node belongs to
gid - the node's unique identifier
Returns:
Description of the Return Value

objectWith

public org.w3c.dom.Node objectWith(NodeProxy p)
Specified by:
objectWith in class DBBroker

registerNamespace

public void registerNamespace(java.lang.String namespace,
                              java.lang.String prefix)
Description copied from class: DBBroker
associate a prefix with a given namespace. Every broker subclass should keep an internal map, where it stores the prefixes used for different namespaces. It should be guaranteed that only one prefix is associated with one namespace URI.

Overrides:
registerNamespace in class DBBroker
Parameters:
namespace - Description of the Parameter
prefix - Description of the Parameter

removeCollection

public boolean removeCollection(User user,
                                java.lang.String name)
                         throws PermissionDeniedException
Description copied from class: DBBroker
Description of the Method

Specified by:
removeCollection in class DBBroker
Parameters:
name - Description of the Parameter
user - Description of the Parameter
Returns:
Description of the Return Value
Throws:
PermissionDeniedException - Description of the Exception

removeDocument

public void removeDocument(User user,
                           java.lang.String docName)
                    throws PermissionDeniedException
Description copied from class: DBBroker
remove the document with the given document name.

Specified by:
removeDocument in class DBBroker
Parameters:
docName - Description of the Parameter
user - Description of the Parameter
Throws:
PermissionDeniedException - Description of the Exception

removeNode

public void removeNode(NodeImpl node,
                       java.lang.String currentPath)
Overrides:
removeNode in class DBBroker

addDocument

public void addDocument(Collection collection,
                        DocumentImpl doc)
                 throws PermissionDeniedException
Overrides:
addDocument in class DBBroker
Throws:
PermissionDeniedException

saveCollection

public void saveCollection(Collection collection)
                    throws PermissionDeniedException
Description copied from class: DBBroker
Store a collection into the database.

Specified by:
saveCollection in class DBBroker
Parameters:
collection - Description of the Parameter
Throws:
PermissionDeniedException

saveSymbols

public static void saveSymbols(BFile namespacesDb)

scanSequential

protected NodeSet scanSequential(NodeSet context,
                                 DocumentSet doc,
                                 int relation,
                                 int truncation,
                                 java.lang.String expr)
Do a sequential search through the DOM-file.

Parameters:
context - Description of the Parameter
doc - Description of the Parameter
relation - Description of the Parameter
truncation - Description of the Parameter
expr - Description of the Parameter
Returns:
Description of the Return Value

shutdown

public void shutdown()
Description copied from class: DBBroker
shutdown the broker. All open files, jdbc connections etc. should be closed.

Overrides:
shutdown in class DBBroker

store

public void store(NodeImpl node,
                  java.lang.CharSequence currentPath)
Store a node into the database. This method is called by the parser to write a node to the storage backend.

Specified by:
store in class DBBroker
Parameters:
node - the node to be stored
currentPath - path expression which points to this node's element-parent or to itself if it is an element (currently used by the Broker to determine if a node's content should be fulltext-indexed).

storeDocument

public void storeDocument(DocumentImpl doc)
Description copied from class: DBBroker
Store a document into the database.

Specified by:
storeDocument in class DBBroker
Parameters:
doc - Description of the Parameter

readDocumentMetadata

public void readDocumentMetadata(DocumentImpl doc)
Overrides:
readDocumentMetadata in class DBBroker

sync

public void sync()
Description copied from class: DBBroker
Description of the Method

Overrides:
sync in class DBBroker

closeDocument

public void closeDocument()
Overrides:
closeDocument in class DBBroker

update

public void update(NodeImpl node)
Description copied from class: DBBroker
Update a node's data. This method is only used by the NativeBroker. To keep nodes in a correct sequential order, it sometimes needs to update a previous written node. Warning: don't use it for other purposes. RelationalBroker does not implement this method.

Overrides:
update in class DBBroker
Parameters:
node - Description of the Parameter

insertAfter

public void insertAfter(NodeImpl previous,
                        NodeImpl node)
Overrides:
insertAfter in class DBBroker

isReadOnly

public boolean isReadOnly()
Description copied from class: DBBroker
Is the database running read-only? Returns false by default. Storage backends should override this if they support read-only mode.

Overrides:
isReadOnly in class DBBroker
Returns:
boolean


Copyright (C) Wolfgang Meier. All rights reserved.