org.apache.calcite.avatica

## Class AvaticaConnection

- java.lang.Object
- - org.apache.calcite.avatica.AvaticaConnection

All Implemented Interfaces:
  AutoCloseable, Connection, Wrapper

    public abstract class AvaticaConnection
    extends Object
    implements Connection

Implementation of JDBC connection for the Avatica framework.

Abstract to allow newer versions of JDBC to add methods.

### Nested Class Summary

Nested Classes
`static interface` `AvaticaConnection.CallableWithoutException<T>` A Callable-like interface but without a "throws Exception".
`static class` `AvaticaConnection.Trojan` A way to call package-protected methods.

### Field Summary

Fields
`protected UnregisteredDriver` `driver`
`protected AvaticaFactory` `factory`
`Meta.ConnectionHandle` `handle`
`static Helper` `HELPER`
`String` `id`
`protected Properties` `info`
`protected long` `maxRetriesPerExecute`
`protected Meta` `meta`
`protected AvaticaSpecificDatabaseMetaData` `metaData`
`static String` `NUM_EXECUTE_RETRIES_DEFAULT`
`static String` `NUM_EXECUTE_RETRIES_KEY`
`static String` `PLAN_COLUMN_NAME` The name of the sole column returned by an EXPLAIN statement.
`Map<InternalProperty,Object>` `properties`
`static String` `ROWCOUNT_COLUMN_NAME` The name of the sole column returned by DML statements, containing the number of rows modified.
`protected int` `statementCount`
`Map<Integer,AvaticaStatement>` `statementMap`
`protected boolean` `transparentReconnectEnabled`

### Fields inherited from interface java.sql.Connection

`TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE`

### Constructor Summary

Constructors
`protected` `AvaticaConnection(UnregisteredDriver driver, AvaticaFactory factory, String url, Properties info)` Creates an AvaticaConnection.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `abort(Executor executor)`
`protected void` `checkOpen()`
`void` `clearWarnings()`
`void` `close()`
`void` `commit()`
`ConnectionConfig` `config()` Returns a view onto this connection's configuration properties.
`Array` `createArrayOf(String typeName, Object[] elements)`
`Blob` `createBlob()`
`Clob` `createClob()`
`NClob` `createNClob()`
`protected ResultSet` `createResultSet(Meta.MetaResultSet metaResultSet, QueryState state)`
`SQLXML` `createSQLXML()`
`AvaticaStatement` `createStatement()`
`Statement` `createStatement(int resultSetType, int resultSetConcurrency)`
`AvaticaStatement` `createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`Struct` `createStruct(String typeName, Object[] attributes)`
`protected static AvaticaConnection.Trojan` `createTrojan()`
`protected long[]` `executeBatchUpdateInternal(AvaticaPreparedStatement pstmt)` Executes a batch update using an `AvaticaPreparedStatement`.
`protected ResultSet` `executeQueryInternal(AvaticaStatement statement, Meta.Signature signature, Meta.Frame firstFrame, QueryState state, boolean isUpdate)` Executes a prepared query, closing any previously open result set.
`boolean` `getAutoCommit()`
`AtomicBoolean` `getCancelFlag(Meta.StatementHandle h)` Returns or creates a slot whose state can be changed to cancel a statement.
`String` `getCatalog()`
`Properties` `getClientInfo()`
`String` `getClientInfo(String name)`
`int` `getHoldability()`
`KerberosConnection` `getKerberosConnection()`
`DatabaseMetaData` `getMetaData()`
`int` `getNetworkTimeout()`
`String` `getSchema()`
`Service` `getService()`
`TimeZone` `getTimeZone()` Returns the time zone of this connection.
`int` `getTransactionIsolation()`
`Map<String,Class<?>>` `getTypeMap()`
`SQLWarning` `getWarnings()`
`<T> T` `invokeWithRetries(AvaticaConnection.CallableWithoutException<T> callable)` Invokes the given "callable", retrying the call when the server responds with an error denoting that the connection is missing on the server.
`boolean` `isClosed()`
`boolean` `isReadOnly()`
`boolean` `isValid(int timeout)`
`boolean` `isWrapperFor(Class<?> iface)`
`protected AvaticaStatement` `lookupStatement(Meta.StatementHandle h)` Creates a statement wrapper around an existing handle.
`String` `nativeSQL(String sql)`
`void` `openConnection()` Opens the connection on the server.
`protected Meta.ExecuteResult` `prepareAndExecuteInternal(AvaticaStatement statement, String sql, long maxRowCount)`
`protected Meta.ExecuteBatchResult` `prepareAndUpdateBatch(AvaticaStatement statement, List<String> queries)`
`CallableStatement` `prepareCall(String sql)`
`CallableStatement` `prepareCall(String sql, int resultSetType, int resultSetConcurrency)`
`CallableStatement` `prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`PreparedStatement` `prepareStatement(String sql)`
`PreparedStatement` `prepareStatement(String sql, int autoGeneratedKeys)`
`PreparedStatement` `prepareStatement(String sql, int[] columnIndexes)`
`PreparedStatement` `prepareStatement(String sql, int resultSetType, int resultSetConcurrency)`
`PreparedStatement` `prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`PreparedStatement` `prepareStatement(String sql, String[] columnNames)`
`void` `releaseSavepoint(Savepoint savepoint)`
`void` `rollback()`
`void` `rollback(Savepoint savepoint)`
`void` `setAutoCommit(boolean autoCommit)`
`void` `setCatalog(String catalog)`
`void` `setClientInfo(Properties properties)`
`void` `setClientInfo(String name, String value)`
`void` `setHoldability(int holdability)`
`void` `setKerberosConnection(KerberosConnection kerberosConnection)`
`void` `setNetworkTimeout(Executor executor, int milliseconds)`
`void` `setReadOnly(boolean readOnly)`
`Savepoint` `setSavepoint()`
`Savepoint` `setSavepoint(String name)`
`void` `setSchema(String schema)`
`void` `setService(Service service)`
`void` `setTransactionIsolation(int level)`
`void` `setTypeMap(Map<String,Class<?>> map)`
`<T> T` `unwrap(Class<T> iface)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### ROWCOUNT_COLUMN_NAME

    public static final String ROWCOUNT_COLUMN_NAME

