Class SFBaseFileTransferAgent
- java.lang.Object
-
- net.snowflake.client.jdbc.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).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SFBaseFileTransferAgent.CommandType
The types of file transfer: upload and download.class
SFBaseFileTransferAgent.DownloadCommandEncryptionFacade
class
SFBaseFileTransferAgent.DownloadCommandFacade
A class for encapsulating the columns to return for the download commandstatic class
SFBaseFileTransferAgent.UploadColumns
A class for encapsulating the columns to return for the upload commandclass
SFBaseFileTransferAgent.UploadCommandEncryptionFacade
class
SFBaseFileTransferAgent.UploadCommandFacade
-
Field Summary
Fields Modifier and Type Field Description protected SFBaseFileTransferAgent.CommandType
commandType
protected boolean
compressSourceFromStream
protected String
destFileNameForStreamSource
protected String
destStagePath
protected boolean
showEncryptionParameter
protected boolean
sourceFromStream
protected InputStream
sourceStream
protected List<Object>
statusRows
-
Constructor Summary
Constructors Constructor Description SFBaseFileTransferAgent()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description List<SnowflakeColumnMetadata>
describeColumns(SFBaseSession session)
Describe the metadata of a fixed view.abstract InputStream
downloadStream(String fileName)
Download data from a stage.abstract boolean
execute()
Run the PUT/GET command, if a command has been set.List<Object>
getNextRow()
Move on to the next row of file metadata.int
getTotalRows()
Gets the total number of rows that this GET/PUT command's output returns in the fixed-view result.void
setCompressSourceFromStream(boolean compressSourceFromStream)
Whether to compress the source stream before upload.void
setDestFileNameForStreamSource(String destFileNameForStreamSource)
Sets the target filename for uploadingvoid
setDestStagePath(String destStagePath)
Sets the destination stage pathvoid
setSourceStream(InputStream sourceStream)
Sets the source data stream to be uploaded.
-
-
-
Field Detail
-
compressSourceFromStream
protected boolean compressSourceFromStream
-
destStagePath
protected String destStagePath
-
destFileNameForStreamSource
protected String destFileNameForStreamSource
-
sourceStream
protected InputStream sourceStream
-
sourceFromStream
protected boolean sourceFromStream
-
showEncryptionParameter
protected boolean showEncryptionParameter
-
commandType
protected SFBaseFileTransferAgent.CommandType commandType
-
-
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 interfaceSnowflakeFixedView
- 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 interfaceSnowflakeFixedView
- Returns:
- The row, represented as a list of Object.
- Throws:
Exception
-
describeColumns
public List<SnowflakeColumnMetadata> describeColumns(SFBaseSession session) throws Exception
Describe the metadata of a fixed view.- Specified by:
describeColumns
in interfaceSnowflakeFixedView
- Returns:
- list of column meta data
- Throws:
Exception
- failed to construct list
-
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.
-
-