- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper,FirebirdConnection
FBConnection is a handle to a FBManagedConnection and implements Connection.
This class is internal API of Jaybird. Future versions may radically change, move, or make inaccessible this type.
For the public API, refer to the Connection and FirebirdConnection interfaces.
- Author:
- David Jencks, Mark Rotteveel
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FBManagedConnectionprotected final InternalTransactionCoordinatorFields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddWarning(SQLWarning warning) protected voidCheck if this connection is valid.voidvoidclose()voidcommit()Get database connection properties for this connection.createArrayOf(String typeName, Object[] elements) createStatement(int resultSetType, int resultSetConcurrency) createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) createStruct(String typeName, Object[] attributes) Create new instance ofTransactionParameterBuffer.protected voidThis method closes all active statements and cleans resources.booleangetClientInfo(String name) Provides access to the low-level connection handle.intReturns a FBLocalTransaction instance that enables a component to demarcate resource manager local transactions on this connection.intintgetTransactionParameters(int isolationLevel) Get transaction parameters for the specified transaction isolation level.protected voidInvalidate all savepoints.protected voidInvalidate everything that should only last for the lifetime of the current transaction.booleanisClosed()protected final booleanbooleanbooleanbooleanisValid(int timeout) booleanisWrapperFor(Class<?> iface) 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) protected PreparedStatementprepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, boolean metaData, boolean generatedKeys) prepareStatement(String sql, String[] columnNames) voidreleaseSavepoint(Savepoint savepoint) voidResets the known client info properties of this connection to the defaults.voidrollback()voidvoidsetAutoCommit(boolean autoCommit) voidsetCatalog(String catalog) voidsetClientInfo(String name, String value) voidsetClientInfo(Properties properties) voidsetHoldability(int holdability) voidSet theFBManagedConnectionaround which this connection is based.voidsetManagedEnvironment(boolean managedConnection) voidsetNetworkTimeout(Executor executor, int milliseconds) voidsetReadOnly(boolean readOnly) setSavepoint(String name) Creates a named savepoint.voidprotected voidsetTransactionCoordinator(boolean managedConnection, boolean autoCommit) voidsetTransactionIsolation(int level) voidsetTransactionParameters(int isolationLevel, int[] parameters) Deprecated.voidsetTransactionParameters(int isolationLevel, TransactionParameterBuffer tpb) Set transaction parameters for the specified transaction isolation level.voidSet transaction parameters for the next transactions.voidsetTypeMap(Map<String, Class<?>> map) <T> Tprotected final LockCloseablewithLock()Methods 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
-
mc
-
txCoordinator
-
activeStatements
-
-
Constructor Details
-
FBConnection
Create a new FBConnection instance based on aFBManagedConnection.- Parameters:
mc- A FBManagedConnection around which this connection is based
-
-
Method Details
-
getHoldability
- Specified by:
getHoldabilityin interfaceConnection- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldabilityin interfaceConnection- Throws:
SQLException
-
checkValidity
Check if this connection is valid. This method should be invoked before executing any action in this class.- Throws:
SQLException- if this connection has been closed and cannot be used anymore
-
freeStatements
This method closes all active statements and cleans resources.- Throws:
SQLException- if at least one of the active statements failed to close gracefully.
-
setManagedConnection
Set theFBManagedConnectionaround which this connection is based.- Parameters:
mc- The FBManagedConnection around which this connection is based
-
getManagedConnection
-
getFbDatabase
Description copied from interface:FirebirdConnectionProvides access to the low-level connection handle.WARNING using this connection handle directly may bring the JDBC connection in an inconsistent state.
- Specified by:
getFbDatabasein interfaceFirebirdConnection- Returns:
- The low-level connection handle.
- Throws:
SQLException
-
connectionProperties
Get database connection properties for this connection.- Returns:
- immutable instance of
DatabaseConnectionProperties.
-
setTransactionParameters
@Deprecated(since="2") public void setTransactionParameters(int isolationLevel, int[] parameters) throws SQLException Deprecated.Description copied from interface:FirebirdConnectionSet transaction parameters for the specified isolation level. They will take effect only on the newly started transaction.- Specified by:
setTransactionParametersin interfaceFirebirdConnection- Parameters:
isolationLevel- JDBC isolation level.parameters- array of TPB parameters, see all TPB_* constants.- Throws:
SQLException- if specified transaction parameters cannot be set.
-
getTransactionParameters
Description copied from interface:FirebirdConnectionGet transaction parameters for the specified transaction isolation level.- Specified by:
getTransactionParametersin interfaceFirebirdConnection- Parameters:
isolationLevel- isolation level defined in theConnectioninterface.- Returns:
- instance of
TransactionParameterBuffercontaining current transaction parameters. - Throws:
SQLException- if error occurred obtaining transaction parameters.
-
createTransactionParameterBuffer
Description copied from interface:FirebirdConnectionCreate new instance ofTransactionParameterBuffer.- Specified by:
createTransactionParameterBufferin interfaceFirebirdConnection- Returns:
- empty instance of
TransactionParameterBuffer. - Throws:
SQLException- if error occurred during this operation.
-
setTransactionParameters
public void setTransactionParameters(int isolationLevel, TransactionParameterBuffer tpb) throws SQLException Description copied from interface:FirebirdConnectionSet transaction parameters for the specified transaction isolation level.This method replaces the default TPB mapping with the specified one, changes will be effective from the next transaction start.
- Specified by:
setTransactionParametersin interfaceFirebirdConnectiontpb- instance ofTransactionParameterBufferwith parameters to set.- Throws:
SQLException- if error occurred during this operation.
-
setTransactionParameters
Description copied from interface:FirebirdConnectionSet transaction parameters for the next transactions.This method does not change the TPB mapping, but replaces the mapping for the current transaction isolation until
Connection.setTransactionIsolation(int)is called.This method cannot be called when a transaction is currently active.
- Specified by:
setTransactionParametersin interfaceFirebirdConnection- Parameters:
tpb- instance ofTransactionParameterBufferwith new transaction parameters.- Throws:
SQLException- if method is called within a transaction.
-
createStatement
- Specified by:
createStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
createBlob
Description copied from interface:FirebirdConnection- Specified by:
createBlobin interfaceConnection- Specified by:
createBlobin interfaceFirebirdConnection- Returns:
- instance of
FirebirdBlob. - Throws:
SQLException
-
createClob
- Specified by:
createClobin interfaceConnection- Throws:
SQLException
-
createStruct
- Specified by:
createStructin interfaceConnection- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOfin interfaceConnection- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQLin interfaceConnection- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceConnection- Throws:
SQLException
-
setTransactionCoordinator
protected void setTransactionCoordinator(boolean managedConnection, boolean autoCommit) throws SQLException - Throws:
SQLException
-
setManagedEnvironment
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommitin interfaceConnection- Throws:
SQLException
-
commit
- Specified by:
commitin interfaceConnection- Throws:
SQLException
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
invalidateTransactionLifetimeObjects
protected void invalidateTransactionLifetimeObjects()Invalidate everything that should only last for the lifetime of the current transaction. -
close
Implementation note: Certain fatal errors also result in a closed Connection.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConnection- Throws:
SQLException
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfaceConnection
-
isValid
- Specified by:
isValidin 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
Implementation ignores calls to this method as catalogs are not supported.
- Specified by:
setCatalogin interfaceConnection- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalogin interfaceConnection- Returns:
- Always
nullas catalogs are not supported. - Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolationin interfaceConnection- Throws:
SQLException
-
getWarnings
If connection property
reportSQLWarningsis set toNONE(case-insensitive), this method will not report warnings and always returnnull.- Specified by:
getWarningsin interfaceConnection- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarningsin interfaceConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin 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) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Throws:
SQLException
-
prepareStatement
protected PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, boolean metaData, boolean generatedKeys) throws SQLException - Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCallin interfaceConnection- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMapin interfaceConnection- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMapin interfaceConnection- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepointin interfaceConnection- Throws:
SQLException
-
setSavepoint
Creates a named savepoint.Savepoint names need to be valid Firebird identifiers, and the maximum length is restricted to the maximum identifier length (see
DatabaseMetaData.getMaxColumnNameLength(). The implementation will take care of quoting the savepoint name appropriately for the connection dialect. Thenameshould be passed unquoted.With connection dialect 1, the name is restricted to the rules for unquoted identifier names, that is, its characters are restricted to
A-Za-z0-9$_and handled case insensitive.For dialect 2 and 3, the name is restricted to the rules for Firebird quoted identifiers (essentially any printable character and space is valid), and the name is handled case sensitive.
- Specified by:
setSavepointin interfaceConnection- Parameters:
name- Savepoint name- Returns:
- Savepoint object
- Throws:
SQLException- if a database access error occurs, this method is called while participating in a distributed transaction, this method is called on a closed connection or thisConnectionobject is currently in auto-commit mode
-
rollback
- Specified by:
rollbackin interfaceConnection- Throws:
SQLException
-
releaseSavepoint
- Specified by:
releaseSavepointin interfaceConnection- Throws:
SQLException
-
invalidateSavepoints
protected void invalidateSavepoints()Invalidate all savepoints. -
getLocalTransaction
Returns a FBLocalTransaction instance that enables a component to demarcate resource manager local transactions on this connection. -
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
setSchema
Implementation ignores calls to this method as schemas are not supported.
- Specified by:
setSchemain interfaceConnection- Throws:
SQLException
-
getSchema
- Specified by:
getSchemain interfaceConnection- Returns:
- Always
nullas schemas ar not supported - Throws:
SQLException
-
addWarning
-
createNClob
Implementation note: This method behaves exactly the same as
createClob().- Specified by:
createNClobin interfaceConnection- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXMLin interfaceConnection- Throws:
SQLException
-
getGDSHelper
- Throws:
SQLException
-
isUseFirebirdAutoCommit
public boolean isUseFirebirdAutoCommit()- Specified by:
isUseFirebirdAutoCommitin interfaceFirebirdConnection- Returns:
trueif this connection is configured to useisc_tpb_autocommitwhen in auto commit.
-
getClientInfo
Retrieves the known properties of this connection. The initial known properties are
ApplicationName(with fallback toCLIENT_PROCESS@SYSTEM),ClientUser(no default value or fallback), andClientHostname(no default value or fallback). Successful retrieval or storing of properties withgetClientInfo(String),setClientInfo(String, String)andsetClientInfo(Properties)will register that property as a known property for this connection only.When auto-commit is enabled, known properties in context
USER_TRANSACTIONare skipped, and not included in the returnedPropertiesobject.Properties which were registered with suffix
@USER_SESSIONare included in the returnedPropertiesobject without that suffix. Known properties with valuenullare not included in the returnedPropertiesobject.- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException- See Also:
-
getClientInfo
Retrieves properties from context
USER_SESSIONor an explicitly specified context withRDB$GET_CONTEXT. Names ending in@USER_SESSION,@USER_TRANSACTIONor@SYSTEMare handled as<property-name>@<context-name>, and the property is retrieved from that context. Bare names are handled the same asname + "@USER_SESSION", unknown or unsupported context suffixes are handled as a property name inUSER_SESSION(that isDDL_EVENT@DDL_TRIGGERis handled as a property with that name inUSER_SESSION, and not as a property DDL_EVENT in context DDL_TRIGGER, which only exists in PSQL DDL triggers).When auto-commit is enabled, properties in context
USER_TRANSACTIONwill always returnnull, and no attempts are made to retrieve the property.Successful retrieval of a property will register it as a known property for this connection only for use with
getClientInfo()(i.e. known properties will be retrieved) andsetClientInfo(Properties)(i.e. if a known property is not included, it will be cleared).- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
setClientInfo
Sets the properties in
propertiesin contextUSER_SESSIONor an explicitly specified user context withRDB$SET_CONTEXT. See alsogetClientInfo(String)for handling of property names. Absent, but known properties are cleared. Contrary tosetClientInfo(String, String), properties in theSYSTEMcontext are silently ignored as they are read-only.When auto-commit is enabled, properties in context
USER_TRANSACTIONare silently ignored (they are not set nor cleared).Successful setting of properties will register it as a known property for this connection only for use with
getClientInfo()(i.e. known properties will be retrieved) andsetClientInfo(Properties)(i.e. if a known property is not included, it will be cleared).- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
setClientInfo
Sets properties in context
USER_SESSIONor an explicitly specified user context withRDB$SET_CONTEXT. See alsogetClientInfo(String)for handling of property names.When auto-commit is enabled, properties in context
USER_TRANSACTIONwill not be set.Successful storing of a property will register it as a known property for this connection only for use with
getClientInfo()(i.e. known properties will be retrieved) andsetClientInfo(Properties)(i.e. if a known property is not included, it will be cleared).- Specified by:
setClientInfoin interfaceConnection- Parameters:
name- name of the client info property to set (cannot be a name ending in@SYSTEMas those are read-only)- Throws:
SQLClientInfoException- ifnameisnullor ends in@SYSTEM, or for database access errors- See Also:
-
resetKnownClientInfoProperties
public void resetKnownClientInfoProperties()Description copied from interface:FirebirdConnectionResets the known client info properties of this connection to the defaults. This does not reset the values of those properties on the server, but only resets the list of known properties held by this connectionIf this connection is closed, this is effectively a no-op. Primary use-case for this method is to reset a connection held in a connection pool.
- Specified by:
resetKnownClientInfoPropertiesin interfaceFirebirdConnection
-
abort
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
withLock
- See Also:
-
isLockedByCurrentThread
protected final boolean isLockedByCurrentThread()
-