Class DirectorySubspace

java.lang.Object
com.apple.foundationdb.subspace.Subspace
com.apple.foundationdb.directory.DirectorySubspace
All Implemented Interfaces:
Directory

public class DirectorySubspace extends Subspace implements Directory
A DirectorySubspace represents the contents of a directory, but it also remembers the path with which it was opened and offers convenience methods to operate on the directory at that path.

An instance of DirectorySubspace can be used for all the usual subspace operations. It can also be used to operate on the directory with which it was opened.

  • Method Details

    • toString

      public String toString()
      Description copied from class: Subspace
      Create a human-readable string representation of this subspace. This is really only useful for debugging purposes, but it includes information on what raw prefix the subspace is using.
      Overrides:
      toString in class Subspace
      Returns:
      a printable representation of this DirectorySubspace
    • equals

      public boolean equals(Object rhs)
      Returns whether this DirectorySubspace is equal to rhs. Two DirectorySubspaces are equal if they were created by the same DirectoryLayer and have the same path, layer, and subspace prefix.
      Overrides:
      equals in class Subspace
      Parameters:
      rhs - the Object to test for equality
      Returns:
      true if this is equal to rhs
    • hashCode

      public int hashCode()
      Computes a hash code compatible with the equals() method of this class. In particular, it will produce a hash code that is based off of the hashes of its path, its layer, and its subspace prefix.
      Overrides:
      hashCode in class Subspace
      Returns:
      a hash compatible with this class's equals() method
    • getPath

      public List<String> getPath()
      Description copied from interface: Directory
      Gets the path represented by this Directory.
      Specified by:
      getPath in interface Directory
      Returns:
      this Directory's path
    • getLayer

      public byte[] getLayer()
      Description copied from interface: Directory
      Gets the layer byte string that was stored when this Directory was created.
      Specified by:
      getLayer in interface Directory
      Returns:
      this Directory's layer byte string
    • getDirectoryLayer

      public DirectoryLayer getDirectoryLayer()
      Description copied from interface: Directory
      Get the DirectoryLayer that was used to create this Directory.
      Specified by:
      getDirectoryLayer in interface Directory
      Returns:
      the DirectoryLayer that created this Directory
    • createOrOpen

      public CompletableFuture<DirectorySubspace> createOrOpen(TransactionContext tcx, List<String> subpath, byte[] otherLayer)
      Description copied from interface: Directory
      Creates or opens the subdirectory of this Directory located at subpath (creating parent directories, if necessary). If the directory is new, then the layer byte string will be recorded as its layer. If the directory already exists, the layer byte string will be compared against the layer set when the directory was created.

      The returned CompletableFuture can be set to the following errors:

      Specified by:
      createOrOpen in interface Directory
      Parameters:
      tcx - the TransactionContext to execute this operation in
      subpath - a List<String> specifying a subpath of this Directory
      otherLayer - a byte[] specifying a layer to set on a new directory or check for on an existing directory
      Returns:
      a CompletableFuture which will be set to the created or opened DirectorySubspace
    • open

      public CompletableFuture<DirectorySubspace> open(ReadTransactionContext tcx, List<String> subpath, byte[] otherLayer)
      Description copied from interface: Directory
      Opens the subdirectory of this Directory located at subpath. The layer byte string will be compared against the layer set when the directory was created.

      The returned CompletableFuture can be set to the following errors:

      Specified by:
      open in interface Directory
      Parameters:
      tcx - the ReadTransactionContext to execute this operation in
      subpath - a List<String> specifying a subpath of this Directory
      otherLayer - a byte[] specifying the expected layer
      Returns:
      a CompletableFuture which will be set to the opened DirectorySubspace
    • create

      public CompletableFuture<DirectorySubspace> create(TransactionContext tcx, List<String> subpath, byte[] otherLayer, byte[] prefix)
      Description copied from interface: Directory
      Creates a subdirectory of this Directory located at subpath (creating parent directories if necessary). The layer byte string will be recorded as the new directory's layer and checked by future calls to Directory.open(ReadTransactionContext, List, byte[]). The specified prefix will be used for this directory's contents instead of allocating a prefix automatically.

      The returned CompletableFuture can be set to the following errors:

      Specified by:
      create in interface Directory
      Parameters:
      tcx - the TransactionContext to execute this operation in
      subpath - a List<String> specifying a subpath of this Directory
      otherLayer - a byte[] specifying a layer to set for the directory
      prefix - a byte[] specifying the key prefix to use for the directory's contents
      Returns:
      a CompletableFuture which will be set to the created DirectorySubspace
    • list

      Description copied from interface: Directory
      List the subdirectories of this directory at a given subpath.

      The returned CompletableFuture can be set to the following errors:

      Specified by:
      list in interface Directory
      Parameters:
      tcx - the ReadTransactionContext to execute this operation in
      subpath - a List<String> specifying a subpath of this Directory
      Returns:
      a CompletableFuture which will be set to a List<String> of names of the subdirectories of the directory at subpath. Each name is a unicode string representing the last component of a subdirectory's path.
    • move

      public CompletableFuture<DirectorySubspace> move(TransactionContext tcx, List<String> oldSubpath, List<String> newSubpath)
      Description copied from interface: Directory
      Moves the subdirectory of this Directory located at oldSubpath to newSubpath.

      There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.

      It is invalid to move a directory to:

      • A location where a directory already exists
      • A location whose parent does not exist
      • A subdirectory of itself
      • A different partition

      The returned CompletableFuture can be set to the following errors:

      Specified by:
      move in interface Directory
      Parameters:
      tcx - the TransactionContext to execute this operation in
      oldSubpath - a List<String> specifying the subpath of the directory to move
      newSubpath - a List<String> specifying the subpath to move to
      Returns:
      a CompletableFuture which will be set to the DirectorySubspace for this Directory at its new location.
    • moveTo

      public CompletableFuture<DirectorySubspace> moveTo(TransactionContext tcx, List<String> newAbsolutePath)
      Description copied from interface: Directory
      Moves this Directory to the specified newAbsolutePath.

      There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.

      It is invalid to move a directory to:

      • A location where a directory already exists
      • A location whose parent does not exist
      • A subdirectory of itself
      • A different partition

      The returned CompletableFuture can be set to the following errors:

      Specified by:
      moveTo in interface Directory
      Parameters:
      tcx - the TransactionContext to execute this operation in
      newAbsolutePath - a List<String> specifying the new absolute path for this Directory
      Returns:
      a CompletableFuture which will be set to the DirectorySubspace for this Directory at its new location.
    • remove

      public CompletableFuture<Void> remove(TransactionContext tcx, List<String> subpath)
      Description copied from interface: Directory
      Removes the subdirectory of this Directory located at subpath and all of its subdirectories, as well as all of their contents.

      Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.

      The returned CompletableFuture can be set to the following errors:

      Specified by:
      remove in interface Directory
      Parameters:
      tcx - the TransactionContext to execute this operation in
      subpath - a List<String> specifying a subpath of this Directory
      Returns:
      a CompletableFuture which will be set once the Directory has been removed
    • removeIfExists

      public CompletableFuture<Boolean> removeIfExists(TransactionContext tcx, List<String> subpath)
      Description copied from interface: Directory
      Removes the subdirectory of this Directory located at subpath and all of its subdirectories, as well as all of their contents.

      Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.

      Specified by:
      removeIfExists in interface Directory
      Parameters:
      tcx - the TransactionContext to execute this operation in
      subpath - a List<String> specifying a subpath of this Directory
      Returns:
      a CompletableFuture which will be set to true once the Directory has been removed, or false if it didn't exist.
    • exists

      public CompletableFuture<Boolean> exists(ReadTransactionContext tcx, List<String> subpath)
      Description copied from interface: Directory
      Checks if the subdirectory of this Directory located at subpath exists.
      Specified by:
      exists in interface Directory
      Parameters:
      tcx - the TransactionContext to execute this operation in
      subpath - a List<String> specifying a subpath of this Directory
      Returns:
      a CompletableFuture which will be set to true if the specified subdirectory exists, or false if it doesn't