Class KeySpacePathWrapper

  • All Implemented Interfaces:
    KeySpacePath

    @API(MAINTAINED)
    public class KeySpacePathWrapper
    extends Object
    implements KeySpacePath
    Helper class to make it easy to create KeySpacePath wrapper implementations for use in 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);
     
    • 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 subdirectory dirName to the directory path.
        Specified by:
        add in interface KeySpacePath
        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 a value for a specific subdirectory dirName to the directory path.
        Specified by:
        add in interface KeySpacePath
        Parameters:
        dirName - the name of the subdirectory to add to the path
        value - the value to use for the subdirectory
        Returns:
        this path
      • getStoredValue

        @Deprecated
        @Nonnull
        public PathValue getStoredValue()
        Deprecated.
        Description copied from interface: KeySpacePath
        If this path was created via a call to pathFromKey or listAsync (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 interface KeySpacePath
        Returns:
        the value that was stored for the path element
      • 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 interface KeySpacePath
        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 of KeySpacePath entries, with the root of the path located at position 0.
        Specified by:
        flatten in interface KeySpacePath
        Returns:
        this path as a list
      • 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 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.

        Specified by:
        listAsync in interface KeySpacePath
        Parameters:
        context - the transaction in which to perform the listing
        subdirName - the name of the subdirectory that is to be listed
        range - 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 attempt
        scanProperties - 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 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.

        Specified by:
        listSubdirectoryAsync in interface KeySpacePath
        Parameters:
        context - the transaction in which to perform the listing
        subdirName - the name of the subdirectory that is to be listed
        range - 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 attempt
        scanProperties - details for how the scan should be performed
        Returns:
        a list of fully qualified paths for each value contained within this directory
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString​(@Nonnull
                               Tuple t)
        Description copied from interface: KeySpacePath
        String representation of this KeySpacePath that shows correspondences between original and resolved directory values in accordance with the input Tuple.
        Specified by:
        toString in interface KeySpacePath
        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