public class DirectoryLayer extends Object implements Directory
The FoundationDB API provides directories as a tool for managing related
Subspaces. Directories are a recommended approach for administering
applications. Each application should create or open at least one directory
to manage its subspaces.
For general guidance on directory usage, see the discussion in the
Developer Guide.
Directories are identified by hierarchical paths analogous to the paths in a Unix-like file system. A path is represented as a List of strings. Each directory has an associated subspace used to store its content. The layer maps each path to a short prefix used for the corresponding subspace. In effect, directories provide a level of indirection for access to subspaces.
In the present release, multiple directories may not be concurrently created within a single transaction. This restriction will be removed in a future release.| Modifier and Type | Field and Description |
|---|---|
static Subspace |
DEFAULT_CONTENT_SUBSPACE
The default content
Subspace used by a DirectoryLayer when none is specified. |
static Subspace |
DEFAULT_NODE_SUBSPACE
The default node
Subspace used by a DirectoryLayer when none is specified. |
static byte[] |
PARTITION_LAYER
The layer string to pass to
Directory.createOrOpen(TransactionContext, List, byte[]) or
Directory.create(TransactionContext, List, byte[]) to create a DirectoryPartition. |
| Constructor and Description |
|---|
DirectoryLayer()
Constructor for a
DirectoryLayer formed with default node and
content subspaces. |
DirectoryLayer(boolean allowManualPrefixes)
Constructor for a
DirectoryLayer formed with default node and
content subspaces. |
DirectoryLayer(Subspace nodeSubspace,
Subspace contentSubspace)
Constructor for a
DirectoryLayer formed with a specified node
subspace and specified content subspace. |
DirectoryLayer(Subspace nodeSubspace,
Subspace contentSubspace,
boolean allowManualPrefixes)
Constructor for a
DirectoryLayer formed with a specified node
subspace and specified content subspace. |
| Modifier and Type | Method and Description |
|---|---|
Future<DirectorySubspace> |
create(TransactionContext tcx,
List<String> path)
Creates a directory located at
path (creating parent directories if necessary). |
Future<DirectorySubspace> |
create(TransactionContext tcx,
List<String> path,
byte[] layer)
Creates a directory located at
path (creating parent directories if necessary). |
Future<DirectorySubspace> |
create(TransactionContext tcx,
List<String> path,
byte[] layer,
byte[] prefix)
Creates a directory located at
path (creating parent directories if necessary). |
Future<DirectorySubspace> |
createOrOpen(TransactionContext tcx,
List<String> path)
Creates or opens the directory located at
path (creating parent directories, if necessary). |
Future<DirectorySubspace> |
createOrOpen(TransactionContext tcx,
List<String> path,
byte[] layer)
Creates or opens the directory located at
path(creating parent directories, if necessary). |
static Directory |
createWithContentSubspace(Subspace content_subspace)
Creates a new
DirectoryLayer formed with a default node subspace and specified content subspace. |
static Directory |
createWithNodeSubspace(Subspace node_subspace)
Creates a new
DirectoryLayer formed with a specified node subspace and default content subspace. |
boolean |
equals(Object rhs)
Tests whether this
DirectoryLayer is equal to rhs. |
Future<Boolean> |
exists(ReadTransactionContext tcx)
Returns
true. |
Future<Boolean> |
exists(ReadTransactionContext tcx,
List<String> path)
Checks if the directory located at
path exists. |
static DirectoryLayer |
getDefault()
Gets the default instance of the DirectoryLayer.
|
DirectoryLayer |
getDirectoryLayer()
Returns
this. |
byte[] |
getLayer()
Returns the layer byte string for this
DirectoryLayer, which is always an empty
array. |
List<String> |
getPath()
Gets the path for the root node of this
DirectoryLayer. |
Future<List<String>> |
list(ReadTransactionContext tcx)
List the subdirectories of the root directory.
|
Future<List<String>> |
list(ReadTransactionContext tcx,
List<String> path)
List the subdirectories of the directory at a given
path. |
Future<DirectorySubspace> |
move(TransactionContext tcx,
List<String> oldPath,
List<String> newPath)
Moves the directory located at
oldPath to newPath. |
Future<DirectorySubspace> |
moveTo(TransactionContext tcx,
List<String> newAbsolutePath)
This method should not be called on a
DirectoryLayer. |
Future<DirectorySubspace> |
open(ReadTransactionContext tcx,
List<String> path)
Opens the directory located at
path. |
Future<DirectorySubspace> |
open(ReadTransactionContext tcx,
List<String> path,
byte[] layer)
Opens the directory located at
path. |
Future<Void> |
remove(TransactionContext tcx)
This method should not be called on the root directory.
|
Future<Void> |
remove(TransactionContext tcx,
List<String> path)
Removes the directory located at
path and all of its subdirectories,
as well as all of their contents. |
Future<Boolean> |
removeIfExists(TransactionContext tcx)
This method should not be called on the root directory.
|
Future<Boolean> |
removeIfExists(TransactionContext tcx,
List<String> path)
Removes the directory located at
subpath and all of its subdirectories,
as well as all of their contents. |
public static final Subspace DEFAULT_NODE_SUBSPACE
Subspace used by a DirectoryLayer when none is specified.public static final Subspace DEFAULT_CONTENT_SUBSPACE
Subspace used by a DirectoryLayer when none is specified.public static final byte[] PARTITION_LAYER
Directory.createOrOpen(TransactionContext, List, byte[]) or
Directory.create(TransactionContext, List, byte[]) to create a DirectoryPartition.public DirectoryLayer()
DirectoryLayer formed with default node and
content subspaces. A DirectoryLayer
defines a new root directory. The node subspace and content subspace
control where the directory metadata and contents, respectively, are
stored. The default root directory has a node subspace with raw prefix
\xFE and a content subspace with no prefix.
Prefixes can not be specified in calls to Directory.create(TransactionContext, List, byte[], byte[]).getDefault()public DirectoryLayer(boolean allowManualPrefixes)
DirectoryLayer formed with default node and
content subspaces. A DirectoryLayer
defines a new root directory. The node subspace and content subspace
control where the directory metadata and contents, respectively, are
stored. The default root directory has a node subspace with raw prefix
\xFE and a content subspace with no prefix.allowManualPrefixes - whether or not prefixes can be specified in calls to
Directory.create(TransactionContext, List, byte[], byte[])public DirectoryLayer(Subspace nodeSubspace, Subspace contentSubspace)
DirectoryLayer formed with a specified node
subspace and specified content subspace. A DirectoryLayer
defines a new root directory. The node subspace and content subspace
control where the directory metadata and contents, respectively, are
stored. The default root directory has a node subspace with raw prefix
\xFE and a content subspace with no prefix. Specifying more
restrictive values for the node subspace and content subspace will allow
using the directory layer alongside other content in a database.
Prefixes can not be specified in calls to Directory.create(TransactionContext, List, byte[], byte[]).public DirectoryLayer(Subspace nodeSubspace, Subspace contentSubspace, boolean allowManualPrefixes)
DirectoryLayer formed with a specified node
subspace and specified content subspace. A DirectoryLayer
defines a new root directory. The node subspace and content subspace
control where the directory metadata and contents, respectively, are
stored. The default root directory has a node subspace with raw prefix
\xFE and a content subspace with no prefix. Specifying more
restrictive values for the node subspace and content subspace will allow
using the directory layer alongside other content in a database.nodeSubspace - a Subspace used to store directory metadatacontentSubspace - a Subspace used to store directory contentallowManualPrefixes - whether or not prefixes can be specified in calls to
Directory.create(TransactionContext, List, byte[], byte[])public static Directory createWithNodeSubspace(Subspace node_subspace)
DirectoryLayer formed with a specified node subspace and default content subspace.
Prefixes can not be specified in calls to Directory.create(TransactionContext, List, byte[], byte[]).node_subspace - a Subspace used to store directory metadataDirectoryLayer formed with node_subspace and a default content subspacepublic static Directory createWithContentSubspace(Subspace content_subspace)
DirectoryLayer formed with a default node subspace and specified content subspace.
Prefixes can not be specified in calls to Directory.create(TransactionContext, List, byte[], byte[]).content_subspace - a Subspace used to store directory contentDirectoryLayer formed with a content_subspace and a default node subspacepublic static DirectoryLayer getDefault()
Directory.create(TransactionContext, List, byte[], byte[]).DirectoryLayerpublic boolean equals(Object rhs)
DirectoryLayer is equal to rhs.
Two DirectoryLayers are equal if they have the same node subspace,
content subspace, and path.public List<String> getPath()
DirectoryLayer. Normally constructed
DirectoryLayers have an empty path, but DirectoryLayers returned by
Directory.getDirectoryLayer() for Directorys inside of a partition
could have non-empty paths.public byte[] getLayer()
DirectoryLayer, which is always an empty
array.public DirectoryLayer getDirectoryLayer()
this.getDirectoryLayer in interface Directorythispublic Future<DirectorySubspace> createOrOpen(TransactionContext tcx, List<String> path)
path (creating parent directories, if necessary).createOrOpen in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a pathFuture which will be set to the created or opened DirectorySubspacepublic Future<DirectorySubspace> createOrOpen(TransactionContext tcx, List<String> path, byte[] layer)
path(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 Future can be set to the following errors:
MismatchedLayerException - if the directory has already been created with a different layer byte stringcreateOrOpen in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a pathlayer - a byte[] specifying a layer to set on a new directory or check for on an existing directoryFuture which will be set to the created or opened DirectorySubspacepublic Future<DirectorySubspace> open(ReadTransactionContext tcx, List<String> path)
path.
The returned Future can be set to the following errors:
NoSuchDirectoryException - if the directory does not existopen in interface Directorytcx - the ReadTransactionContext to execute this operation inpath - a List<String> specifying a pathFuture which will be set to the opened DirectorySubspacepublic Future<DirectorySubspace> open(ReadTransactionContext tcx, List<String> path, byte[] layer)
path.
The layer byte string will be compared against the layer set when
the directory was created.
The returned Future can be set to the following errors:
MismatchedLayerException - if the directory was created with a different layer byte stringNoSuchDirectoryException - if the directory does not existopen in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a pathlayer - a byte[] specifying the expected layerFuture which will be set to the opened DirectorySubspacepublic Future<DirectorySubspace> create(TransactionContext tcx, List<String> path)
path (creating parent directories if necessary).
The returned Future can be set to the following errors:
DirectoryAlreadyExistsException - if the given directory already existscreate in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a pathFuture which will be set to the created DirectorySubspacepublic Future<DirectorySubspace> create(TransactionContext tcx, List<String> path, byte[] layer)
path (creating parent directories if necessary).
The layer byte string will be recorded as the new directory's layer and checked by
future calls to open(ReadTransactionContext, List, byte[]).
The returned Future can be set to the following errors:
DirectoryAlreadyExistsException - if the given directory already existscreate in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a path of this Directorylayer - a byte[] specifying a layer to set for the directoryFuture which will be set to the created DirectorySubspacepublic Future<DirectorySubspace> create(TransactionContext tcx, List<String> path, byte[] layer, byte[] prefix)
path (creating parent directories if necessary).
The layer byte string will be recorded as the new directory's layer and checked by
future calls to open(ReadTransactionContext, List, byte[]). The specified prefix
will be used for this directory's contents instead of allocating a prefix automatically.
The returned Future can be set to the following errors:
DirectoryAlreadyExistsException - if the given directory already existscreate in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a path of this Directorylayer - a byte[] specifying a layer to set for the directoryprefix - a byte[] specifying the key prefix to use for the directory's contentsFuture which will be set to the created DirectorySubspacepublic Future<DirectorySubspace> moveTo(TransactionContext tcx, List<String> newAbsolutePath)
DirectoryLayer. Calling this method will result in the returned
Future being set to a DirectoryMoveException.
The returned Future can be set to the following errors:
moveTo in interface Directorytcx - the TransactionContext to execute this operation innewAbsolutePath - a List<String> specifying a pathFuture which will be set to a DirectoryMoveExceptionpublic Future<DirectorySubspace> move(TransactionContext tcx, List<String> oldPath, List<String> newPath)
oldPath to newPath.
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:
The returned Future can be set to the following errors:
NoSuchDirectoryException - if no Directory exists at oldPathDirectoryAlreadyExistsException - if a directory already exists at newPathDirectoryMoveException - if an invalid move location is specifiedmove in interface Directorytcx - the TransactionContext to execute this operation inoldPath - a List<String> specifying the path of the directory to movenewPath - a List<String> specifying the path to move toFuture which will be set to the DirectorySubspace for this Directory
at its new location.public Future<Void> remove(TransactionContext tcx)
Future being set to a DirectoryException.
The returned Future can be set to the following errors:
remove in interface Directorytcx - the TransactionContext to execute this operation inFuture which will be set to a DirectoryExceptionpublic Future<Void> remove(TransactionContext tcx, List<String> path)
path 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 Future can be set to the following errors:
NoSuchDirectoryException - if no directory exists at pathremove in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a pathFuture which will be set once the Directory has been removedpublic Future<Boolean> removeIfExists(TransactionContext tcx)
Future being set to a DirectoryException.
The returned Future can be set to the following errors:
removeIfExists in interface Directorytcx - the TransactionContext to execute this operation inFuture which will be set to a DirectoryExceptionpublic Future<Boolean> removeIfExists(TransactionContext tcx, List<String> path)
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.
removeIfExists in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a pathFuture which will be set to true once the Directory has been removed,
or false if it didn't exist.public Future<List<String>> list(ReadTransactionContext tcx)
list in interface Directorytcx - the ReadTransactionContext to execute this operation inFuture which will be set to a List<String> of names of the subdirectories
of the root directory. Each name is a unicode string representing the last component of a
subdirectory's path.public Future<List<String>> list(ReadTransactionContext tcx, List<String> path)
path.
The returned Future can be set to the following errors:
NoSuchDirectoryException - if no directory exists at pathlist in interface Directorytcx - the ReadTransactionContext to execute this operation inpath - a List<String> specifying a pathFuture which will be set to a List<String> of names of the subdirectories
of the directory at path. Each name is a unicode string representing the last component
of a subdirectory's path.public Future<Boolean> exists(ReadTransactionContext tcx)
true.exists in interface Directorytcx - the TransactionContext to execute this operation intruepublic Future<Boolean> exists(ReadTransactionContext tcx, List<String> path)
path exists.exists in interface Directorytcx - the TransactionContext to execute this operation inpath - a List<String> specifying a path of this DirectoryFuture which will be set to true if the specified directory exists, or false if it
doesn't