Package org.apache.calcite.avatica
Class AvaticaConnection
java.lang.Object
org.apache.calcite.avatica.AvaticaConnection
- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper
Implementation of JDBC connection
for the Avatica framework.
Abstract to allow newer versions of JDBC to add methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA Callable-like interface but without a "throws Exception".static classA way to call package-protected methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final UnregisteredDriverprotected final AvaticaFactoryfinal Meta.ConnectionHandlestatic final Helperfinal Stringprotected final Propertiesprotected final longprotected final Metaprotected final AvaticaSpecificDatabaseMetaDatastatic final Stringstatic final Stringstatic final StringThe name of the sole column returned by an EXPLAIN statement.final Map<InternalProperty,Object> static final StringThe name of the sole column returned by DML statements, containing the number of rows modified.protected intfinal Map<Integer,AvaticaStatement> protected final booleanFields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAvaticaConnection(UnregisteredDriver driver, AvaticaFactory factory, String url, Properties info) Creates an AvaticaConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidvoidvoidclose()voidcommit()config()Returns a view onto this connection's configuration properties.createArrayOf(String typeName, Object[] elements) protected ResultSetcreateResultSet(Meta.MetaResultSet metaResultSet, QueryState state) createStatement(int resultSetType, int resultSetConcurrency) createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct(String typeName, Object[] attributes) protected static AvaticaConnection.Trojanprotected long[]Executes a batch update using anAvaticaPreparedStatement.protected ResultSetexecuteQueryInternal(AvaticaStatement statement, Meta.Signature signature, Meta.Frame firstFrame, QueryState state, boolean isUpdate) Executes a prepared query, closing any previously open result set.booleanReturns or creates a slot whose state can be changed to cancel a statement.getClientInfo(String name) intintReturns the time zone of this connection.int<T> TInvokes the given "callable", retrying the call when the server responds with an error denoting that the connection is missing on the server.booleanisClosed()booleanbooleanisValid(int timeout) booleanisWrapperFor(Class<?> iface) protected AvaticaStatementCreates a statement wrapper around an existing handle.voidOpens the connection on the server.protected Meta.ExecuteResultprepareAndExecuteInternal(AvaticaStatement statement, String sql, long maxRowCount) protected Meta.ExecuteBatchResultprepareAndUpdateBatch(AvaticaStatement statement, List<String> queries) prepareCall(String sql) prepareCall(String sql, int resultSetType, int resultSetConcurrency) prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement(String sql) prepareStatement(String sql, int autoGeneratedKeys) prepareStatement(String sql, int[] columnIndexes) prepareStatement(String sql, int resultSetType, int resultSetConcurrency) prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement(String sql, String[] columnNames) voidreleaseSavepoint(Savepoint savepoint) voidrollback()voidvoidsetAutoCommit(boolean autoCommit) voidsetCatalog(String catalog) voidsetClientInfo(String name, String value) voidsetClientInfo(Properties properties) voidsetHoldability(int holdability) voidsetKerberosConnection(KerberosConnection kerberosConnection) voidsetNetworkTimeout(Executor executor, int milliseconds) voidsetReadOnly(boolean readOnly) setSavepoint(String name) voidvoidsetService(Service service) voidsetTransactionIsolation(int level) voidsetTypeMap(Map<String, Class<?>> map) <T> TMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Field Details
-
ROWCOUNT_COLUMN_NAME
The name of the sole column returned by DML statements, containing the number of rows modified.- See Also:
-
NUM_EXECUTE_RETRIES_KEY
- See Also:
-
NUM_EXECUTE_RETRIES_DEFAULT
- See Also:
-
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:
-
HELPER
-
statementCount
protected int statementCount -
id
-
handle
-
driver
-
factory
-
info
-
meta
-
metaData
-
properties
-
statementMap
-
maxRetriesPerExecute
protected final long maxRetriesPerExecute -
transparentReconnectEnabled
protected final boolean transparentReconnectEnabled
-
-
Constructor Details
-
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- Driverfactory- Factory for JDBC objectsurl- Server URLinfo- Other connection properties
-
-
Method Details
-
config
Returns a view onto this connection's configuration properties. Code in Avatica and derived projects should use this view rather than callingProperties.getProperty(String). Derived projects will almost certainly subclassConnectionConfigwith their own properties. -
openConnection
public void openConnection()Opens the connection on the server. -
checkOpen
- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQLin interfaceConnection- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
commit
- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException
-
isClosed
- Specified by:
isClosedin interfaceConnection- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaDatain interfaceConnection- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnlyin interfaceConnection- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnlyin interfaceConnection- Throws:
SQLException
-
setCatalog
- Specified by:
setCatalogin interfaceConnection- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalogin interfaceConnection- Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getWarnings
- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMapin interfaceConnection- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMapin interfaceConnection- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
getHoldability
- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
releaseSavepoint
- Specified by:
releaseSavepointin interfaceConnection- Throws:
SQLException
-
createStatement
public AvaticaStatement 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
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
createClob
- Specified by:
createClobin interfaceConnection- Throws:
SQLException
-
createBlob
- Specified by:
createBlobin interfaceConnection- Throws:
SQLException
-
createNClob
- Specified by:
createNClobin interfaceConnection- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXMLin interfaceConnection- Throws:
SQLException
-
isValid
- Specified by:
isValidin interfaceConnection- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOfin interfaceConnection- Throws:
SQLException
-
createStruct
- Specified by:
createStructin interfaceConnection- Throws:
SQLException
-
setSchema
- Specified by:
setSchemain interfaceConnection- Throws:
SQLException
-
getSchema
- Specified by:
getSchemain interfaceConnection- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
getTimeZone
Returns the time zone of this connection. Determines the offset applied when converting datetime values from the database intoTimestampvalues. -
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- Statementsignature- Prepared queryfirstFrame- First frame of rows, or null if we need to executestate- The state used to create the given resultisUpdate- Was the caller context viaPreparedStatement.executeUpdate().- Returns:
- Result set
- Throws:
SQLException- if a database error occurs
-
executeBatchUpdateInternal
Executes a batch update using anAvaticaPreparedStatement.- 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:
SQLExceptionNoSuchStatementException
-
prepareAndUpdateBatch
protected Meta.ExecuteBatchResult prepareAndUpdateBatch(AvaticaStatement statement, List<String> queries) throws NoSuchStatementException, SQLException - Throws:
NoSuchStatementExceptionSQLException
-
createResultSet
protected ResultSet createResultSet(Meta.MetaResultSet metaResultSet, QueryState state) throws SQLException - Throws:
SQLException
-
lookupStatement
Creates a statement wrapper around an existing handle.- Throws:
SQLException
-
createTrojan
-
getCancelFlag
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
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
-
getKerberosConnection
-
getService
-
setService
-