Class FBConnection
- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper,FirebirdConnection,Synchronizable
- 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_SERIALIZABLEFields inherited from interface org.firebirdsql.jdbc.FirebirdConnection
TPB_CONCURRENCY, TPB_CONSISTENCY, TPB_NO_REC_VERSION, TPB_NOWAIT, TPB_READ, TPB_READ_COMMITTED, TPB_REC_VERSION, TPB_WAIT, TPB_WRITE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddWarning(SQLWarning warning) protected voidChecks if client info is supported.protected voidCheck if this connection is valid.voidvoidclose()voidcommit()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 voidfinalize()protected voidThis method closes all active statements and cleans resources.booleangetClientInfo(String name) protected StringgetClientInfo(PreparedStatement stmt, String name) Get database parameter buffer for this connection.protected FBEscapedParserReturns the FBEscapedParser instance for this connection.Provides access to the low-level connection handle.intGet current ISC encoding.Returns a FBLocalTransaction instance that enables a component to demarcate resource manager local transactions on this connection.intfinal ObjectGet synchronization object.intgetTransactionParameters(int isolationLevel) Get transaction parameters for the specified transaction isolation level.booleanCheck if this connection is currently involved in a transactionprotected voidInvalidate all savepoints.protected voidInvalidate everything that should only last for the lifetime of the current transaction.booleanisClosed()booleanbooleanbooleanisValid(int timeout) booleanisWrapperFor(Class<?> iface) prepareCall(String sql) prepareCall(String sql, int resultSetType, int resultSetConcurrency) prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) protected PreparedStatementprepareMetaDataStatement(String sql, int resultSetType, int resultSetConcurrency) 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) voidrollback()voidvoidsetAutoCommit(boolean autoCommit) voidsetCatalog(String catalog) voidsetClientInfo(String name, String value) protected voidsetClientInfo(PreparedStatement stmt, 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> TMethods inherited from class java.lang.Object
clone, equals, 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 AbstractConnection instance based on aFBManagedConnection.- Parameters:
mc- A FBManagedConnection around which this connection is based
-
-
Method Details
-
getStatementListener
-
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
-
getDatabaseParameterBuffer
Get database parameter buffer for this connection.- Returns:
- instance of
DatabaseParameterBuffer.
-
setTransactionParameters
@Deprecated 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 occured 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 occured 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 interfaceFirebirdConnection- Parameters:
isolationLevel- isolation level defined in theConnectioninterface.tpb- instance ofTransactionParameterBufferwith parameters to set.- Throws:
SQLException- if error occured 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 untilConnection.setTransactionIsolation(int)is called.Method cannot be called when transaction has already started.
- 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
-
getEscapedParser
Returns the FBEscapedParser instance for this connection.- Returns:
- Instance of FBEscapedParser
-
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
- 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
-
prepareMetaDataStatement
protected PreparedStatement prepareMetaDataStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - 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
-
inTransaction
Check if this connection is currently involved in a transaction- Throws:
SQLException
-
getIscEncoding
Description copied from interface:FirebirdConnectionGet current ISC encoding.- Specified by:
getIscEncodingin interfaceFirebirdConnection- Returns:
- current ISC encoding.
- 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.
-
finalize
-
checkClientInfoSupport
Checks if client info is supported.- Throws:
SQLException- If the client info is not supported, or if there is no database connection.
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
getClientInfo
- Specified by:
getClientInfoin interfaceConnection- Throws:
SQLException
-
getClientInfo
- Throws:
SQLException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
setClientInfo
- Specified by:
setClientInfoin interfaceConnection- Throws:
SQLClientInfoException
-
setClientInfo
- Throws:
SQLException
-
abort
- Specified by:
abortin interfaceConnection- Throws:
SQLException
-
setNetworkTimeout
- Specified by:
setNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getNetworkTimeout
- Specified by:
getNetworkTimeoutin interfaceConnection- Throws:
SQLException
-
getSynchronizationObject
Description copied from interface:SynchronizableGet synchronization object.- Specified by:
getSynchronizationObjectin interfaceSynchronizable- Returns:
- object, cannot be
null.
-