The name of the sole column returned by DML statements, containing the number of rows modified.

See Also:
  Constant Field Values

#### NUM_EXECUTE_RETRIES_KEY

    public static final String NUM_EXECUTE_RETRIES_KEY

See Also:
  Constant Field Values

#### NUM_EXECUTE_RETRIES_DEFAULT

    public static final String NUM_EXECUTE_RETRIES_DEFAULT

See Also:
  Constant Field Values

#### PLAN_COLUMN_NAME

    public static final String PLAN_COLUMN_NAME

The name of the sole column returned by an EXPLAIN statement.

Actually Avatica does not care what this column is called, but here is a useful place to define a suggested value.

See Also:
  Constant Field Values

#### HELPER

    public static final Helper HELPER

#### statementCount

    protected int statementCount

#### id

    public final String id

#### handle

    public final Meta.ConnectionHandle handle

#### driver

    protected final UnregisteredDriver driver

#### factory

    protected final AvaticaFactory factory

#### info

    protected final Properties info

#### meta

    protected final Meta meta

#### metaData

    protected final AvaticaSpecificDatabaseMetaData metaData

#### properties

    public final Map<InternalProperty,Object> properties

#### statementMap

    public final Map<Integer,AvaticaStatement> statementMap

#### maxRetriesPerExecute

    protected final long maxRetriesPerExecute

#### transparentReconnectEnabled

    protected final boolean transparentReconnectEnabled

### Constructor Detail

#### AvaticaConnection

    protected AvaticaConnection(UnregisteredDriver driver,
                                AvaticaFactory factory,
                                String url,
                                Properties info)

Creates an AvaticaConnection.

Not public; method is called only from the driver or a derived class.

Parameters:
  `driver` - Driver
  `factory` - Factory for JDBC objects
  `url` - Server URL
  `info` - Other connection properties

