Package com.databricks.jdbc.api.impl
Class DatabricksStatement
- java.lang.Object
-
- com.databricks.jdbc.api.impl.DatabricksStatement
-
- All Implemented Interfaces:
IDatabricksStatement,IDatabricksStatementInternal,AutoCloseable,Statement,Wrapper
- Direct Known Subclasses:
DatabricksPreparedStatement
public class DatabricksStatement extends Object implements IDatabricksStatement, IDatabricksStatementInternal
-
-
Field Summary
Fields Modifier and Type Field Description protected DatabricksConnectionconnectionprotected BooleanshouldReturnResultSet-
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
-
-
Constructor Summary
Constructors Constructor Description DatabricksStatement(DatabricksConnection connection)DatabricksStatement(DatabricksConnection connection, StatementId statementId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBatch(String sql)voidallowInputStreamForVolumeOperation(boolean allowInputStream)voidcancel()voidclearBatch()voidclearWarnings()voidclose()voidclose(boolean removeFromSession)voidcloseOnCompletion()StringenquoteIdentifier(String identifier, boolean alwaysQuote)StringenquoteLiteral(String val)StringenquoteNCharLiteral(String val)booleanexecute(String sql)booleanexecute(String sql, int autoGeneratedKeys)booleanexecute(String sql, int[] columnIndexes)booleanexecute(String sql, String[] columnNames)ResultSetexecuteAsync(String sql)Executes the given SQL command asynchronously and returns a lightweight result set handle.int[]executeBatch()long[]executeLargeBatch()longexecuteLargeUpdate(String sql)longexecuteLargeUpdate(String sql, int autoGeneratedKeys)longexecuteLargeUpdate(String sql, int[] columnIndexes)longexecuteLargeUpdate(String sql, String[] columnNames)ResultSetexecuteQuery(String sql)intexecuteUpdate(String sql)intexecuteUpdate(String sql, int autoGeneratedKeys)intexecuteUpdate(String sql, int[] columnIndexes)intexecuteUpdate(String sql, String[] columnNames)ConnectiongetConnection()ResultSetgetExecutionResult()Retrieves the result set for a previously executed statement.intgetFetchDirection()intgetFetchSize()ResultSetgetGeneratedKeys()org.apache.http.entity.InputStreamEntitygetInputStreamForUCVolume()longgetLargeMaxRows()longgetLargeUpdateCount()intgetMaxFieldSize()intgetMaxRows()booleangetMoreResults()booleangetMoreResults(int current)intgetQueryTimeout()ResultSetgetResultSet()intgetResultSetConcurrency()intgetResultSetHoldability()intgetResultSetType()StatementgetStatement()StatementIdgetStatementId()intgetUpdateCount()SQLWarninggetWarnings()voidhandleResultSetClose(IDatabricksResultSet resultSet)booleanisAllowedInputStreamForVolumeOperation()booleanisClosed()booleanisCloseOnCompletion()booleanisPoolable()booleanisSimpleIdentifier(String identifier)booleanisWrapperFor(Class<?> iface)voidmarkAsClosed()Marks the statement as closed without attempting to close it on the server or clean up local resources.voidsetCursorName(String name)voidsetEscapeProcessing(boolean enable)voidsetFetchDirection(int direction)voidsetFetchSize(int rows)voidsetInputStreamForUCVolume(org.apache.http.entity.InputStreamEntity inputStream)voidsetLargeMaxRows(long max)voidsetMaxFieldSize(int max)voidsetMaxRows(int max)voidsetPoolable(boolean poolable)voidsetQueryTimeout(int seconds)voidsetStatementId(StatementId statementId)protected booleanshouldReturnResultSetWithConfig(String query)StringtoString()<T> Tunwrap(Class<T> iface)
-
-
-
Field Detail
-
connection
protected final DatabricksConnection connection
-
shouldReturnResultSet
protected Boolean shouldReturnResultSet
-
-
Constructor Detail
-
DatabricksStatement
public DatabricksStatement(DatabricksConnection connection) throws DatabricksValidationException
- Throws:
DatabricksValidationException
-
DatabricksStatement
public DatabricksStatement(DatabricksConnection connection, StatementId statementId) throws DatabricksValidationException
- Throws:
DatabricksValidationException
-
-
Method Detail
-
executeQuery
public ResultSet executeQuery(String sql) throws SQLException
- Specified by:
executeQueryin interfaceStatement- Throws:
SQLException
-
executeUpdate
public int executeUpdate(String sql) throws SQLException
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
public long executeLargeUpdate(String sql) throws SQLException
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
close
public void close() throws SQLException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Throws:
SQLException
-
close
public void close(boolean removeFromSession) throws DatabricksSQLException- Specified by:
closein interfaceIDatabricksStatementInternal- Throws:
DatabricksSQLException
-
getMaxFieldSize
public int getMaxFieldSize() throws SQLException- Specified by:
getMaxFieldSizein interfaceStatement- Throws:
SQLException
-
setMaxFieldSize
public void setMaxFieldSize(int max) throws SQLException- Specified by:
setMaxFieldSizein interfaceStatement- Throws:
SQLException
-
getMaxRows
public int getMaxRows() throws DatabricksSQLException- Specified by:
getMaxRowsin interfaceIDatabricksStatementInternal- Specified by:
getMaxRowsin interfaceStatement- Throws:
DatabricksSQLException
-
getLargeMaxRows
public long getLargeMaxRows() throws DatabricksSQLException- Specified by:
getLargeMaxRowsin interfaceStatement- Throws:
DatabricksSQLException
-
setMaxRows
public void setMaxRows(int max) throws SQLException- Specified by:
setMaxRowsin interfaceStatement- Throws:
SQLException
-
setLargeMaxRows
public void setLargeMaxRows(long max) throws SQLException- Specified by:
setLargeMaxRowsin interfaceStatement- Throws:
SQLException
-
setEscapeProcessing
public void setEscapeProcessing(boolean enable) throws SQLException- Specified by:
setEscapeProcessingin interfaceStatement- Throws:
SQLException
-
getQueryTimeout
public int getQueryTimeout() throws SQLException- Specified by:
getQueryTimeoutin interfaceStatement- Throws:
SQLException
-
setQueryTimeout
public void setQueryTimeout(int seconds) throws SQLException- Specified by:
setQueryTimeoutin interfaceStatement- Throws:
SQLException
-
cancel
public void cancel() throws SQLException- Specified by:
cancelin interfaceStatement- Throws:
SQLException
-
getWarnings
public SQLWarning getWarnings()
- Specified by:
getWarningsin interfaceStatement
-
clearWarnings
public void clearWarnings()
- Specified by:
clearWarningsin interfaceStatement
-
setCursorName
public void setCursorName(String name) throws SQLException
- Specified by:
setCursorNamein interfaceStatement- Throws:
SQLException
-
execute
public boolean execute(String sql) throws SQLException
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
getResultSet
public ResultSet getResultSet() throws SQLException
- Specified by:
getResultSetin interfaceStatement- Throws:
SQLException
-
getUpdateCount
public int getUpdateCount() throws SQLException- Specified by:
getUpdateCountin interfaceStatement- Throws:
SQLException
-
getLargeUpdateCount
public long getLargeUpdateCount() throws SQLException- Specified by:
getLargeUpdateCountin interfaceStatement- Throws:
SQLException
-
getMoreResults
public boolean getMoreResults() throws SQLException- Specified by:
getMoreResultsin interfaceStatement- Throws:
SQLException
-
setFetchDirection
public void setFetchDirection(int direction) throws SQLException- Specified by:
setFetchDirectionin interfaceStatement- Throws:
SQLException
-
getFetchDirection
public int getFetchDirection() throws SQLException- Specified by:
getFetchDirectionin interfaceStatement- Throws:
SQLException
-
setFetchSize
public void setFetchSize(int rows)
- Specified by:
setFetchSizein interfaceStatement
-
getFetchSize
public int getFetchSize()
- Specified by:
getFetchSizein interfaceStatement
-
getResultSetConcurrency
public int getResultSetConcurrency() throws SQLException- Specified by:
getResultSetConcurrencyin interfaceStatement- Throws:
SQLException
-
getResultSetType
public int getResultSetType() throws SQLException- Specified by:
getResultSetTypein interfaceStatement- Throws:
SQLException
-
addBatch
public void addBatch(String sql) throws SQLException
- Specified by:
addBatchin interfaceStatement- Throws:
SQLException
-
clearBatch
public void clearBatch() throws SQLException- Specified by:
clearBatchin interfaceStatement- Throws:
SQLException
-
executeBatch
public int[] executeBatch() throws SQLException- Specified by:
executeBatchin interfaceStatement- Throws:
SQLException
-
executeLargeBatch
public long[] executeLargeBatch() throws SQLException- Specified by:
executeLargeBatchin interfaceStatement- Throws:
SQLException
-
getConnection
public Connection getConnection() throws SQLException
- Specified by:
getConnectionin interfaceStatement- Throws:
SQLException
-
getMoreResults
public boolean getMoreResults(int current) throws SQLException- Specified by:
getMoreResultsin interfaceStatement- Throws:
SQLException
-
getGeneratedKeys
public ResultSet getGeneratedKeys() throws SQLException
- Specified by:
getGeneratedKeysin interfaceStatement- Throws:
SQLException
-
executeUpdate
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeUpdate
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
executeUpdate
public int executeUpdate(String sql, String[] columnNames) throws SQLException
- Specified by:
executeUpdatein interfaceStatement- Throws:
SQLException
-
executeLargeUpdate
public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException
- Specified by:
executeLargeUpdatein interfaceStatement- Throws:
SQLException
-
execute
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
execute
public boolean execute(String sql, int[] columnIndexes) throws SQLException
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
execute
public boolean execute(String sql, String[] columnNames) throws SQLException
- Specified by:
executein interfaceStatement- Throws:
SQLException
-
getResultSetHoldability
public int getResultSetHoldability()
- Specified by:
getResultSetHoldabilityin interfaceStatement
-
isClosed
public boolean isClosed() throws SQLException- Specified by:
isClosedin interfaceStatement- Throws:
SQLException
-
setPoolable
public void setPoolable(boolean poolable) throws SQLException- Specified by:
setPoolablein interfaceStatement- Throws:
SQLException
-
isPoolable
public boolean isPoolable() throws SQLException- Specified by:
isPoolablein interfaceStatement- Throws:
SQLException
-
closeOnCompletion
public void closeOnCompletion() throws SQLException- Specified by:
closeOnCompletionin interfaceStatement- Throws:
SQLException
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws SQLException- Specified by:
isCloseOnCompletionin interfaceStatement- Throws:
SQLException
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
handleResultSetClose
public void handleResultSetClose(IDatabricksResultSet resultSet) throws DatabricksSQLException
- Specified by:
handleResultSetClosein interfaceIDatabricksStatementInternal- Throws:
DatabricksSQLException
-
setStatementId
public void setStatementId(StatementId statementId)
- Specified by:
setStatementIdin interfaceIDatabricksStatementInternal
-
getStatementId
public StatementId getStatementId()
- Specified by:
getStatementIdin interfaceIDatabricksStatementInternal
-
getStatement
public Statement getStatement()
- Specified by:
getStatementin interfaceIDatabricksStatementInternal
-
allowInputStreamForVolumeOperation
public void allowInputStreamForVolumeOperation(boolean allowInputStream) throws DatabricksSQLException- Specified by:
allowInputStreamForVolumeOperationin interfaceIDatabricksStatementInternal- Throws:
DatabricksSQLException
-
isAllowedInputStreamForVolumeOperation
public boolean isAllowedInputStreamForVolumeOperation() throws DatabricksSQLException- Specified by:
isAllowedInputStreamForVolumeOperationin interfaceIDatabricksStatementInternal- Throws:
DatabricksSQLException
-
setInputStreamForUCVolume
public void setInputStreamForUCVolume(org.apache.http.entity.InputStreamEntity inputStream) throws DatabricksSQLException- Specified by:
setInputStreamForUCVolumein interfaceIDatabricksStatementInternal- Throws:
DatabricksSQLException
-
getInputStreamForUCVolume
public org.apache.http.entity.InputStreamEntity getInputStreamForUCVolume() throws DatabricksSQLException- Specified by:
getInputStreamForUCVolumein interfaceIDatabricksStatementInternal- Throws:
DatabricksSQLException
-
executeAsync
public ResultSet executeAsync(String sql) throws SQLException
Description copied from interface:IDatabricksStatementExecutes the given SQL command asynchronously and returns a lightweight result set handle. This method initiates the execution but does not wait for it to complete, making it suitable for long-running queries. The actual results can be retrieved later usingIDatabricksStatement.getExecutionResult().- Specified by:
executeAsyncin interfaceIDatabricksStatement- Parameters:
sql- The SQL command to be executed- Returns:
- A
ResultSethandle that can be used to track and retrieve the results - Throws:
SQLException- if a database access error occurs, this method is called on a closed statement, or the SQL command is not valid
-
getExecutionResult
public ResultSet getExecutionResult() throws SQLException
Description copied from interface:IDatabricksStatementRetrieves the result set for a previously executed statement. This method should be called after executing a statement usingIDatabricksStatement.executeAsync(String)to get the actual results.- Specified by:
getExecutionResultin interfaceIDatabricksStatement- Returns:
- A
ResultSetcontaining the results of the statement execution in case of successful completion, else handle for the result status. - Throws:
SQLException- if the statement was never executed, has been closed, or if a database access error occurs
-
enquoteLiteral
public String enquoteLiteral(String val) throws SQLException
- Specified by:
enquoteLiteralin interfaceStatement- Throws:
SQLException
-
enquoteIdentifier
public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws DatabricksSQLException
- Specified by:
enquoteIdentifierin interfaceStatement- Throws:
DatabricksSQLException
-
enquoteNCharLiteral
public String enquoteNCharLiteral(String val) throws SQLException
- Specified by:
enquoteNCharLiteralin interfaceStatement- Throws:
SQLException
-
isSimpleIdentifier
public boolean isSimpleIdentifier(String identifier) throws SQLException
- Specified by:
isSimpleIdentifierin interfaceStatement- Throws:
SQLException
-
shouldReturnResultSetWithConfig
protected boolean shouldReturnResultSetWithConfig(String query)
-
markAsClosed
public void markAsClosed()
Marks the statement as closed without attempting to close it on the server or clean up local resources. This should be used when the server has already indicated the statement is closed.This method sets the closed flag to prevent further operations, but defers resource cleanup (result set, executor) to the
close(boolean)method. Whenclose()is subsequently called, it will detect the statement is already closed and skip the server-side close operation while still cleaning up local resources.- See Also:
close(boolean)
-
-