Package org.apache.calcite.avatica
Class AvaticaStatement
- java.lang.Object
-
- org.apache.calcite.avatica.AvaticaStatement
-
- All Implemented Interfaces:
java.lang.AutoCloseable,java.sql.Statement,java.sql.Wrapper
- Direct Known Subclasses:
AvaticaJdbc41Factory.AvaticaJdbc41Statement,AvaticaPreparedStatement
public abstract class AvaticaStatement extends java.lang.Object implements java.sql.StatementImplementation ofStatementfor the Avatica engine.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>batchedSqlprotected java.util.concurrent.atomic.AtomicBooleancancelFlagSupport forcancel()method.protected booleanclosedprotected booleancloseOnCompletionSupport forcloseOnCompletion()method.AvaticaConnectionconnectionstatic intDEFAULT_FETCH_SIZEThe default value forStatement.getFetchSize().private intfetchDirectionprivate intfetchSizeMeta.StatementHandlehandleStatement id; unique within connection.protected longmaxRowCountprotected AvaticaResultSetopenResultSetCurrent result set, or null if the statement is not executing anything.private intqueryTimeoutMillis(package private) intresultSetConcurrency(package private) intresultSetHoldability(package private) intresultSetTypeprivate Meta.Signaturesignatureprotected longupdateCountCurrent update count.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAvaticaStatement(AvaticaConnection connection, Meta.StatementHandle h, int resultSetType, int resultSetConcurrency, int resultSetHoldability)Creates an AvaticaStatement.protectedAvaticaStatement(AvaticaConnection connection, Meta.StatementHandle h, int resultSetType, int resultSetConcurrency, int resultSetHoldability, Meta.Signature signature)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBatch(java.lang.String sql)voidcancel()private voidcheckNotPreparedOrCallable(java.lang.String s)protected voidcheckOpen()voidclearBatch()voidclearWarnings()voidclose()protected voidclose_()voidcloseOnCompletion()booleanexecute(java.lang.String sql)booleanexecute(java.lang.String sql, int autoGeneratedKeys)booleanexecute(java.lang.String sql, int[] columnIndexes)booleanexecute(java.lang.String sql, java.lang.String[] columnNames)int[]executeBatch()protected long[]executeBatchInternal()Executes a collection of updates in a single batch RPC.protected voidexecuteInternal(java.lang.String sql)protected booleanexecuteInternal(Meta.Signature signature, boolean isUpdate)Executes a prepared statement.long[]executeLargeBatch()longexecuteLargeUpdate(java.lang.String sql)java.sql.ResultSetexecuteQuery(java.lang.String sql)protected java.sql.ResultSetexecuteQueryInternal(Meta.Signature signature, boolean isUpdate)Executes a prepared query, closing any previously open result set.intexecuteUpdate(java.lang.String sql)intexecuteUpdate(java.lang.String sql, int autoGeneratedKeys)intexecuteUpdate(java.lang.String sql, int[] columnIndexes)intexecuteUpdate(java.lang.String sql, java.lang.String[] columnNames)protected java.util.List<TypedValue>getBoundParameterValues()Returns a list of bound parameter values.AvaticaConnectiongetConnection()intgetFetchDirection()intgetFetchSize()java.sql.ResultSetgetGeneratedKeys()intgetId()Returns the identifier of the statement, unique within its connection.longgetLargeMaxRows()longgetLargeUpdateCount()intgetMaxFieldSize()intgetMaxRows()booleangetMoreResults()booleangetMoreResults(int current)protected java.util.List<TypedValue>getParameterValues()Returns the list of values of this statement's parameters.intgetQueryTimeout()(package private) intgetQueryTimeoutMillis()java.sql.ResultSetgetResultSet()intgetResultSetConcurrency()intgetResultSetHoldability()intgetResultSetType()protected Meta.SignaturegetSignature()Meta.StatementTypegetStatementType()intgetUpdateCount()java.sql.SQLWarninggetWarnings()booleanisClosed()booleanisCloseOnCompletion()booleanisPoolable()booleanisWrapperFor(java.lang.Class<?> iface)(package private) voidonResultSetClose(java.sql.ResultSet resultSet)Called by each child result set when it is closed.protected voidresetStatement()voidsetCursorName(java.lang.String name)voidsetEscapeProcessing(boolean enable)voidsetFetchDirection(int direction)voidsetFetchSize(int rows)voidsetLargeMaxRows(long maxRowCount)voidsetMaxFieldSize(int max)voidsetMaxRows(int maxRowCount)voidsetPoolable(boolean poolable)voidsetQueryTimeout(int seconds)(package private) voidsetQueryTimeoutMillis(int millis)protected voidsetSignature(Meta.Signature signature)protected booleansyncResults(QueryState state, long offset)Re-initialize the ResultSet on the server with the given state.<T> Tunwrap(java.lang.Class<T> iface)
-
-
-
Field Detail
-
DEFAULT_FETCH_SIZE
public static final int DEFAULT_FETCH_SIZE
The default value forStatement.getFetchSize().- See Also:
- Constant Field Values
-
connection
public final AvaticaConnection connection
-
handle
public Meta.StatementHandle handle
Statement id; unique within connection.
-
closed
protected boolean closed
-
cancelFlag
protected final java.util.concurrent.atomic.AtomicBoolean cancelFlag
Support forcancel()method.
-
closeOnCompletion
protected boolean closeOnCompletion
Support forcloseOnCompletion()method.
-
openResultSet
protected AvaticaResultSet openResultSet
Current result set, or null if the statement is not executing anything. Any method which modifies this member must synchronize on the AvaticaStatement.
-
updateCount
protected long updateCount
Current update count. Same lifecycle asopenResultSet.
-
queryTimeoutMillis
private int queryTimeoutMillis
-
resultSetType
final int resultSetType
-
resultSetConcurrency
final int resultSetConcurrency
-
resultSetHoldability
final int resultSetHoldability
-
fetchSize
private int fetchSize
-
fetchDirection
private int fetchDirection
-
maxRowCount
protected long maxRowCount
-
signature
private Meta.Signature signature
-
batchedSql
private final java.util.List<java.lang.String> batchedSql
-
-
Constructor Detail
-
AvaticaStatement
protected AvaticaStatement(AvaticaConnection connection, Meta.StatementHandle h, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
Creates an AvaticaStatement.- Parameters:
connection- Connectionh- Statement handleresultSetType- Result set typeresultSetConcurrency- Result set concurrencyresultSetHoldability- Result set holdability
-
AvaticaStatement
protected AvaticaStatement(AvaticaConnection connection, Meta.StatementHandle h, int resultSetType, int resultSetConcurrency, int resultSetHoldability, Meta.Signature signature)
-
-
Method Detail
-
setSignature
protected void setSignature(Meta.Signature signature)
-
getSignature
protected Meta.Signature getSignature()
-
getStatementType
public Meta.StatementType getStatementType()
-
getId
public int getId()
Returns the identifier of the statement, unique within its connection.
-
checkOpen
protected void checkOpen() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
checkNotPreparedOrCallable
private void checkNotPreparedOrCallable(java.lang.String s) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
executeInternal
protected void executeInternal(java.lang.String sql) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
executeBatchInternal
protected long[] executeBatchInternal() throws java.sql.SQLExceptionExecutes a collection of updates in a single batch RPC.- Returns:
- an array of long mapping to the update count per SQL command.
- Throws:
java.sql.SQLException
-
resetStatement
protected void resetStatement()
-
syncResults
protected boolean syncResults(QueryState state, long offset) throws NoSuchStatementException
Re-initialize the ResultSet on the server with the given state.- Parameters:
state- The ResultSet's state.offset- Offset into the desired ResultSet- Returns:
- True if the ResultSet has more results, false if there are no more results.
- Throws:
NoSuchStatementException
-
execute
public boolean execute(java.lang.String sql) throws java.sql.SQLException- Specified by:
executein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeQuery
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException- Specified by:
executeQueryin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeUpdate
public final int executeUpdate(java.lang.String sql) throws java.sql.SQLException- Specified by:
executeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql) throws java.sql.SQLException- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
close
public void close() throws java.sql.SQLException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
close_
protected void close_()
-
getMaxFieldSize
public int getMaxFieldSize() throws java.sql.SQLException- Specified by:
getMaxFieldSizein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setMaxFieldSize
public void setMaxFieldSize(int max) throws java.sql.SQLException- Specified by:
setMaxFieldSizein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getMaxRows
public final int getMaxRows() throws java.sql.SQLException- Specified by:
getMaxRowsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getLargeMaxRows
public long getLargeMaxRows() throws java.sql.SQLException- Specified by:
getLargeMaxRowsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setMaxRows
public final void setMaxRows(int maxRowCount) throws java.sql.SQLException- Specified by:
setMaxRowsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setLargeMaxRows
public void setLargeMaxRows(long maxRowCount) throws java.sql.SQLException- Specified by:
setLargeMaxRowsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setEscapeProcessing
public void setEscapeProcessing(boolean enable) throws java.sql.SQLException- Specified by:
setEscapeProcessingin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getQueryTimeout
public int getQueryTimeout() throws java.sql.SQLException- Specified by:
getQueryTimeoutin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getQueryTimeoutMillis
int getQueryTimeoutMillis()
-
setQueryTimeout
public void setQueryTimeout(int seconds) throws java.sql.SQLException- Specified by:
setQueryTimeoutin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setQueryTimeoutMillis
void setQueryTimeoutMillis(int millis)
-
cancel
public void cancel() throws java.sql.SQLException- Specified by:
cancelin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException- Specified by:
getWarningsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings() throws java.sql.SQLException- Specified by:
clearWarningsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setCursorName
public void setCursorName(java.lang.String name) throws java.sql.SQLException- Specified by:
setCursorNamein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getResultSet
public java.sql.ResultSet getResultSet() throws java.sql.SQLException- Specified by:
getResultSetin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getUpdateCount
public int getUpdateCount() throws java.sql.SQLException- Specified by:
getUpdateCountin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getLargeUpdateCount
public long getLargeUpdateCount() throws java.sql.SQLException- Specified by:
getLargeUpdateCountin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getMoreResults
public boolean getMoreResults() throws java.sql.SQLException- Specified by:
getMoreResultsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setFetchDirection
public void setFetchDirection(int direction) throws java.sql.SQLException- Specified by:
setFetchDirectionin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getFetchDirection
public int getFetchDirection() throws java.sql.SQLException- Specified by:
getFetchDirectionin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setFetchSize
public void setFetchSize(int rows) throws java.sql.SQLException- Specified by:
setFetchSizein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getFetchSize
public int getFetchSize() throws java.sql.SQLException- Specified by:
getFetchSizein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getResultSetConcurrency
public int getResultSetConcurrency() throws java.sql.SQLException- Specified by:
getResultSetConcurrencyin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getResultSetType
public int getResultSetType() throws java.sql.SQLException- Specified by:
getResultSetTypein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
addBatch
public void addBatch(java.lang.String sql) throws java.sql.SQLException- Specified by:
addBatchin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
clearBatch
public void clearBatch() throws java.sql.SQLException- Specified by:
clearBatchin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeBatch
public int[] executeBatch() throws java.sql.SQLException- Specified by:
executeBatchin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeLargeBatch
public long[] executeLargeBatch() throws java.sql.SQLException- Specified by:
executeLargeBatchin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getConnection
public AvaticaConnection getConnection() throws java.sql.SQLException
- Specified by:
getConnectionin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getMoreResults
public boolean getMoreResults(int current) throws java.sql.SQLException- Specified by:
getMoreResultsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getGeneratedKeys
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException- Specified by:
getGeneratedKeysin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeUpdate
public int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException- Specified by:
executeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeUpdate
public int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException- Specified by:
executeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeUpdate
public int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException- Specified by:
executeUpdatein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
execute
public boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException- Specified by:
executein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
execute
public boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException- Specified by:
executein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
execute
public boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException- Specified by:
executein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
getResultSetHoldability
public int getResultSetHoldability() throws java.sql.SQLException- Specified by:
getResultSetHoldabilityin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
isClosed
public boolean isClosed() throws java.sql.SQLException- Specified by:
isClosedin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setPoolable
public void setPoolable(boolean poolable) throws java.sql.SQLException- Specified by:
setPoolablein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
isPoolable
public boolean isPoolable() throws java.sql.SQLException- Specified by:
isPoolablein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
closeOnCompletion
public void closeOnCompletion() throws java.sql.SQLException- Specified by:
closeOnCompletionin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws java.sql.SQLException- Specified by:
isCloseOnCompletionin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrapin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
executeInternal
protected boolean executeInternal(Meta.Signature signature, boolean isUpdate) throws java.sql.SQLException
Executes a prepared statement.- Parameters:
signature- Parsed statementisUpdate- if the execute is for an update- Returns:
- as specified by
Statement.execute(String) - Throws:
java.sql.SQLException- if a database error occurs
-
executeQueryInternal
protected java.sql.ResultSet executeQueryInternal(Meta.Signature signature, boolean isUpdate) throws java.sql.SQLException
Executes a prepared query, closing any previously open result set.- Parameters:
signature- Parsed queryisUpdate- If the execute is for an update- Returns:
- Result set
- Throws:
java.sql.SQLException- if a database error occurs
-
onResultSetClose
void onResultSetClose(java.sql.ResultSet resultSet)
Called by each child result set when it is closed.- Parameters:
resultSet- Result set or cell set
-
getParameterValues
protected java.util.List<TypedValue> getParameterValues()
Returns the list of values of this statement's parameters.Called at execute time. Not a public API.
The default implementation returns the empty list, because non-prepared statements have no parameters.
-
getBoundParameterValues
protected java.util.List<TypedValue> getBoundParameterValues() throws java.sql.SQLException
Returns a list of bound parameter values.If any of the parameters have not been bound, throws. If parameters have been bound to null, the value in the list is null.
- Throws:
java.sql.SQLException
-
-