### Method Detail

#### config

    public ConnectionConfig config()

Returns a view onto this connection's configuration properties. Code in Avatica and derived projects should use this view rather than calling `Properties.getProperty(String)`. Derived projects will almost certainly subclass `ConnectionConfig` with their own properties.

#### openConnection

    public void openConnection()

Opens the connection on the server.

#### checkOpen

    protected void checkOpen()
                      throws SQLException

Throws:
  `SQLException`

#### createStatement

    public AvaticaStatement createStatement()
                                     throws SQLException

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql)
                                       throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareCall

    public CallableStatement prepareCall(String sql)
                                  throws SQLException

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLException`

#### nativeSQL

    public String nativeSQL(String sql)
                     throws SQLException

Specified by:
  `nativeSQL` in interface `Connection`
Throws:
  `SQLException`

#### setAutoCommit

    public void setAutoCommit(boolean autoCommit)
                       throws SQLException

Specified by:
  `setAutoCommit` in interface `Connection`
Throws:
  `SQLException`

#### getAutoCommit

    public boolean getAutoCommit()
                          throws SQLException

Specified by:
  `getAutoCommit` in interface `Connection`
Throws:
  `SQLException`

#### commit

    public void commit()
                throws SQLException

Specified by:
  `commit` in interface `Connection`
Throws:
  `SQLException`

#### rollback

    public void rollback()
                  throws SQLException

Specified by:
  `rollback` in interface `Connection`
Throws:
  `SQLException`

#### close

    public void close()
               throws SQLException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Connection`
Throws:
  `SQLException`

#### isClosed

    public boolean isClosed()
                     throws SQLException

Specified by:
  `isClosed` in interface `Connection`
Throws:
  `SQLException`

#### getMetaData

    public DatabaseMetaData getMetaData()
                                 throws SQLException

Specified by:
  `getMetaData` in interface `Connection`
Throws:
  `SQLException`

#### setReadOnly

    public void setReadOnly(boolean readOnly)
                     throws SQLException

Specified by:
  `setReadOnly` in interface `Connection`
Throws:
  `SQLException`

#### isReadOnly

    public boolean isReadOnly()
                       throws SQLException

Specified by:
  `isReadOnly` in interface `Connection`
Throws:
  `SQLException`

#### setCatalog

    public void setCatalog(String catalog)
                    throws SQLException

Specified by:
  `setCatalog` in interface `Connection`
Throws:
  `SQLException`

#### getCatalog

    public String getCatalog()
                      throws SQLException

Specified by:
  `getCatalog` in interface `Connection`
Throws:
  `SQLException`

#### setTransactionIsolation

    public void setTransactionIsolation(int level)
                                 throws SQLException

Specified by:
  `setTransactionIsolation` in interface `Connection`
Throws:
  `SQLException`

#### getTransactionIsolation

    public int getTransactionIsolation()
                                throws SQLException

Specified by:
  `getTransactionIsolation` in interface `Connection`
Throws:
  `SQLException`

#### getWarnings

    public SQLWarning getWarnings()
                           throws SQLException

Specified by:
  `getWarnings` in interface `Connection`
Throws:
  `SQLException`

#### clearWarnings

    public void clearWarnings()
                       throws SQLException

Specified by:
  `clearWarnings` in interface `Connection`
Throws:
  `SQLException`

