Class SFBaseFileTransferAgent

  • All Implemented Interfaces:
    SnowflakeFixedView
    Direct Known Subclasses:
    SnowflakeFileTransferAgent

    public abstract class SFBaseFileTransferAgent
    extends Object
    implements SnowflakeFixedView
    Base class for file transfers: given a SnowflakeConnection, files may be uploaded or downloaded from/to an InputStream.

    Note that while SnowflakeFileTransferAgent is used liberally throughout the codebase for performing uploads, the "alternative" implementations may have quite different ways of uploading to cloud storage, so this is a rather "thin" abstract class that leaves much of the implementation up to the implementing class.

    It is also expected that a command (GET/PUT) is parsed by the FileTransferAgent before either execute() or downloadStream() is called. This is not enforced by the abstract class's interface, but will be passed to the SFConnectionHandler's getFileTransferAgent().

    In general, besides the abstract methods execute() and downloadStream(), an implementing class needs to also populate the statusRows List with the file-metadata rows forming the fixed view, as well as set the showEncryptionParameter boolean (usually returned by the session parameter; default is false).

    • Field Detail

      • compressSourceFromStream

        protected boolean compressSourceFromStream
      • destStagePath

        protected String destStagePath
      • destFileNameForStreamSource

        protected String destFileNameForStreamSource
      • sourceFromStream

        protected boolean sourceFromStream
      • showEncryptionParameter

        protected boolean showEncryptionParameter
    • Constructor Detail

      • SFBaseFileTransferAgent

        public SFBaseFileTransferAgent()
    • Method Detail

      • getTotalRows

        public int getTotalRows()
        Gets the total number of rows that this GET/PUT command's output returns in the fixed-view result. The statusRows list must be populated with the FileMetadata.
        Specified by:
        getTotalRows in interface SnowflakeFixedView
        Returns:
        The number of rows that this fixed-view represents.
      • getNextRow

        public List<Object> getNextRow()
                                throws Exception
        Move on to the next row of file metadata. The statusRows list must be populated with the file-metadata output of the GET/PUT command.
        Specified by:
        getNextRow in interface SnowflakeFixedView
        Returns:
        The row, represented as a list of Object.
        Throws:
        Exception
      • setSourceStream

        public void setSourceStream​(InputStream sourceStream)
        Sets the source data stream to be uploaded.
        Parameters:
        sourceStream - The source data to upload.
      • setDestStagePath

        public void setDestStagePath​(String destStagePath)
        Sets the destination stage path
        Parameters:
        destStagePath - The target destination stage path.
      • setDestFileNameForStreamSource

        public void setDestFileNameForStreamSource​(String destFileNameForStreamSource)
        Sets the target filename for uploading
        Parameters:
        destFileNameForStreamSource - The target destination filename once the file is uploaded.
      • setCompressSourceFromStream

        public void setCompressSourceFromStream​(boolean compressSourceFromStream)
        Whether to compress the source stream before upload.
        Parameters:
        compressSourceFromStream - boolean for whether to compress the data stream before upload.
      • execute

        public abstract boolean execute()
                                 throws SQLException
        Run the PUT/GET command, if a command has been set.
        Returns:
        Whether the operation was completed successfully, and completely.
        Throws:
        SQLException - for SQL or upload errors
      • downloadStream

        public abstract InputStream downloadStream​(String fileName)
                                            throws SnowflakeSQLException
        Download data from a stage.
        Parameters:
        fileName - A file on a stage to download.
        Returns:
        An InputStream for the requested file.
        Throws:
        SnowflakeSQLException - If the file does not exist, or if an error occurred during transport.