Class KeySpacePathWrapper
- java.lang.Object
-
- com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePathWrapper
-
- All Implemented Interfaces:
KeySpacePath
@API(MAINTAINED) public class KeySpacePathWrapper extends Object implements KeySpacePath
Helper class to make it easy to createKeySpacePath
wrapper implementations for use inKeySpaceDirectory(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 theemployee
directory and another around itsphone
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);
-
-
Field Summary
Fields Modifier and Type Field Description protected KeySpacePath
inner
-
Constructor Summary
Constructors Constructor Description KeySpacePathWrapper(KeySpacePath inner)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description KeySpacePath
add(String dirName)
Adds the constant value for subdirectorydirName
to the directory path.KeySpacePath
add(String dirName, Object value)
Adds avalue
for a specific subdirectorydirName
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 ofKeySpacePath
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 toKeySpacePath.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 aResolvedKeySpacePath
, 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 thisKeySpacePath
that shows correspondences between original and resolved directory values in accordance with the inputTuple
.CompletableFuture<Tuple>
toTupleAsync(FDBRecordContext context)
Converts this path into a tuple.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath
deleteAllData, hasData, list, list, list, listAsync, listSubdirectory, listSubdirectory, listSubdirectory, listSubdirectory, listSubdirectoryAsync, size, toResolvedPath, toSubspace, toSubspaceAsync, toTuple
-
-
-
-
Field Detail
-
inner
protected KeySpacePath inner
-
-
Constructor Detail
-
KeySpacePathWrapper
public KeySpacePathWrapper(KeySpacePath inner)
-
-
Method Detail
-
add
@Nonnull public KeySpacePath add(@Nonnull String dirName)
Description copied from interface:KeySpacePath
Adds the constant value for subdirectorydirName
to the directory path.- Specified by:
add
in interfaceKeySpacePath
- Parameters:
dirName
- the name of the subdirectory to add to the path- Returns:
- this path
-
add
@Nonnull public KeySpacePath add(@Nonnull String dirName, @Nullable Object value)
Description copied from interface:KeySpacePath
Adds avalue
for a specific subdirectorydirName
to the directory path.- Specified by:
add
in interfaceKeySpacePath
- Parameters:
dirName
- the name of the subdirectory to add to the pathvalue
- the value to use for the subdirectory- Returns:
- this path
-
getRemainder
@Deprecated @Nullable public Tuple getRemainder()
Deprecated.Description copied from interface:KeySpacePath
If this path was created viaKeySpace.pathFromKey(FDBRecordContext, Tuple)
, this returns any remaining portion of the input tuple that was not used to construct the path.- Specified by:
getRemainder
in interfaceKeySpacePath
- Returns:
- the remaining portion of the original input tuple or
null
-
getParent
@Nullable public KeySpacePath getParent()
Description copied from interface:KeySpacePath
Returns the parent of this entry or null if this is the root of the path.- Specified by:
getParent
in interfaceKeySpacePath
- Returns:
- the parent keyspace path
-
getDirectoryName
@Nonnull public String getDirectoryName()
Description copied from interface:KeySpacePath
Returns the directory name for this path element.- Specified by:
getDirectoryName
in interfaceKeySpacePath
- Returns:
- the directory name
-
getDirectory
@Nonnull public KeySpaceDirectory getDirectory()
Description copied from interface:KeySpacePath
Returns the directory that corresponds to this path entry.- Specified by:
getDirectory
in interfaceKeySpacePath
- Returns:
- returns the directory that corresponds to this path entry
-
getValue
public Object getValue()
Description copied from interface:KeySpacePath
Returns the value that was provided when toKeySpacePath.add(String, Object)
when this path was constructed. Note that for some directory types, such asDirectoryLayerDirectory
, this may not be the value that is actually stored at this path element. For that, useKeySpacePath.resolveAsync(FDBRecordContext)
.- Specified by:
getValue
in interfaceKeySpacePath
- Returns:
- the path value
-
getStoredValue
@Deprecated @Nonnull public PathValue getStoredValue()
Deprecated.Description copied from interface:KeySpacePath
If this path was created via a call topathFromKey
orlistAsync
(or their blocking variants), this method may be used to determine what the underlying value was physically stored in the key.- Specified by:
getStoredValue
in interfaceKeySpacePath
- Returns:
- the value that was stored for the path element
-
hasStoredValue
@Deprecated public boolean hasStoredValue()
Deprecated.- Specified by:
hasStoredValue
in interfaceKeySpacePath
- Returns:
- true if it is legal to call
KeySpacePath.getStoredValue()
.
-
resolveAsync
@Nonnull public CompletableFuture<PathValue> resolveAsync(@Nonnull FDBRecordContext context)
Description copied from interface:KeySpacePath
Retrieve the value that is to be stored for this directory entry. For example, if the directory associated with this entry is aDirectoryLayerDirectory
the value returned will be the number assigned by the directory layer for this path entry's value.- Specified by:
resolveAsync
in interfaceKeySpacePath
- Parameters:
context
- the context in which to resolve the value- Returns:
- future that will resolve to value to be store for this path element. Note that if the path
was produced via
KeySpace.pathFromKeyAsync(FDBRecordContext, Tuple)
orKeySpacePath.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)
-
toTupleAsync
@Nonnull public CompletableFuture<Tuple> toTupleAsync(@Nonnull FDBRecordContext context)
Description copied from interface:KeySpacePath
Converts this path into a tuple. During this process the value that was provided for the directory, or was resolved by the directory implementation, is validated to ensure that it is a valid type for the directory.- Specified by:
toTupleAsync
in interfaceKeySpacePath
- Parameters:
context
- the context in which the path is to be resolved- Returns:
- a future that will complete to the tuple representation of this path
-
flatten
@Nonnull public List<KeySpacePath> flatten()
Description copied from interface:KeySpacePath
Flattens the path into a list ofKeySpacePath
entries, with the root of the path located at position 0.- Specified by:
flatten
in interfaceKeySpacePath
- Returns:
- this path as a list
-
hasDataAsync
@Nonnull public CompletableFuture<Boolean> hasDataAsync(@Nonnull FDBRecordContext context)
Description copied from interface:KeySpacePath
Check whether data exists for this path.- Specified by:
hasDataAsync
in interfaceKeySpacePath
- Parameters:
context
- the context in which the path is resolved and a scan is performed looking for data- Returns:
- a future that evaluates to
true
if data exists for this path
-
deleteAllDataAsync
@Nonnull public CompletableFuture<Void> deleteAllDataAsync(@Nonnull FDBRecordContext context)
Description copied from interface:KeySpacePath
Delete all data from this path. Use with care.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.
- Specified by:
deleteAllDataAsync
in interfaceKeySpacePath
- Parameters:
context
- the context in which the path is resolved and the delete operation takes place- Returns:
- a future that will delete all data underneath of this path
-
listAsync
@Deprecated @Nonnull public RecordCursor<KeySpacePath> listAsync(@Nonnull FDBRecordContext context, @Nonnull String subdirName, @Nullable ValueRange<?> range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
Deprecated.Description copied from interface:KeySpacePath
For a given subdirectory from this path element, return a list of paths for all available keys in the FDB keyspace for that directory. For example, given the tree:root +- node +- leaf
Performing alistAsync
from a givennode
, will result in a list of paths, one for eachleaf
that is available within thenode
'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 returnedKeySpacePath
may contain a remainder (seeKeySpacePath.getRemainder()
) of the portion of the key tuple that was read.- Specified by:
listAsync
in interfaceKeySpacePath
- Parameters:
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 isnull
. If the directory is restricted to a specific constant value, it has to benull
continuation
- an optional continuation from a previous list attemptscanProperties
- details for how the scan should be performed- Returns:
- a list of fully qualified paths for each value contained within this directory
-
listSubdirectoryAsync
@Nonnull public RecordCursor<ResolvedKeySpacePath> listSubdirectoryAsync(@Nonnull FDBRecordContext context, @Nonnull String subdirName, @Nullable ValueRange<?> range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
Description copied from interface:KeySpacePath
For a given subdirectory from this path element, return a list of paths for all available keys in the FDB keyspace for that directory. For example, given the tree:root +- dirA +- dirB +- dirC
Performing alistSubdirectoryAsync
fromdirA
for subdirectorydirB
will path to each distinct value ofdirB
.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 returnedResolvedKeySpacePath
may contain a remainder (seeResolvedKeySpacePath.getRemainder()
) of the portion of the key tuple that was read. In the above example, each unique value ofdirB
would contain a remainderTuple
of the first value ofdirC
.- Specified by:
listSubdirectoryAsync
in interfaceKeySpacePath
- Parameters:
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 isnull
. If the directory is restricted to a specific constant value, it has to benull
continuation
- an optional continuation from a previous list attemptscanProperties
- details for how the scan should be performed- Returns:
- a list of fully qualified paths for each value contained within this directory
-
toResolvedPathAsync
@Nonnull public CompletableFuture<ResolvedKeySpacePath> toResolvedPathAsync(@Nonnull FDBRecordContext context)
Description copied from interface:KeySpacePath
Resolves the path into aResolvedKeySpacePath
, a form the retains all of the information about the path itself along with the value to which each path entry is resolved.- Specified by:
toResolvedPathAsync
in interfaceKeySpacePath
- Parameters:
context
- the context in which the path is to be resolved- Returns:
- the resolved path
-
toString
public String toString(@Nonnull Tuple t)
Description copied from interface:KeySpacePath
String representation of thisKeySpacePath
that shows correspondences between original and resolved directory values in accordance with the inputTuple
.- Specified by:
toString
in interfaceKeySpacePath
- Parameters:
t
- representing the directory values of this path in resolved form- Returns:
- a string representation of the path that shows both original and resolved directory values
-
-