#### createStatement

    public Statement createStatement(int resultSetType,
                                     int resultSetConcurrency)
                              throws SQLException

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareCall

    public CallableStatement prepareCall(String sql,
                                         int resultSetType,
                                         int resultSetConcurrency)
                                  throws SQLException

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLException`

#### getTypeMap

    public Map<String,Class<?>> getTypeMap()
                                    throws SQLException

Specified by:
  `getTypeMap` in interface `Connection`
Throws:
  `SQLException`

#### setTypeMap

    public void setTypeMap(Map<String,Class<?>> map)
                    throws SQLException

Specified by:
  `setTypeMap` in interface `Connection`
Throws:
  `SQLException`

#### setHoldability

    public void setHoldability(int holdability)
                        throws SQLException

Specified by:
  `setHoldability` in interface `Connection`
Throws:
  `SQLException`

#### getHoldability

    public int getHoldability()
                       throws SQLException

Specified by:
  `getHoldability` in interface `Connection`
Throws:
  `SQLException`

#### setSavepoint

    public Savepoint setSavepoint()
                           throws SQLException

Specified by:
  `setSavepoint` in interface `Connection`
Throws:
  `SQLException`

#### setSavepoint

    public Savepoint setSavepoint(String name)
                           throws SQLException

Specified by:
  `setSavepoint` in interface `Connection`
Throws:
  `SQLException`

#### rollback

    public void rollback(Savepoint savepoint)
                  throws SQLException

Specified by:
  `rollback` in interface `Connection`
Throws:
  `SQLException`

#### releaseSavepoint

    public void releaseSavepoint(Savepoint savepoint)
                          throws SQLException

Specified by:
  `releaseSavepoint` in interface `Connection`
Throws:
  `SQLException`

#### createStatement

    public AvaticaStatement createStatement(int resultSetType,
                                            int resultSetConcurrency,
                                            int resultSetHoldability)
                                     throws SQLException

Specified by:
  `createStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability)
                                       throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareCall

    public CallableStatement prepareCall(String sql,
                                         int resultSetType,
                                         int resultSetConcurrency,
                                         int resultSetHoldability)
                                  throws SQLException

Specified by:
  `prepareCall` in interface `Connection`
Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int autoGeneratedKeys)
                                       throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int[] columnIndexes)
                                       throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              String[] columnNames)
                                       throws SQLException

Specified by:
  `prepareStatement` in interface `Connection`
Throws:
  `SQLException`

#### createClob

    public Clob createClob()
                    throws SQLException

Specified by:
  `createClob` in interface `Connection`
Throws:
  `SQLException`

#### createBlob

    public Blob createBlob()
                    throws SQLException

Specified by:
  `createBlob` in interface `Connection`
Throws:
  `SQLException`

#### createNClob

    public NClob createNClob()
                      throws SQLException

Specified by:
  `createNClob` in interface `Connection`
Throws:
  `SQLException`

#### createSQLXML

    public SQLXML createSQLXML()
                        throws SQLException

Specified by:
  `createSQLXML` in interface `Connection`
Throws:
  `SQLException`

#### isValid

    public boolean isValid(int timeout)
                    throws SQLException

Specified by:
  `isValid` in interface `Connection`
Throws:
  `SQLException`

#### setClientInfo

    public void setClientInfo(String name,
                              String value)
                       throws SQLClientInfoException

Specified by:
  `setClientInfo` in interface `Connection`
Throws:
  `SQLClientInfoException`

#### setClientInfo

    public void setClientInfo(Properties properties)
                       throws SQLClientInfoException

Specified by:
  `setClientInfo` in interface `Connection`
Throws:
  `SQLClientInfoException`

#### getClientInfo

    public String getClientInfo(String name)
                         throws SQLException

Specified by:
  `getClientInfo` in interface `Connection`
Throws:
  `SQLException`

#### getClientInfo

    public Properties getClientInfo()
                             throws SQLException

Specified by:
  `getClientInfo` in interface `Connection`
Throws:
  `SQLException`

#### createArrayOf

    public Array createArrayOf(String typeName,
                               Object[] elements)
                        throws SQLException

Specified by:
  `createArrayOf` in interface `Connection`
Throws:
  `SQLException`

#### createStruct

    public Struct createStruct(String typeName,
                               Object[] attributes)
                        throws SQLException

Specified by:
  `createStruct` in interface `Connection`
Throws:
  `SQLException`

#### setSchema

    public void setSchema(String schema)
                   throws SQLException

Specified by:
  `setSchema` in interface `Connection`
Throws:
  `SQLException`

#### getSchema

    public String getSchema()
                     throws SQLException

Specified by:
  `getSchema` in interface `Connection`
Throws:
  `SQLException`

#### abort

    public void abort(Executor executor)
               throws SQLException

