Package com.databend.jdbc
Class DatabendConnection
- java.lang.Object
-
- com.databend.jdbc.DatabendConnection
-
- All Implemented Interfaces:
DatabendConnectionExtension,FileTransferAPI,AutoCloseable,Connection,Wrapper,Consumer<com.databend.client.DatabendSession>
public class DatabendConnection extends Object implements Connection, DatabendConnectionExtension, FileTransferAPI, Consumer<com.databend.client.DatabendSession>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.databend.jdbc.DatabendConnectionExtension
DatabendConnectionExtension.LoadMethod
-
-
Field Summary
-
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort(Executor executor)voidaccept(com.databend.client.DatabendSession session)voidclearWarnings()voidclose()voidcommit()voidcopyIntoTable(String database, String tableName, DatabendCopyParams params)Copy into the target table from files on the internal stage Documentation: ...ArraycreateArrayOf(String s, Object[] objects)BlobcreateBlob()ClobcreateClob()NClobcreateNClob()SQLXMLcreateSQLXML()StatementcreateStatement()StatementcreateStatement(int resultSetType, int resultSetConcurrency)StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)StructcreateStruct(String s, Object[] objects)InputStreamdownloadStream(String stageName, String path)Download a file from the databend internal stage, the data would be downloaded as one file with no split.InputStreamdownloadStream(String stageName, String path, boolean decompress)Deprecated. UsedownloadStream(String, String)instead.booleangetAutoCommit()StringgetCatalog()PropertiesgetClientInfo()StringgetClientInfo(String s)intgetHoldability()intgetMaxFailoverRetries()DatabaseMetaDatagetMetaData()intgetNetworkTimeout()StringgetSchema()intgetTransactionIsolation()Map<String,Class<?>>getTypeMap()URIgetURI()SQLWarninggetWarnings()booleanisClosed()booleanisReadOnly()booleanisValid(int i)booleanisWrapperFor(Class<?> aClass)intloadStreamToTable(String sql, InputStream inputStream, long fileSize, DatabendConnectionExtension.LoadMethod loadMethod)Loads data from an input stream directly into a target Databend table using the specified SQL command.StringnativeSQL(String sql)CallableStatementprepareCall(String s)CallableStatementprepareCall(String s, int i, int i1)CallableStatementprepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)PreparedStatementprepareStatement(String s)PreparedStatementprepareStatement(String s, int autoGeneratedKeys)PreparedStatementprepareStatement(String s, int[] ints)PreparedStatementprepareStatement(String s, int i, int i1)PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)PreparedStatementprepareStatement(String s, String[] strings)voidreleaseSavepoint(Savepoint savepoint)voidrollback()voidrollback(Savepoint savepoint)voidsetAutoCommit(boolean b)voidsetCatalog(String s)voidsetClientInfo(String s, String s1)voidsetClientInfo(Properties properties)voidsetHoldability(int holdability)voidsetNetworkTimeout(Executor executor, int i)voidsetReadOnly(boolean b)SavepointsetSavepoint()SavepointsetSavepoint(String s)voidsetSchema(String schema)voidsetTransactionIsolation(int i)voidsetTypeMap(Map<String,Class<?>> map)<T> Tunwrap(Class<T> aClass)voiduploadStream(InputStream inputStream, String stageName, String destPrefix, String destFileName, long fileSize, boolean compressData)Upload inputStream to the databend internal stage, the data would be uploaded as one file with no split.voiduploadStream(String stageName, String destPrefix, InputStream inputStream, String destFileName, long fileSize, boolean compressData)Method to put data from a stream at a stage location.
-
-
-
Method Detail
-
createStatement
public Statement createStatement() throws SQLException
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String s) throws SQLException
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String s) throws SQLException
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
nativeSQL
public String nativeSQL(String sql) throws SQLException
- Specified by:
nativeSQLin interfaceConnection- Throws:
SQLException
-
commit
public void commit() throws SQLException- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
getAutoCommit
public boolean getAutoCommit() throws SQLException- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
setAutoCommit
public void setAutoCommit(boolean b) throws SQLException- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
rollback
public void rollback() throws SQLException- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
close
public void close() throws SQLException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException
-
isClosed
public boolean isClosed() throws SQLException- Specified by:
isClosedin interfaceConnection- Throws:
SQLException
-
getMetaData
public DatabaseMetaData getMetaData() throws SQLException
- Specified by:
getMetaDatain interfaceConnection- Throws:
SQLException
-
isReadOnly
public boolean isReadOnly() throws SQLException- Specified by:
isReadOnlyin interfaceConnection- Throws:
SQLException
-
setReadOnly
public void setReadOnly(boolean b) throws SQLException- Specified by:
setReadOnlyin interfaceConnection- Throws:
SQLException
-
getCatalog
public String getCatalog() throws SQLException
- Specified by:
getCatalogin interfaceConnection- Throws:
SQLException
-
setCatalog
public void setCatalog(String s) throws SQLException
- Specified by:
setCatalogin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
public int getTransactionIsolation() throws SQLException- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
setTransactionIsolation
public void setTransactionIsolation(int i) throws SQLException- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getWarnings
public SQLWarning getWarnings() throws SQLException
- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
clearWarnings
public void clearWarnings() throws SQLException- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String s, int i, int i1) throws SQLException
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String s, int i, int i1) throws SQLException
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
getTypeMap
public Map<String,Class<?>> getTypeMap() throws SQLException
- Specified by:
getTypeMapin interfaceConnection- Throws:
SQLException
-
setTypeMap
public void setTypeMap(Map<String,Class<?>> map) throws SQLException
- Specified by:
setTypeMapin interfaceConnection- Throws:
SQLException
-
getHoldability
public int getHoldability() throws SQLException- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
getMaxFailoverRetries
public int getMaxFailoverRetries()
-
setHoldability
@NotImplemented public void setHoldability(int holdability) throws SQLException
- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
setSavepoint
public Savepoint setSavepoint() throws SQLException
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
setSavepoint
public Savepoint setSavepoint(String s) throws SQLException
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
rollback
public void rollback(Savepoint savepoint) throws SQLException
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
releaseSavepoint
public void releaseSavepoint(Savepoint savepoint) throws SQLException
- Specified by:
releaseSavepointin interfaceConnection- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String s, int autoGeneratedKeys) throws SQLException
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String s, int[] ints) throws SQLException
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String s, String[] strings) throws SQLException
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
createClob
public Clob createClob() throws SQLException
- Specified by:
createClobin interfaceConnection- Throws:
SQLException
-
createBlob
public Blob createBlob() throws SQLException
- Specified by:
createBlobin interfaceConnection- Throws:
SQLException
-
createNClob
public NClob createNClob() throws SQLException
- Specified by:
createNClobin interfaceConnection- Throws:
SQLException
-
createSQLXML
public SQLXML createSQLXML() throws SQLException
- Specified by:
createSQLXMLin interfaceConnection- Throws:
SQLException
-
isValid
public boolean isValid(int i) throws SQLException- Specified by:
isValidin interfaceConnection- Throws:
SQLException
-
setClientInfo
public void setClientInfo(String s, String s1) throws SQLClientInfoException
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
getClientInfo
public String getClientInfo(String s) throws SQLException
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
getClientInfo
public Properties getClientInfo() throws SQLException
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
setClientInfo
public void setClientInfo(Properties properties) throws SQLClientInfoException
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
createArrayOf
public Array createArrayOf(String s, Object[] objects) throws SQLException
- Specified by:
createArrayOfin interfaceConnection- Throws:
SQLException
-
createStruct
public Struct createStruct(String s, Object[] objects) throws SQLException
- Specified by:
createStructin interfaceConnection- Throws:
SQLException
-
getSchema
public String getSchema() throws SQLException
- Specified by:
getSchemain interfaceConnection- Throws:
SQLException
-
setSchema
public void setSchema(String schema) throws SQLException
- Specified by:
setSchemain interfaceConnection- Throws:
SQLException
-
abort
public void abort(Executor executor) throws SQLException
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
public void setNetworkTimeout(Executor executor, int i) throws SQLException
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
public int getNetworkTimeout() throws SQLException- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
unwrap
public <T> T unwrap(Class<T> aClass) throws SQLException
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
public boolean isWrapperFor(Class<?> aClass) throws SQLException
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
getURI
public URI getURI()
-
accept
public void accept(com.databend.client.DatabendSession session)
-
uploadStream
public void uploadStream(InputStream inputStream, String stageName, String destPrefix, String destFileName, long fileSize, boolean compressData) throws SQLException
Description copied from interface:DatabendConnectionExtensionUpload inputStream to the databend internal stage, the data would be uploaded as one file with no split. Caller should close the input stream after the upload is done.- Specified by:
uploadStreamin interfaceDatabendConnectionExtension- Parameters:
inputStream- the input stream of the filestageName- the stage which receive uploaded filedestPrefix- the prefix of the file name in the stagedestFileName- the destination file name in the stagefileSize- the file size in the stagecompressData- whether to compress the data- Throws:
SQLException- failed to upload input stream
-
uploadStream
public void uploadStream(String stageName, String destPrefix, InputStream inputStream, String destFileName, long fileSize, boolean compressData) throws SQLException
Method to put data from a stream at a stage location. The data will be uploaded as one file. No splitting is done in this method.Stream size must match the total size of data in the input stream unless compressData parameter is set to true.
caller is responsible for passing the correct size for the data in the stream and releasing the inputStream after the method is called.
Note this method is deprecated since streamSize is not required now. Keep the function signature for backward compatibility
- Specified by:
uploadStreamin interfaceDatabendConnectionExtension- Specified by:
uploadStreamin interfaceFileTransferAPI- Parameters:
stageName- stage name: e.g. ~ or table name or stage namedestPrefix- path prefix under which the data should be uploaded on the stageinputStream- input stream from which the data will be uploadeddestFileName- destination file name to usefileSize- data size in the streamcompressData- whether to compress the data- Throws:
SQLException- failed to put data from a stream at stage
-
downloadStream
public InputStream downloadStream(String stageName, String path) throws SQLException
Description copied from interface:DatabendConnectionExtensionDownload a file from the databend internal stage, the data would be downloaded as one file with no split.- Specified by:
downloadStreamin interfaceDatabendConnectionExtension- Parameters:
stageName- the stage which contains the filepath- the file name in the stage- Returns:
- the input stream of the file
- Throws:
SQLException- failed to download input stream
-
downloadStream
public InputStream downloadStream(String stageName, String path, boolean decompress) throws SQLException
Description copied from interface:FileTransferAPIDeprecated. UsedownloadStream(String, String)instead. Download a file from the databend internal stage, the data would be downloaded as one file with no split.- Specified by:
downloadStreamin interfaceFileTransferAPI- Parameters:
stageName- the stage which contains the filepath- the file name in the stagedecompress- whether to decompress the data- Returns:
- the input stream of the file
- Throws:
SQLException- failed to download input stream
-
copyIntoTable
public void copyIntoTable(String database, String tableName, DatabendCopyParams params) throws SQLException
Description copied from interface:FileTransferAPICopy into the target table from files on the internal stage Documentation: ...- Specified by:
copyIntoTablein interfaceFileTransferAPI- Parameters:
database- the target table's databasetableName- the target table nameparams- copy options and file options- Throws:
SQLException- fail to copy into table
-
loadStreamToTable
public int loadStreamToTable(String sql, InputStream inputStream, long fileSize, DatabendConnectionExtension.LoadMethod loadMethod) throws SQLException
Description copied from interface:DatabendConnectionExtensionLoads data from an input stream directly into a target Databend table using the specified SQL command. Supports two loading strategies viaDatabendConnectionExtension.LoadMethod.- Specified by:
loadStreamToTablein interfaceDatabendConnectionExtension- Parameters:
sql- SQL command with Databend's load syntax:INSERT INTO <table> [(<columns>)] FROM @_databend_load [file_format=(...)]inputStream- Input stream containing the data to load into the tablefileSize- Size of the data (in bytes) to be loadedloadMethod- Loading strategy (DatabendConnectionExtension.LoadMethod.STAGEorDatabendConnectionExtension.LoadMethod.STREAMING)- Returns:
- Number of rows successfully loaded into the target table
- Throws:
SQLException- If the load operation fails (e.g., invalid SQL, stream errors, or data format issues)
-
-