- 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 FBManagedConnection
protected final InternalTransactionCoordinator
Fields 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 TypeMethodDescriptionvoid
void
addWarning
(SQLWarning warning) protected void
Check if this connection is valid.void
void
close()
void
commit()
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 void
This method closes all active statements and cleans resources.boolean
getClientInfo
(String name) Provides access to the low-level connection handle.int
Returns a FBLocalTransaction instance that enables a component to demarcate resource manager local transactions on this connection.int
int
getTransactionParameters
(int isolationLevel) Get transaction parameters for the specified transaction isolation level.protected void
Invalidate all savepoints.protected void
Invalidate everything that should only last for the lifetime of the current transaction.boolean
isClosed()
protected final boolean
boolean
boolean
boolean
isValid
(int timeout) boolean
isWrapperFor
(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 PreparedStatement
prepareStatement
(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, boolean metaData, boolean generatedKeys) prepareStatement
(String sql, String[] columnNames) void
releaseSavepoint
(Savepoint savepoint) void
Resets the known client info properties of this connection to the defaults.void
rollback()
void
void
setAutoCommit
(boolean autoCommit) void
setCatalog
(String catalog) void
setClientInfo
(String name, String value) void
setClientInfo
(Properties properties) void
setHoldability
(int holdability) void
Set theFBManagedConnection
around which this connection is based.void
setManagedEnvironment
(boolean managedConnection) void
setNetworkTimeout
(Executor executor, int milliseconds) void
setReadOnly
(boolean readOnly) setSavepoint
(String name) Creates a named savepoint.void
protected void
setTransactionCoordinator
(boolean managedConnection, boolean autoCommit) void
setTransactionIsolation
(int level) void
setTransactionParameters
(int isolationLevel, int[] parameters) Deprecated.void
setTransactionParameters
(int isolationLevel, TransactionParameterBuffer tpb) Set transaction parameters for the specified transaction isolation level.void
Set transaction parameters for the next transactions.void
setTypeMap
(Map<String, Class<?>> map) <T> T
protected final LockCloseable
withLock()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
getHoldability
in interfaceConnection
- Throws:
SQLException
-
setHoldability
- Specified by:
setHoldability
in 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 theFBManagedConnection
around which this connection is based.- Parameters:
mc
- The FBManagedConnection around which this connection is based
-
getManagedConnection
-
getFbDatabase
Description copied from interface:FirebirdConnection
Provides access to the low-level connection handle.WARNING using this connection handle directly may bring the JDBC connection in an inconsistent state.
- Specified by:
getFbDatabase
in 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:FirebirdConnection
Set transaction parameters for the specified isolation level. They will take effect only on the newly started transaction.- Specified by:
setTransactionParameters
in 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:FirebirdConnection
Get transaction parameters for the specified transaction isolation level.- Specified by:
getTransactionParameters
in interfaceFirebirdConnection
- Parameters:
isolationLevel
- isolation level defined in theConnection
interface.- Returns:
- instance of
TransactionParameterBuffer
containing current transaction parameters. - Throws:
SQLException
- if error occurred obtaining transaction parameters.
-
createTransactionParameterBuffer
Description copied from interface:FirebirdConnection
Create new instance ofTransactionParameterBuffer
.- Specified by:
createTransactionParameterBuffer
in 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:FirebirdConnection
Set 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:
setTransactionParameters
in interfaceFirebirdConnection
tpb
- instance ofTransactionParameterBuffer
with parameters to set.- Throws:
SQLException
- if error occurred during this operation.
-
setTransactionParameters
Description copied from interface:FirebirdConnection
Set 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:
setTransactionParameters
in interfaceFirebirdConnection
- Parameters:
tpb
- instance ofTransactionParameterBuffer
with new transaction parameters.- Throws:
SQLException
- if method is called within a transaction.
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
createBlob
Description copied from interface:FirebirdConnection
- Specified by:
createBlob
in interfaceConnection
- Specified by:
createBlob
in interfaceFirebirdConnection
- Returns:
- instance of
FirebirdBlob
. - Throws:
SQLException
-
createClob
- Specified by:
createClob
in interfaceConnection
- Throws:
SQLException
-
createStruct
- Specified by:
createStruct
in interfaceConnection
- Throws:
SQLException
-
createArrayOf
- Specified by:
createArrayOf
in interfaceConnection
- Throws:
SQLException
-
nativeSQL
- Specified by:
nativeSQL
in interfaceConnection
- Throws:
SQLException
-
setAutoCommit
- Specified by:
setAutoCommit
in interfaceConnection
- Throws:
SQLException
-
setTransactionCoordinator
protected void setTransactionCoordinator(boolean managedConnection, boolean autoCommit) throws SQLException - Throws:
SQLException
-
setManagedEnvironment
- Throws:
SQLException
-
getAutoCommit
- Specified by:
getAutoCommit
in interfaceConnection
- Throws:
SQLException
-
commit
- Specified by:
commit
in interfaceConnection
- Throws:
SQLException
-
rollback
- Specified by:
rollback
in 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
- Throws:
SQLException
-
isClosed
public boolean isClosed()- Specified by:
isClosed
in interfaceConnection
-
isValid
- Specified by:
isValid
in interfaceConnection
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaData
in interfaceConnection
- Throws:
SQLException
-
setReadOnly
- Specified by:
setReadOnly
in interfaceConnection
- Throws:
SQLException
-
isReadOnly
- Specified by:
isReadOnly
in interfaceConnection
- Throws:
SQLException
-
setCatalog
Implementation ignores calls to this method as catalogs are not supported.
- Specified by:
setCatalog
in interfaceConnection
- Throws:
SQLException
-
getCatalog
- Specified by:
getCatalog
in interfaceConnection
- Returns:
- Always
null
as catalogs are not supported. - Throws:
SQLException
-
setTransactionIsolation
- Specified by:
setTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
getTransactionIsolation
- Specified by:
getTransactionIsolation
in interfaceConnection
- Throws:
SQLException
-
getWarnings
If connection property
reportSQLWarnings
is set toNONE
(case-insensitive), this method will not report warnings and always returnnull
.- Specified by:
getWarnings
in interfaceConnection
- Throws:
SQLException
-
clearWarnings
- Specified by:
clearWarnings
in interfaceConnection
- Throws:
SQLException
-
createStatement
- Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in interfaceConnection
- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatement
in 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:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCall
in interfaceConnection
- Throws:
SQLException
-
getTypeMap
- Specified by:
getTypeMap
in interfaceConnection
- Throws:
SQLException
-
setTypeMap
- Specified by:
setTypeMap
in interfaceConnection
- Throws:
SQLException
-
setSavepoint
- Specified by:
setSavepoint
in 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. Thename
should 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:
setSavepoint
in 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 thisConnection
object is currently in auto-commit mode
-
rollback
- Specified by:
rollback
in interfaceConnection
- Throws:
SQLException
-
releaseSavepoint
- Specified by:
releaseSavepoint
in 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:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
setSchema
Implementation ignores calls to this method as schemas are not supported.
- Specified by:
setSchema
in interfaceConnection
- Throws:
SQLException
-
getSchema
- Specified by:
getSchema
in interfaceConnection
- Returns:
- Always
null
as schemas ar not supported - Throws:
SQLException
-
addWarning
-
createNClob
Implementation note: This method behaves exactly the same as
createClob()
.- Specified by:
createNClob
in interfaceConnection
- Throws:
SQLException
-
createSQLXML
- Specified by:
createSQLXML
in interfaceConnection
- Throws:
SQLException
-
getGDSHelper
- Throws:
SQLException
-
isUseFirebirdAutoCommit
public boolean isUseFirebirdAutoCommit()- Specified by:
isUseFirebirdAutoCommit
in interfaceFirebirdConnection
- Returns:
true
if this connection is configured to useisc_tpb_autocommit
when 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_TRANSACTION
are skipped, and not included in the returnedProperties
object.Properties which were registered with suffix
@USER_SESSION
are included in the returnedProperties
object without that suffix. Known properties with valuenull
are not included in the returnedProperties
object.- Specified by:
getClientInfo
in interfaceConnection
- Throws:
SQLException
- See Also:
-
getClientInfo
Retrieves properties from context
USER_SESSION
or an explicitly specified context withRDB$GET_CONTEXT
. Names ending in@USER_SESSION
,@USER_TRANSACTION
or@SYSTEM
are 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_TRIGGER
is 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_TRANSACTION
will 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:
getClientInfo
in interfaceConnection
- Throws:
SQLException
-
setClientInfo
Sets the properties in
properties
in contextUSER_SESSION
or 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 theSYSTEM
context are silently ignored as they are read-only.When auto-commit is enabled, properties in context
USER_TRANSACTION
are 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:
setClientInfo
in interfaceConnection
- Throws:
SQLClientInfoException
-
setClientInfo
Sets properties in context
USER_SESSION
or 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_TRANSACTION
will 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:
setClientInfo
in interfaceConnection
- Parameters:
name
- name of the client info property to set (cannot be a name ending in@SYSTEM
as those are read-only)- Throws:
SQLClientInfoException
- ifname
isnull
or ends in@SYSTEM
, or for database access errors- See Also:
-
resetKnownClientInfoProperties
public void resetKnownClientInfoProperties()Description copied from interface:FirebirdConnection
Resets 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:
resetKnownClientInfoProperties
in interfaceFirebirdConnection
-
abort
- Specified by:
abort
in interfaceConnection
- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeout
in interfaceConnection
- Throws:
SQLException
-
withLock
- See Also:
-
isLockedByCurrentThread
protected final boolean isLockedByCurrentThread()
-