@API(value=MAINTAINED) public class KeySpacePathWrapper extends Object implements KeySpacePath
KeySpacePath
wrapper implementations for use in
KeySpaceDirectory.KeySpaceDirectory(String, KeySpaceDirectory.KeyType, Object, java.util.function.Function)
(String, KeySpaceDirectory.KeyType, Object, Function)}.
Wrappers are most useful for making it easy for clients of the KeySpacePath API to work with path
elements using concrete method calls rather than logical directory names. For example:
public enum PhoneType { WORK, HOME, MOBILE } public class EmployeePath() extends KeySpacePathWrapper { public EmployeePath(KeySpacePath path) { super(path); } public PhonePath() phone(PhoneType phoneType) { return (PhonePath) inner.add("phone", phoneType.toString()); } public CorporateRoot parent() { return (CorporateRoot) inner.getParent(); } } public class PhonePath() extends KeySpacePathWrapper { public PhonePath(KeySpacePath path) { super(path); } public parent() { return (EmployeePath) inner.getParent(); } } public class CorporateRoot() { private KeySpace root = new KeySpace( new KeySpaceDirectory("employee", KeyType.UUID, EmployeePath::new) .addSubdirectory(new KeySpaceDirectory("phone", KeyType.STRING, PhonePath::new))); public EmployeePath employee(UUID uuid) { return (EmployeePath) root.path("employee", uuid); } }Here, we have created two wrappers, one around the
employee
directory and another around its
phone
subdirectory. Each of these wrappers will automatically wrap the actual path entry that is
returned when these directories are accessed and each decorate the path entry with methods that allow you to
explicitly refer to directories by method name and to perform type validate at compile time. For example:
CorporateRoot root = new CorporateRoot(); PhonePath phonePath = root.employee(myUuid).phone(PhoneType.WORK);
Modifier and Type | Field and Description |
---|---|
protected KeySpacePath |
inner |
Constructor and Description |
---|
KeySpacePathWrapper(KeySpacePath inner) |
Modifier and Type | Method and Description |
---|---|
KeySpacePath |
add(String dirName)
Adds the constant value for subdirectory
dirName to the directory path. |
KeySpacePath |
add(String dirName,
Object value)
Adds a
value for a specific subdirectory dirName to the directory path. |
CompletableFuture<Void> |
deleteAllDataAsync(FDBRecordContext context)
Delete all data from this path.
|
boolean |
equals(Object obj) |
List<KeySpacePath> |
flatten()
Flattens the path into a list of
KeySpacePath entries, with the root of the path
located at position 0. |
KeySpaceDirectory |
getDirectory()
Returns the directory that corresponds to this path entry.
|
String |
getDirectoryName()
Returns the directory name for this path element.
|
KeySpacePath |
getParent()
Returns the parent of this entry or null if this is the root of the path.
|
Tuple |
getRemainder()
Deprecated.
|
PathValue |
getStoredValue()
Deprecated.
|
Object |
getValue()
Returns the value that was provided when to
KeySpacePath.add(String, Object) when this path was constructed. |
CompletableFuture<Boolean> |
hasDataAsync(FDBRecordContext context)
Check whether data exists for this path.
|
int |
hashCode() |
boolean |
hasStoredValue()
Deprecated.
|
RecordCursor<KeySpacePath> |
listAsync(FDBRecordContext context,
String subdirName,
ValueRange<?> range,
byte[] continuation,
ScanProperties scanProperties)
Deprecated.
|
RecordCursor<ResolvedKeySpacePath> |
listSubdirectoryAsync(FDBRecordContext context,
String subdirName,
ValueRange<?> range,
byte[] continuation,
ScanProperties scanProperties)
For a given subdirectory from this path element, return a list of paths for all available keys in the FDB
keyspace for that directory.
|
CompletableFuture<PathValue> |
resolveAsync(FDBRecordContext context)
Retrieve the value that is to be stored for this directory entry.
|
CompletableFuture<ResolvedKeySpacePath> |
toResolvedPathAsync(FDBRecordContext context)
Resolves the path into a
ResolvedKeySpacePath , a form the retains all of the information about
the path itself along with the value to which each path entry is resolved. |
String |
toString() |
String |
toString(Tuple t)
String representation of this
KeySpacePath that shows correspondences between original and resolved
directory values in accordance with the input Tuple . |
CompletableFuture<Tuple> |
toTupleAsync(FDBRecordContext context)
Converts this path into a tuple.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
deleteAllData, hasData, list, list, list, listAsync, listSubdirectory, listSubdirectory, listSubdirectory, listSubdirectory, listSubdirectoryAsync, size, toResolvedPath, toSubspace, toSubspaceAsync, toTuple
protected KeySpacePath inner
public KeySpacePathWrapper(KeySpacePath inner)
@Nonnull public KeySpacePath add(@Nonnull String dirName)
KeySpacePath
dirName
to the directory path.add
in interface KeySpacePath
dirName
- the name of the subdirectory to add to the path@Nonnull public KeySpacePath add(@Nonnull String dirName, @Nullable Object value)
KeySpacePath
value
for a specific subdirectory dirName
to the directory path.add
in interface KeySpacePath
dirName
- the name of the subdirectory to add to the pathvalue
- the value to use for the subdirectory@Deprecated @Nullable public Tuple getRemainder()
KeySpacePath
KeySpace.pathFromKey(FDBRecordContext, Tuple)
, this returns
any remaining portion of the input tuple that was not used to construct the path.getRemainder
in interface KeySpacePath
null
@Nullable public KeySpacePath getParent()
KeySpacePath
getParent
in interface KeySpacePath
@Nonnull public String getDirectoryName()
KeySpacePath
getDirectoryName
in interface KeySpacePath
@Nonnull public KeySpaceDirectory getDirectory()
KeySpacePath
getDirectory
in interface KeySpacePath
public Object getValue()
KeySpacePath
KeySpacePath.add(String, Object)
when this path was constructed.
Note that for some directory types, such as DirectoryLayerDirectory
, this may not be the value
that is actually stored at this path element. For that, use KeySpacePath.resolveAsync(FDBRecordContext)
.getValue
in interface KeySpacePath
@Deprecated @Nonnull public PathValue getStoredValue()
KeySpacePath
pathFromKey
or listAsync
(or their blocking
variants), this method may be used to determine what the underlying value was physically stored in the key.getStoredValue
in interface KeySpacePath
@Deprecated public boolean hasStoredValue()
hasStoredValue
in interface KeySpacePath
KeySpacePath.getStoredValue()
.@Nonnull public CompletableFuture<PathValue> resolveAsync(@Nonnull FDBRecordContext context)
KeySpacePath
DirectoryLayerDirectory
the value returned will be the number assigned
by the directory layer for this path entry's value.resolveAsync
in interface KeySpacePath
context
- the context in which to resolve the valueKeySpace.pathFromKeyAsync(FDBRecordContext, Tuple)
or KeySpacePath.listAsync(FDBRecordContext, String, byte[], ScanProperties)
,
then the future that is returned will have already been completed (i.e it is safe to retrieve the
value without blocking)@Nonnull public CompletableFuture<Tuple> toTupleAsync(@Nonnull FDBRecordContext context)
KeySpacePath
toTupleAsync
in interface KeySpacePath
context
- the context in which the path is to be resolved@Nonnull public List<KeySpacePath> flatten()
KeySpacePath
KeySpacePath
entries, with the root of the path
located at position 0.flatten
in interface KeySpacePath
@Nonnull public CompletableFuture<Boolean> hasDataAsync(@Nonnull FDBRecordContext context)
KeySpacePath
hasDataAsync
in interface KeySpacePath
context
- the context in which the path is resolved and a scan is performed looking for datatrue
if data exists for this path@Nonnull public CompletableFuture<Void> deleteAllDataAsync(@Nonnull FDBRecordContext context)
KeySpacePath
Note that as it is possible that one or more record stores saved underneath this path might have cacheable meta-data, this method will reset the database's FDBRecordContext.getMetaDataVersionStampAsync(com.apple.foundationdb.record.IsolationLevel) meta-data version-stamp}. This can result in clients which are caching store state having to invalidate their caches.
deleteAllDataAsync
in interface KeySpacePath
context
- the context in which the path is resolved and the delete operation takes place@Deprecated @Nonnull public RecordCursor<KeySpacePath> listAsync(@Nonnull FDBRecordContext context, @Nonnull String subdirName, @Nullable ValueRange<?> range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
KeySpacePath
root +- node +- leafPerforming a
listAsync
from a given node
, will result in a list of paths, one for
each leaf
that is available within the node
's scope.
The listing is performed by reading the first key of the data type (and possibly constant value) for the
subdirectory and, if a key is found, skipping to the next available value after the first one that was found,
and so on, each time resulting in an additional KeySpacePath
that is returned. In each case,
the returned KeySpacePath
may contain a remainder (see KeySpacePath.getRemainder()
) of the portion
of the key tuple that was read.
listAsync
in interface KeySpacePath
context
- the transaction in which to perform the listingsubdirName
- the name of the subdirectory that is to be listedrange
- the range of the subdirectory values to be listed. All will be listed if it is null
.
If the directory is restricted to a specific constant value, it has to be null
continuation
- an optional continuation from a previous list attemptscanProperties
- details for how the scan should be performed@Nonnull public RecordCursor<ResolvedKeySpacePath> listSubdirectoryAsync(@Nonnull FDBRecordContext context, @Nonnull String subdirName, @Nullable ValueRange<?> range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
KeySpacePath
root +- dirA +- dirB +- dirCPerforming a
listSubdirectoryAsync
from dirA
for subdirectory dirB
will path to each distinct value of dirB
.
The listing is performed by reading the first key of the data type (and possibly constant value) for the
subdirectory and, if a key is found, skipping to the next available value after the first one that was found,
and so on, each time resulting in an additional ResolvedKeySpacePath
that is returned. In each case,
the returned ResolvedKeySpacePath
may contain a remainder (see ResolvedKeySpacePath.getRemainder()
)
of the portion of the key tuple that was read. In the above example, each unique value of dirB
would contain a remainder Tuple
of the first value of dirC
.
listSubdirectoryAsync
in interface KeySpacePath
context
- the transaction in which to perform the listingsubdirName
- the name of the subdirectory that is to be listedrange
- the range of the subdirectory values to be listed. All will be listed if it is null
.
If the directory is restricted to a specific constant value, it has to be null
continuation
- an optional continuation from a previous list attemptscanProperties
- details for how the scan should be performed@Nonnull public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBRecordContext context)
KeySpacePath
ResolvedKeySpacePath
, a form the retains all of the information about
the path itself along with the value to which each path entry is resolved.toResolvedPathAsync
in interface KeySpacePath
context
- the context in which the path is to be resolvedpublic String toString(@Nonnull Tuple t)
KeySpacePath
KeySpacePath
that shows correspondences between original and resolved
directory values in accordance with the input Tuple
.toString
in interface KeySpacePath
t
- representing the directory values of this path in resolved form