Package db

# Class Database

java.lang.Object
db.Database

Direct Known Subclasses:
  `PackedDatabase`, `PrivateDatabase`, `VersionedDatabase`

public abstract class Database extends Object
`Database` facilitates the creation of a DBHandle for accessing a database.

Public constructors are only provided for use with "Non-Versioned" databases. This class should be extended when additional management features are needed, such as for a "Versioned" database.

This class assumes exclusive control of the associated files contained within the associated database directory and relies on the proper establishment of a syncObject to midigate potential concurrent modification issues.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected class`
  `Database.DBBufferFileManager`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected BufferFileManager`
  `bfMgr`
  `protected static final String`
  `CHANGE_FILE_PREFIX`
  `protected static final String`
  `CUMULATIVE_CHANGE_FILENAME`
  `protected static final String`
  `CUMULATIVE_MODMAP_FILENAME`
  `protected int`
  `currentVersion`
  `protected static final String`
  `DATABASE_FILE_PREFIX`
  `protected File`
  `dbDir`
  `protected boolean`
  `dbDirCreated`
  `protected DBFileListener`
  `dbFileListener`
  `protected boolean`
  `isCheckOutCopy`
  `protected boolean`
  `isVersioned`
  `protected long`
  `lastModified`
  `protected int`
  `minVersion`
  `protected Object`
  `syncObject`
  `protected boolean`
  `updateAllowed`
  `protected static final String`
  `VERSION_FILE_PREFIX`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Database(File dbDir)`
  Constructor for an existing "Non-Versioned" Database.
  `protected`
  `Database(File dbDir, boolean isVersioned, boolean create)`
  General Database Constructor.
  `protected`
  `Database(File dbDir, DBFileListener dbFileListener, boolean create)`
  Constructor for a new or existing "Non-Versioned" Database.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected static final boolean`
  `deleteDir(File dir)`
  Delete a directory and all of its contents.
  `int`
  `getCurrentVersion()`
  Returns the version number associated with the latest buffer file version.
  `long`
  `lastModified()`
  Returns the time at which this database was last saved.
  `long`
  `length()`
  Returns the length of this domain file.
  `DBHandle`
  `open(TaskMonitor monitor)`
  Open the stored database for non-update use.
  `DBHandle`
  `openForUpdate(TaskMonitor monitor)`
  Open the stored database for update use.
  `void`
  `refresh()`
  Scan files and update state.
  `protected void`
  `scanFiles(boolean repair)`
  Scan files and update state.
  `void`
  `setSynchronizationObject(Object syncObject)`
  Set the object to be used for synchronization.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DATABASE_FILE_PREFIX

    protected static final String DATABASE_FILE_PREFIX
    See Also:
      - Constant Field Values

  - ### VERSION_FILE_PREFIX

    protected static final String VERSION_FILE_PREFIX
    See Also:
      - Constant Field Values

  - ### CHANGE_FILE_PREFIX

    protected static final String CHANGE_FILE_PREFIX
    See Also:
      - Constant Field Values

  - ### CUMULATIVE_CHANGE_FILENAME

    protected static final String CUMULATIVE_CHANGE_FILENAME
    See Also:
      - Constant Field Values

  - ### CUMULATIVE_MODMAP_FILENAME

    protected static final String CUMULATIVE_MODMAP_FILENAME
    See Also:
      - Constant Field Values

  - ### minVersion

    protected int minVersion

  - ### currentVersion

    protected int currentVersion

  - ### lastModified

    protected long lastModified

  - ### isVersioned

    protected boolean isVersioned

  - ### isCheckOutCopy

    protected boolean isCheckOutCopy

  - ### updateAllowed

    protected boolean updateAllowed

  - ### bfMgr

    protected BufferFileManager bfMgr

  - ### dbDir

    protected File dbDir

  - ### dbFileListener

    protected DBFileListener dbFileListener

  - ### dbDirCreated

    protected boolean dbDirCreated

  - ### syncObject

    protected Object syncObject

- ## Constructor Details

  - ### Database

    protected Database(File dbDir, boolean isVersioned, boolean create) throws IOException
    General Database Constructor.
    Parameters:
      `dbDir` -
      `isVersioned` -
      `create` - if true the database will be created.
    Throws:
      `IOException`

  - ### Database

    protected Database(File dbDir, DBFileListener dbFileListener, boolean create) throws IOException
    Constructor for a new or existing "Non-Versioned" Database.
    Parameters:
      `dbDir` -
      `dbFileListener` - file version listener
      `create` -
    Throws:
      `IOException`

  - ### Database

    protected Database(File dbDir) throws IOException
    Constructor for an existing "Non-Versioned" Database.
    Parameters:
      `dbDir` - database directory
    Throws:
      `IOException`

- ## Method Details

  - ### setSynchronizationObject

    public void setSynchronizationObject(Object syncObject)
    Set the object to be used for synchronization.
    Parameters:
      `syncObject` -

  - ### lastModified

    public long lastModified()
    Returns the time at which this database was last saved.

  - ### deleteDir

    protected static final boolean deleteDir(File dir)
    Delete a directory and all of its contents.
    Parameters:
      `dir` -
    Returns:
      true if delete was successful. If false is returned, a partial delete may have occurred.

  - ### getCurrentVersion

    public int getCurrentVersion()
    Returns the version number associated with the latest buffer file version.

  - ### open

    public DBHandle open(TaskMonitor monitor) throws IOException, CancelledException
    Open the stored database for non-update use. The returned handle does not support the Save operation.
    Parameters:
      `monitor` - task monitor (may be null)
    Returns:
      database handle
    Throws:
      `FileInUseException` - thrown if unable to obtain the required database lock(s).
      `IOException` - thrown if IO error occurs.
      `CancelledException` - if cancelled by monitor

  - ### openForUpdate

    public DBHandle openForUpdate(TaskMonitor monitor) throws IOException, CancelledException
    Open the stored database for update use.
    Parameters:
      `monitor` - task monitor (may be null)
    Returns:
      buffer file
    Throws:
      `FileInUseException` - thrown if unable to obtain the required database lock(s).
      `IOException` - thrown if IO error occurs.
      `CancelledException` - if cancelled by monitor

  - ### length

    public long length() throws IOException
    Returns the length of this domain file. This size is the minimum disk space used for storing this file, but does not account for additional storage space used to tracks changes, etc.
    Returns:
      file length
    Throws:
      `IOException` - thrown if IO or access error occurs

  - ### refresh

    public void refresh() throws FileNotFoundException
    Scan files and update state.
    Throws:
      `FileNotFoundException`

  - ### scanFiles

    protected void scanFiles(boolean repair) throws FileNotFoundException
    Scan files and update state.
    Parameters:
      `repair` - if true files are repaired if needed.
    Throws:
      `FileNotFoundException`