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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<DirectorySubspace>
create(TransactionContext tcx, java.util.List<java.lang.String> subpath, byte[] otherLayer, byte[] prefix)
Creates a subdirectory of thisDirectory
located atsubpath
(creating parent directories if necessary).java.util.concurrent.CompletableFuture<DirectorySubspace>
createOrOpen(TransactionContext tcx, java.util.List<java.lang.String> subpath, byte[] otherLayer)
Creates or opens the subdirectory of thisDirectory
located atsubpath
(creating parent directories, if necessary).boolean
equals(java.lang.Object rhs)
Returns whether thisDirectorySubspace
is equal torhs
.java.util.concurrent.CompletableFuture<java.lang.Boolean>
exists(ReadTransactionContext tcx, java.util.List<java.lang.String> subpath)
Checks if the subdirectory of thisDirectory
located atsubpath
exists.DirectoryLayer
getDirectoryLayer()
Get theDirectoryLayer
that was used to create thisDirectory
.byte[]
getLayer()
Gets the layer byte string that was stored when thisDirectory
was created.java.util.List<java.lang.String>
getPath()
Gets the path represented by thisDirectory
.int
hashCode()
Computes a hash code compatible with theequals()
method of this class.java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>>
list(ReadTransactionContext tcx, java.util.List<java.lang.String> subpath)
List the subdirectories of this directory at a givensubpath
.java.util.concurrent.CompletableFuture<DirectorySubspace>
move(TransactionContext tcx, java.util.List<java.lang.String> oldSubpath, java.util.List<java.lang.String> newSubpath)
Moves the subdirectory of thisDirectory
located atoldSubpath
tonewSubpath
.java.util.concurrent.CompletableFuture<DirectorySubspace>
moveTo(TransactionContext tcx, java.util.List<java.lang.String> newAbsolutePath)
Moves thisDirectory
to the specifiednewAbsolutePath
.java.util.concurrent.CompletableFuture<DirectorySubspace>
open(ReadTransactionContext tcx, java.util.List<java.lang.String> subpath, byte[] otherLayer)
Opens the subdirectory of thisDirectory
located atsubpath
.java.util.concurrent.CompletableFuture<java.lang.Void>
remove(TransactionContext tcx, java.util.List<java.lang.String> subpath)
Removes the subdirectory of thisDirectory
located atsubpath
and all of its subdirectories, as well as all of their contents.java.util.concurrent.CompletableFuture<java.lang.Boolean>
removeIfExists(TransactionContext tcx, java.util.List<java.lang.String> subpath)
Removes the subdirectory of thisDirectory
located atsubpath
and all of its subdirectories, as well as all of their contents.java.lang.String
toString()
Create a human-readable string representation of this subspace.-
Methods inherited from class com.apple.foundationdb.subspace.Subspace
contains, get, get, getKey, pack, pack, pack, packWithVersionstamp, range, range, subspace, unpack
-
Methods inherited from interface com.apple.foundationdb.directory.Directory
create, create, createOrOpen, exists, list, open, remove, removeIfExists
-
-
-
-
Method Detail
-
toString
public java.lang.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.
-
equals
public boolean equals(java.lang.Object rhs)
Returns whether thisDirectorySubspace
is equal torhs
. TwoDirectorySubspace
s are equal if they were created by the sameDirectoryLayer
and have the same path, layer, and subspace prefix.
-
hashCode
public int hashCode()
Computes a hash code compatible with theequals()
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.
-
getPath
public java.util.List<java.lang.String> getPath()
Description copied from interface:Directory
Gets the path represented by thisDirectory
.
-
getLayer
public byte[] getLayer()
Description copied from interface:Directory
Gets the layer byte string that was stored when thisDirectory
was created.
-
getDirectoryLayer
public DirectoryLayer getDirectoryLayer()
Description copied from interface:Directory
Get theDirectoryLayer
that was used to create thisDirectory
.- Specified by:
getDirectoryLayer
in interfaceDirectory
- Returns:
- the
DirectoryLayer
that created thisDirectory
-
createOrOpen
public java.util.concurrent.CompletableFuture<DirectorySubspace> createOrOpen(TransactionContext tcx, java.util.List<java.lang.String> subpath, byte[] otherLayer)
Description copied from interface:Directory
Creates or opens the subdirectory of thisDirectory
located atsubpath
(creating parent directories, if necessary). If the directory is new, then thelayer
byte string will be recorded as its layer. If the directory already exists, thelayer
byte string will be compared against thelayer
set when the directory was created.The returned
CompletableFuture
can be set to the following errors:MismatchedLayerException
- if the directory has already been created with a differentlayer
byte string
- Specified by:
createOrOpen
in interfaceDirectory
- Parameters:
tcx
- theTransactionContext
to execute this operation insubpath
- aList<String>
specifying a subpath of thisDirectory
otherLayer
- abyte[]
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 openedDirectorySubspace
-
open
public java.util.concurrent.CompletableFuture<DirectorySubspace> open(ReadTransactionContext tcx, java.util.List<java.lang.String> subpath, byte[] otherLayer)
Description copied from interface:Directory
Opens the subdirectory of thisDirectory
located atsubpath
. Thelayer
byte string will be compared against thelayer
set when the directory was created.The returned
CompletableFuture
can be set to the following errors:MismatchedLayerException
- if the directory was created with a differentlayer
byte stringNoSuchDirectoryException
- if the directory does not exist
- Specified by:
open
in interfaceDirectory
- Parameters:
tcx
- theReadTransactionContext
to execute this operation insubpath
- aList<String>
specifying a subpath of thisDirectory
otherLayer
- abyte[]
specifying the expected layer- Returns:
- a
CompletableFuture
which will be set to the openedDirectorySubspace
-
create
public java.util.concurrent.CompletableFuture<DirectorySubspace> create(TransactionContext tcx, java.util.List<java.lang.String> subpath, byte[] otherLayer, byte[] prefix)
Description copied from interface:Directory
Creates a subdirectory of thisDirectory
located atsubpath
(creating parent directories if necessary). Thelayer
byte string will be recorded as the new directory's layer and checked by future calls toDirectory.open(ReadTransactionContext, List, byte[])
. The specifiedprefix
will be used for this directory's contents instead of allocating a prefix automatically.The returned
CompletableFuture
can be set to the following errors:DirectoryAlreadyExistsException
- if the given directory already exists
- Specified by:
create
in interfaceDirectory
- Parameters:
tcx
- theTransactionContext
to execute this operation insubpath
- aList<String>
specifying a subpath of thisDirectory
otherLayer
- abyte[]
specifying a layer to set for the directoryprefix
- abyte[]
specifying the key prefix to use for the directory's contents- Returns:
- a
CompletableFuture
which will be set to the createdDirectorySubspace
-
list
public java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> list(ReadTransactionContext tcx, java.util.List<java.lang.String> subpath)
Description copied from interface:Directory
List the subdirectories of this directory at a givensubpath
.The returned
CompletableFuture
can be set to the following errors:NoSuchDirectoryException
- if no directory exists atsubpath
- Specified by:
list
in interfaceDirectory
- Parameters:
tcx
- theReadTransactionContext
to execute this operation insubpath
- aList<String>
specifying a subpath of thisDirectory
- Returns:
- a
CompletableFuture
which will be set to aList<String>
of names of the subdirectories of the directory atsubpath
. Each name is a unicode string representing the last component of a subdirectory's path.
-
move
public java.util.concurrent.CompletableFuture<DirectorySubspace> move(TransactionContext tcx, java.util.List<java.lang.String> oldSubpath, java.util.List<java.lang.String> newSubpath)
Description copied from interface:Directory
Moves the subdirectory of thisDirectory
located atoldSubpath
tonewSubpath
.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:NoSuchDirectoryException
- if noDirectory
exists atoldSubpath
DirectoryAlreadyExistsException
- if a directory already exists atnewSubpath
DirectoryMoveException
- if an invalid move location is specified
- Specified by:
move
in interfaceDirectory
- Parameters:
tcx
- theTransactionContext
to execute this operation inoldSubpath
- aList<String>
specifying the subpath of the directory to movenewSubpath
- aList<String>
specifying the subpath to move to- Returns:
- a
CompletableFuture
which will be set to theDirectorySubspace
for thisDirectory
at its new location.
-
moveTo
public java.util.concurrent.CompletableFuture<DirectorySubspace> moveTo(TransactionContext tcx, java.util.List<java.lang.String> newAbsolutePath)
Description copied from interface:Directory
Moves thisDirectory
to the specifiednewAbsolutePath
.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:NoSuchDirectoryException
- if thisDirectory
doesn't existDirectoryAlreadyExistsException
- if a directory already exists atnewAbsolutePath
DirectoryMoveException
- if an invalid move location is specified
- Specified by:
moveTo
in interfaceDirectory
- Parameters:
tcx
- theTransactionContext
to execute this operation innewAbsolutePath
- aList<String>
specifying the new absolute path for thisDirectory
- Returns:
- a
CompletableFuture
which will be set to theDirectorySubspace
for thisDirectory
at its new location.
-
remove
public java.util.concurrent.CompletableFuture<java.lang.Void> remove(TransactionContext tcx, java.util.List<java.lang.String> subpath)
Description copied from interface:Directory
Removes the subdirectory of thisDirectory
located atsubpath
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:NoSuchDirectoryException
- if no directory exists atsubpath
- Specified by:
remove
in interfaceDirectory
- Parameters:
tcx
- theTransactionContext
to execute this operation insubpath
- aList<String>
specifying a subpath of thisDirectory
- Returns:
- a
CompletableFuture
which will be set once theDirectory
has been removed
-
removeIfExists
public java.util.concurrent.CompletableFuture<java.lang.Boolean> removeIfExists(TransactionContext tcx, java.util.List<java.lang.String> subpath)
Description copied from interface:Directory
Removes the subdirectory of thisDirectory
located atsubpath
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 interfaceDirectory
- Parameters:
tcx
- theTransactionContext
to execute this operation insubpath
- aList<String>
specifying a subpath of thisDirectory
- Returns:
- a
CompletableFuture
which will be set to true once theDirectory
has been removed, or false if it didn't exist.
-
exists
public java.util.concurrent.CompletableFuture<java.lang.Boolean> exists(ReadTransactionContext tcx, java.util.List<java.lang.String> subpath)
Description copied from interface:Directory
Checks if the subdirectory of thisDirectory
located atsubpath
exists.- Specified by:
exists
in interfaceDirectory
- Parameters:
tcx
- theTransactionContext
to execute this operation insubpath
- aList<String>
specifying a subpath of thisDirectory
- Returns:
- a
CompletableFuture
which will be set totrue
if the specified subdirectory exists, orfalse
if it doesn't
-
-