Class Builder

java.lang.Object
org.basex.core.jobs.Job
org.basex.build.Builder
Direct Known Subclasses:
DiskBuilder, MemBuilder

public abstract class Builder extends Job
This class provides an interface for building database instances. The specified Parser sends events to this class whenever nodes are to be added or closed. The builder implementation decides whether the nodes are stored on disk or kept in memory.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Summary

    Fields inherited from class org.basex.core.jobs.Job

    state, updating
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    addAttr(int nameId, byte[] value, int dist, int uriId)
    Adds an attribute to the database.
    protected abstract void
    addDoc(byte[] value)
    Adds a document node to the database.
    protected abstract void
    addElem(int dist, int nameId, int asize, int uriId, boolean ne)
    Adds an element node to the database.
    protected abstract void
    addText(byte[] value, int dist, byte kind)
    Adds a text node to the database.
    final void
    binary(String target, IO data)
    Stores binary data.
    final Builder
    Sets the path to the raw database files.
    abstract Data
    Builds the database and returns the resulting database instance.
    final void
    Closes a document node.
    final void
    Closes an element.
    final void
    comment(byte[] value)
    Stores a comment.
    final String
    Returns detailed progress information.
    final void
    emptyElem(byte[] name, Atts att, Atts nsp)
    Stores an empty element.
    final void
    openDoc(byte[] value)
    Opens a document node.
    final void
    openElem(byte[] name, Atts att, Atts nsp)
    Opens a new element node.
    final void
    pi(byte[] pi)
    Stores a processing instruction.
    final double
    Returns a progress value (0 - 1).
    protected abstract void
    setSize(int pre, int size)
    Stores a size value to the specified table position.
    final String
    Returns short progress information.
    final void
    text(byte[] value)
    Stores a text node.

    Methods inherited from class org.basex.core.jobs.Job

    active, addLocks, checkStop, jc, memory, popJob, pushJob, register, state, stop, stopped, timeout, unregister

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • binaryDir

      public final Builder binaryDir(IOFile dir)
      Sets the path to the raw database files. The path might differ from the actual database path if XML data is written to a temporary instance.
      Parameters:
      dir - database directory (can be null)
      Returns:
      self reference
    • openDoc

      public final void openDoc(byte[] value) throws IOException
      Opens a document node.
      Parameters:
      value - document name
      Throws:
      IOException - I/O exception
    • closeDoc

      public final void closeDoc() throws IOException
      Closes a document node.
      Throws:
      IOException - I/O exception
    • openElem

      public final void openElem(byte[] name, Atts att, Atts nsp) throws IOException
      Opens a new element node.
      Parameters:
      name - name of element
      att - attributes
      nsp - namespaces
      Throws:
      IOException - I/O exception
    • emptyElem

      public final void emptyElem(byte[] name, Atts att, Atts nsp) throws IOException
      Stores an empty element.
      Parameters:
      name - name of element
      att - attributes
      nsp - namespaces
      Throws:
      IOException - I/O exception
    • closeElem

      public final void closeElem() throws IOException
      Closes an element.
      Throws:
      IOException - I/O exception
    • text

      public final void text(byte[] value) throws IOException
      Stores a text node.
      Parameters:
      value - text value
      Throws:
      IOException - I/O exception
    • comment

      public final void comment(byte[] value) throws IOException
      Stores a comment.
      Parameters:
      value - comment text
      Throws:
      IOException - I/O exception
    • pi

      public final void pi(byte[] pi) throws IOException
      Stores a processing instruction.
      Parameters:
      pi - processing instruction name and value
      Throws:
      IOException - I/O exception
    • binary

      public final void binary(String target, IO data) throws IOException
      Stores binary data.
      Parameters:
      target - database target
      data - data to store
      Throws:
      IOException - I/O exception
    • shortInfo

      public final String shortInfo()
      Description copied from class: Job
      Returns short progress information. Can be overwritten to give more specific feedback.
      Overrides:
      shortInfo in class Job
      Returns:
      header information
    • detailedInfo

      public final String detailedInfo()
      Description copied from class: Job
      Returns detailed progress information. Can be overwritten to give more specific feedback.
      Overrides:
      detailedInfo in class Job
      Returns:
      header information
    • progressInfo

      public final double progressInfo()
      Description copied from class: Job
      Returns a progress value (0 - 1). Can be overwritten to give more specific feedback.
      Overrides:
      progressInfo in class Job
      Returns:
      header information
    • build

      public abstract Data build() throws IOException
      Builds the database and returns the resulting database instance.
      Returns:
      data database instance
      Throws:
      IOException - I/O exception
    • addDoc

      protected abstract void addDoc(byte[] value) throws IOException
      Adds a document node to the database.
      Parameters:
      value - name of the document
      Throws:
      IOException - I/O exception
    • addElem

      protected abstract void addElem(int dist, int nameId, int asize, int uriId, boolean ne) throws IOException
      Adds an element node to the database. This method stores a preliminary size value; if this node has further descendants, setSize(int, int) must be called to set the final size value.
      Parameters:
      dist - distance to parent
      nameId - id of element name
      asize - number of attributes
      uriId - id of namespace uri
      ne - namespace flag (indicates if this element introduces new namespaces)
      Throws:
      IOException - I/O exception
    • addAttr

      protected abstract void addAttr(int nameId, byte[] value, int dist, int uriId) throws IOException
      Adds an attribute to the database.
      Parameters:
      nameId - id of attribute name
      value - attribute value
      dist - distance to parent
      uriId - id of namespace uri
      Throws:
      IOException - I/O exception
    • addText

      protected abstract void addText(byte[] value, int dist, byte kind) throws IOException
      Adds a text node to the database.
      Parameters:
      value - the token to be added
      dist - distance to parent
      kind - the node kind
      Throws:
      IOException - I/O exception
    • setSize

      protected abstract void setSize(int pre, int size) throws IOException
      Stores a size value to the specified table position.
      Parameters:
      pre - pre reference
      size - value to be stored
      Throws:
      IOException - I/O exception