Class DataStore

java.lang.Object
org.apache.derby.impl.io.vfmem.DataStore

public final class DataStore extends Object
A virtual data store, keeping track of all the virtual files existing and offering a set of high-level operations on virtual files.

A newly created data store doesn't contain a single existing directory.

  • Field Details

    • SEP

      private static final char SEP
      The path separator used.
    • EMPTY_STR_ARR

      private static final String[] EMPTY_STR_ARR
      Constant for the empty String array.
    • LOCK

      private final Object LOCK
      Lock object for the file map.
    • TMP_COUNTER_LOCK

      private final Object TMP_COUNTER_LOCK
      Lock object for the temporary file counter.
    • files

      private final Map<String,DataStoreEntry> files
      The files exsiting in the store.

      The initial size is set to the number of initial files of a Derby database, pluss a few more.

    • databaseName

      private final String databaseName
      The name of the database this store serves, expected to be the absolute path of the service root (i.e. /tmp/myDB if the database myDB is created in /tmp).
    • tmpFileCounter

      private long tmpFileCounter
      Counter used to generate unique temporary file names.
    • deleteMe

      private boolean deleteMe
      Tells if this store is scheduled for deletion.
  • Constructor Details

    • DataStore

      public DataStore(String databaseName)
      Creates a new data store.
      Parameters:
      databaseName - the name of the assoicated database, expected to be the absolute path of the service root.
  • Method Details

    • getDatabaseName

      public String getDatabaseName()
      Returns the database name, which is expected to equal the path of the service root.
      Returns:
      The database name.
    • scheduledForDeletion

      public boolean scheduledForDeletion()
      Tells if this data store is scheduled for deletion.
      Returns:
      true if the store is awaiting deletion, false otherwise.
    • createEntry

      public DataStoreEntry createEntry(String iPath, boolean isDir)
      Creates a new entry in the data store.

      This method returns null if the path already exists, if one of the parent directories doesn't exist, or if one of the parents is a file instead of a directory.

      Parameters:
      iPath - the path of the entry
      isDir - tells if the new entry shall be directory or a file
      Returns:
      A DataStoreEntry-instance if the entry was successfully created, null otherwise
    • createAllParents

      public boolean createAllParents(String path)
      Creates all the parents of the specified path.
      Returns:
      true if all parents either already existed as directories or were created, false otherwise
    • deleteEntry

      public boolean deleteEntry(String iPath)
      Deletes the specified entry.

      If the specified entry is a directory, it is only deleted if it is empty. Read-only entries are deleted.

      Parameters:
      iPath - path of the entry to delete
      Returns:
      true if the entry was deleted, false otherwise.
    • getEntry

      public DataStoreEntry getEntry(String iPath)
      Returns the entry with the specified path.
      Parameters:
      iPath - path of the entry to fetch
      Returns:
      null if the entry doesn't exist, the DataStoreEntry-object otherwise.
    • deleteAll

      public boolean deleteAll(String iPath)
      Deletes the specified entry and all its children.
      Parameters:
      iPath - the root entry
      Returns:
      true if the entry and all its children were deleted, false if the root doesn't exist.
    • listChildren

      public String[] listChildren(String iPath)
      Lists the childen of the specified path.
      Parameters:
      iPath - the directory to list the children of
      Returns:
      An array with the relative paths of the children.
    • move

      public boolean move(StorageFile currentFile, StorageFile newFile)
      Moves / renames a file.
      Parameters:
      currentFile - the current file
      newFile - the new file
      Returns:
      true if the file was moved, false if the new file already existed or the existing file doesn't exist.
    • purge

      public void purge()
      Purges the database and releases all files associated with it.
    • _deleteAll

      private boolean _deleteAll(String prefixPath)
      Deletes every child of the root path specified.

      Note that the root itself must be removed outside of this method.

      Parameters:
      prefixPath - the normalized root path to start deleting from
      Returns:
      true if all children of the root path were deleted, false otherwise.
    • getTempFileCounter

      public long getTempFileCounter()
      Returns an identifier for a temporary file.
      Returns:
      An integer uniquely identifying a temporary file.
    • getParentList

      private String[] getParentList(String path)
      Returns the list of parents for the specified path.

      The lowest level parent is listed first in the list, so all absolute paths will have the root listed as the last element.

      Parameters:
      path - the normalized path to create a parent list for
      Returns:
      A list of parents.