Specified by:
  `abort` in interface `Connection`
Throws:
  `SQLException`

#### setNetworkTimeout

    public void setNetworkTimeout(Executor executor,
                                  int milliseconds)
                           throws SQLException

Specified by:
  `setNetworkTimeout` in interface `Connection`
Throws:
  `SQLException`

#### getNetworkTimeout

    public int getNetworkTimeout()
                          throws SQLException

Specified by:
  `getNetworkTimeout` in interface `Connection`
Throws:
  `SQLException`

#### unwrap

    public <T> T unwrap(Class<T> iface)
                 throws SQLException

Specified by:
  `unwrap` in interface `Wrapper`
Throws:
  `SQLException`

#### isWrapperFor

    public boolean isWrapperFor(Class<?> iface)
                         throws SQLException

Specified by:
  `isWrapperFor` in interface `Wrapper`
Throws:
  `SQLException`

#### getTimeZone

    public TimeZone getTimeZone()

Returns the time zone of this connection. Determines the offset applied when converting datetime values from the database into `Timestamp` values.

#### executeQueryInternal

    protected ResultSet executeQueryInternal(AvaticaStatement statement,
                                             Meta.Signature signature,
                                             Meta.Frame firstFrame,
                                             QueryState state,
                                             boolean isUpdate)
                                      throws SQLException

Executes a prepared query, closing any previously open result set.

Parameters:
  `statement` - Statement
  `signature` - Prepared query
  `firstFrame` - First frame of rows, or null if we need to execute
  `state` - The state used to create the given result
  `isUpdate` - Was the caller context via `PreparedStatement.executeUpdate()`.
Returns:
  Result set
Throws:
  `SQLException` - if a database error occurs

#### executeBatchUpdateInternal

    protected long[] executeBatchUpdateInternal(AvaticaPreparedStatement pstmt)
                                         throws SQLException

Executes a batch update using an `AvaticaPreparedStatement`.

Parameters:
  `pstmt` - The prepared statement.
Returns:
  An array of update counts containing one element for each command in the batch.
Throws:
  `SQLException`

#### prepareAndExecuteInternal

    protected Meta.ExecuteResult prepareAndExecuteInternal(AvaticaStatement statement,
                                                           String sql,
                                                           long maxRowCount)
                                                    throws SQLException,
                                                           NoSuchStatementException

Throws:
  `SQLException`
  `NoSuchStatementException`

#### prepareAndUpdateBatch

    protected Meta.ExecuteBatchResult prepareAndUpdateBatch(AvaticaStatement statement,
                                                            List<String> queries)
                                                     throws NoSuchStatementException,
                                                            SQLException

Throws:
  `NoSuchStatementException`
  `SQLException`

#### createResultSet

    protected ResultSet createResultSet(Meta.MetaResultSet metaResultSet,
                                        QueryState state)
                                 throws SQLException

Throws:
  `SQLException`

#### lookupStatement

    protected AvaticaStatement lookupStatement(Meta.StatementHandle h)
                                        throws SQLException

Creates a statement wrapper around an existing handle.

Throws:
  `SQLException`

#### createTrojan

    protected static AvaticaConnection.Trojan createTrojan()

#### getCancelFlag

    public AtomicBoolean getCancelFlag(Meta.StatementHandle h)
                                throws NoSuchStatementException

Returns or creates a slot whose state can be changed to cancel a statement. Statements will receive the same slot if and only if their id is the same.

Throws:
  `NoSuchStatementException`

#### invokeWithRetries

    public <T> T invokeWithRetries(AvaticaConnection.CallableWithoutException<T> callable)

Invokes the given "callable", retrying the call when the server responds with an error denoting that the connection is missing on the server.

Parameters:
  `callable` - The function to invoke.
Returns:
  The value from the result of the callable.

#### setKerberosConnection

    public void setKerberosConnection(KerberosConnection kerberosConnection)

#### getKerberosConnection

    public KerberosConnection getKerberosConnection()

#### getService

    public Service getService()

#### setService

    public void setService(Service service)