org.firebirdsql.pool

Class AbstractFBConnectionPoolDataSource

Implemented Interfaces:
ConnectionEventListener, ConnectionPoolDataSource, ConnectionPoolConfiguration, FirebirdConnectionProperties, FirebirdPool, PooledConnectionEventListener, PooledConnectionManager, Referenceable, Serializable, XADataSource, PooledObjectListener

public abstract class AbstractFBConnectionPoolDataSource
extends BasicAbstractConnectionPool
implements PooledConnectionManager, ConnectionPoolDataSource, XADataSource, PooledConnectionEventListener, FirebirdPool

Connection pool for Firebird JDBC driver. Following properties are supported:
  • loginTimeout property from javax.sql.DataSource, in this context is a synonym for blockingTimeout (however value is specified in seconds).
  • maxIdleTime time in milliseconds after which idle physical connection in the pool is closed.
  • maxStatements maximum number of pooled prepared statements, if 0, pooling is switched off.
  • maxPoolSize maximum number of physical connections that can be opened by this data source.
  • minPoolSize minimum number of connections that will remain open by this data source.
  • nonStandardProperty a non-standard connection parameter in form name[=value].
  • password password that is used to connect to database.
  • pingInterval time interval during which connection will be proved for aliveness.
  • pooling allows switching pooling off.
  • statementPooling alternative way to switch statement pooling off.
  • socketBufferSize size of the socket buffer in bytes. In some cases values used by JVM by default are not optimal. This results in performance degradation (especially when you transfer big BLOBs). Usually 8192 bytes provides good results.
  • sqlRole SQL role name.
  • tpbMapping mapping of the TPB parameters to JDBC transaction isolation levels.
  • transactionIsolationLevel default transaction isolation level, number from java.sql.Connection interface.
  • totalSize total number of allocated connections.
  • type type of connection that will be created. There are four possible types: pure Java (or type 4), type 2 that will use Firebird client library to connect to the database, local-mode type 2 driver, and embedded that will use embedded engine (access to local databases). Possible values are (case insensitive):
  • userName name of the user that will be used to access the database.
  • workingSize number of connections that are in use (e.g. were obtained using getPooledConnection() method, but not yet closed).
  • Author:
    Roman Rokytskyy

    Nested Class Summary

    Nested classes/interfaces inherited from class org.firebirdsql.pool.AbstractConnectionPool

    AbstractConnectionPool.UserPasswordPair

    Field Summary

    static AbstractConnectionPool.UserPasswordPair
    EMPTY_USER_PASSWORD
    protected static String
    REF_NON_STANDARD_PROPERTY
    protected static String
    REF_PROPERTIES

    Constructor Summary

    AbstractFBConnectionPoolDataSource()
    Create instance of this class.

    Method Summary

    PooledObject
    allocateConnection(Object key)
    Allocate new physical connection for the specified user name and password.
    void
    connectionClosed(ConnectionEvent connectionEvent)
    Notify about connection being closed.
    void
    connectionErrorOccurred(ConnectionEvent event)
    Notify about serious error when using the connection.
    protected BasicAbstractConnectionPool
    createObjectInstance()
    int
    getBlobBufferSize()
    int
    getBuffersNumber()
    String
    getCharSet()
    protected PooledConnectionManager
    getConnectionManager()
    FBConnectionProperties
    getConnectionProperties()
    Get connection properties.
    String
    getDatabase()
    DatabaseParameterBuffer
    getDatabaseParameterBuffer()
    String
    getDefaultIsolation()
    Reference
    getDefaultReference()
    int
    getDefaultTransactionIsolation()
    String
    getEncoding()
    int
    getFreeSize()
    org.firebirdsql.gds.impl.GDSType
    getGDSType()
    Get type of JDBC driver that is used.
    PrintWriter
    getLogWriter()
    protected org.firebirdsql.logging.Logger
    getLogger()
    int
    getLoginTimeout()
    Get login timeout.
    String
    getNonStandardProperty(String key)
    String
    getPassword()
    String
    getPingStatement()
    Get SQL statement that will be used to "ping" the connection.
    protected String
    getPoolName()
    Get name of the connection queue.
    PooledConnection
    getPooledConnection()
    Get pooled connection.
    PooledConnection
    getPooledConnection(String user, String password)
    Get pooled connection for the specified user name and password.
    protected PooledObject
    getPooledConnection(org.firebirdsql.pool.PooledConnectionQueue queue)
    Get pooled connection from the pooled queue.
    String
    getRoleName()
    int
    getSocketBufferSize()
    String
    getSqlDialect()
    String
    getSqlRole()
    Deprecated. please use getRoleName() instead.
    int
    getTotalSize()
    String
    getTpbMapping()
    TransactionParameterBuffer
    getTransactionParameters(int isolation)
    String
    getType()
    Get type of JDBC driver that will be used.
    String
    getUseTranslation()
    String
    getUserName()
    int
    getWorkingSize()
    XAConnection
    getXAConnection()
    Get XA connection.
    XAConnection
    getXAConnection(String user, String password)
    Get XA connection for the specified user name and password.
    boolean
    isDefaultResultSetHoldable()
    boolean
    isPingable()
    Check if this configuation defines a pingable connection JDBC pool.
    boolean
    isTimestampUsesLocalTimezone()
    boolean
    isUseStandardUdf()
    boolean
    isUseStreamBlobs()
    void
    physicalConnectionClosed(ConnectionEvent connectionEvent)
    Notify about physical connection being closed.
    void
    physicalConnectionDeallocated(ConnectionEvent connectionEvent)
    Notify about the deallocation of the physical connection.
    protected Object
    processObjectInstance(AbstractFBConnectionPoolDataSource ds, Reference ref)
    void
    setBlobBufferSize(int blobBufferSize)
    void
    setBuffersNumber(int buffersNumber)
    void
    setCharSet(String charSet)
    void
    setConnectionProperties(FBConnectionProperties props)
    Set the connection properties in bulk.
    void
    setDatabase(String database)
    void
    setDefaultIsolation(String isolation)
    void
    setDefaultResultSetHoldable(boolean isHoldable)
    void
    setDefaultTransactionIsolation(int defaultIsolationLevel)
    void
    setEncoding(String encoding)
    void
    setGDSType(org.firebirdsql.gds.impl.GDSType gdsType)
    Set type of the JDBC driver to use.
    void
    setLogWriter(PrintWriter out)
    void
    setLoginTimeout(int seconds)
    Set login timeout for new connection.
    void
    setNonStandardProperty(String propertyMapping)
    Method that allows setting non-standard property in the form "key=value" form.
    void
    setNonStandardProperty(String key, String value)
    void
    setPassword(String password)
    void
    setProperties(Properties properties)
    Set JDBC properties that will be passed when opening a connection.
    void
    setRoleName(String roleName)
    void
    setSocketBufferSize(int socketBufferSize)
    void
    setSqlDialect(String sqlDialect)
    void
    setSqlRole(String sqlRole)
    Deprecated. please use setRoleName(String) instead.
    void
    setTimestampUsesLocalTimezone(boolean timestampUsesLocalTimezone)
    void
    setTpbMapping(String tpbMapping)
    void
    setTransactionParameters(int isolation, TransactionParameterBuffer tpb)
    void
    setType(String type)
    Set type of JDBC driver to use.
    void
    setUseStandardUdf(boolean useStandardUdf)
    void
    setUseStreamBlobs(boolean useStreamBlobs)
    void
    setUseTranslation(String translationPath)
    void
    setUserName(String userName)

    Methods inherited from class org.firebirdsql.pool.BasicAbstractConnectionPool

    createObjectInstance, deserialize, getBlockingTimeout, getConfiguration, getDefaultReference, getIdleTimeout, getLogWriter, getLoginTimeout, getMaxConnections, getMaxIdleTime, getMaxPoolSize, getMaxStatements, getMinConnections, getMinPoolSize, getObjectInstance, getPingInterval, getPingStatement, getPooledConnection, getPooledConnection, getRefAddr, getReference, getRetryInterval, isKeepStatements, isPingable, isPooling, isStatementPooling, serialize, setBlockingTimeout, setIdleTimeout, setKeepStatements, setLogWriter, setLoginTimeout, setMaxConnections, setMaxIdleTime, setMaxPoolSize, setMaxStatements, setMinConnections, setMinPoolSize, setPingInterval, setPingStatement, setPooling, setReference, setRetryInterval, setStatementPooling

    Methods inherited from class org.firebirdsql.pool.AbstractConnectionPool

    finalize, getConfiguration, getConnectionManager, getFreeSize, getLogger, getPoolName, getPooledConnection, getQueue, getTotalSize, getWorkingSize, physicalConnectionDeallocated, pooledObjectReleased, restart, shutdown

    Field Details

    EMPTY_USER_PASSWORD

    public static final AbstractConnectionPool.UserPasswordPair EMPTY_USER_PASSWORD

    REF_NON_STANDARD_PROPERTY

    protected static final String REF_NON_STANDARD_PROPERTY

    REF_PROPERTIES

    protected static final String REF_PROPERTIES

    Constructor Details

    AbstractFBConnectionPoolDataSource

    public AbstractFBConnectionPoolDataSource()
    Create instance of this class.

    Method Details

    allocateConnection

    public PooledObject allocateConnection(Object key)
                throws SQLException
    Allocate new physical connection for the specified user name and password.
    Specified by:
    allocateConnection in interface PooledConnectionManager
    Parameters:
    key - key identifying pooled object.
    Returns:
    instance of PooledObject.

    connectionClosed

    public void connectionClosed(ConnectionEvent connectionEvent)
    Notify about connection being closed.
    Parameters:
    connectionEvent - instance of ConnectionEvent.

    connectionErrorOccurred

    public void connectionErrorOccurred(ConnectionEvent event)
    Notify about serious error when using the connection. Currently these events are ignored.
    Parameters:
    event - instance of ConnectionEvent containing information about an error.

    createObjectInstance

    protected BasicAbstractConnectionPool createObjectInstance()
    Overrides:
    createObjectInstance in interface BasicAbstractConnectionPool

    getBlobBufferSize

    public int getBlobBufferSize()
    Specified by:
    getBlobBufferSize in interface FirebirdConnectionProperties

    getBuffersNumber

    public int getBuffersNumber()
    Specified by:
    getBuffersNumber in interface FirebirdConnectionProperties

    getCharSet

    public String getCharSet()
    Specified by:
    getCharSet in interface FirebirdConnectionProperties

    getConnectionManager

    protected PooledConnectionManager getConnectionManager()
    Overrides:
    getConnectionManager in interface AbstractConnectionPool

    getConnectionProperties

    public FBConnectionProperties getConnectionProperties()
    Get connection properties. This method returns a live object where connection properties can be set. Usually application does not need to call this method, since this class implements appropriate interface and all properties can set directly. However, this is needed for custom serialization.
    Returns:
    "live" instance of FBConnectionProperties.

    getDatabase

    public String getDatabase()
    Specified by:
    getDatabase in interface FirebirdConnectionProperties

    getDatabaseParameterBuffer

    public DatabaseParameterBuffer getDatabaseParameterBuffer()
                throws SQLException
    Specified by:
    getDatabaseParameterBuffer in interface FirebirdConnectionProperties

    getDefaultIsolation

    public String getDefaultIsolation()
    Specified by:
    getDefaultIsolation in interface FirebirdConnectionProperties

    getDefaultReference

    public Reference getDefaultReference()
    Overrides:
    getDefaultReference in interface BasicAbstractConnectionPool

    getDefaultTransactionIsolation

    public int getDefaultTransactionIsolation()
    Specified by:
    getDefaultTransactionIsolation in interface FirebirdConnectionProperties

    getEncoding

    public String getEncoding()
    Specified by:
    getEncoding in interface FirebirdConnectionProperties

    getFreeSize

    public int getFreeSize()
                throws SQLException
    Specified by:
    getFreeSize in interface FirebirdPool
    Overrides:
    getFreeSize in interface AbstractConnectionPool

    getGDSType

    public org.firebirdsql.gds.impl.GDSType getGDSType()
    Get type of JDBC driver that is used.
    Returns:
    type of JDBC driver that is used.

    getLogWriter

    public PrintWriter getLogWriter()
    Overrides:
    getLogWriter in interface BasicAbstractConnectionPool

    getLogger

    protected org.firebirdsql.logging.Logger getLogger()
    Overrides:
    getLogger in interface AbstractConnectionPool

    getLoginTimeout

    public int getLoginTimeout()
    Get login timeout.
    Overrides:
    getLoginTimeout in interface BasicAbstractConnectionPool
    Returns:
    value set in setLoginTimeout(int) method or 0.

    getNonStandardProperty

    public String getNonStandardProperty(String key)
    Specified by:
    getNonStandardProperty in interface FirebirdConnectionProperties

    getPassword

    public String getPassword()
    Specified by:
    getPassword in interface FirebirdConnectionProperties

    getPingStatement

    public String getPingStatement()
    Get SQL statement that will be used to "ping" the connection.
    Specified by:
    getPingStatement in interface ConnectionPoolConfiguration
    Overrides:
    getPingStatement in interface BasicAbstractConnectionPool

    getPoolName

    protected String getPoolName()
    Get name of the connection queue.
    Overrides:
    getPoolName in interface AbstractConnectionPool

    getPooledConnection

    public PooledConnection getPooledConnection()
                throws SQLException
    Get pooled connection. This method will block until there will be free connection to return.
    Overrides:
    getPooledConnection in interface BasicAbstractConnectionPool
    Returns:
    instance of PooledConnection.

    getPooledConnection

    public PooledConnection getPooledConnection(String user,
                                                String password)
                throws SQLException
    Get pooled connection for the specified user name and password.
    Overrides:
    getPooledConnection in interface BasicAbstractConnectionPool
    Parameters:
    user - user name.
    password - password corresponding to specified user name.
    Returns:
    instance of PooledConnection for the specified credentials.

    getPooledConnection

    protected PooledObject getPooledConnection(org.firebirdsql.pool.PooledConnectionQueue queue)
                throws SQLException
    Get pooled connection from the pooled queue.
    Overrides:
    getPooledConnection in interface AbstractConnectionPool

    getRoleName

    public String getRoleName()
    Specified by:
    getRoleName in interface FirebirdConnectionProperties

    getSocketBufferSize

    public int getSocketBufferSize()
    Specified by:
    getSocketBufferSize in interface FirebirdConnectionProperties

    getSqlDialect

    public String getSqlDialect()
    Specified by:
    getSqlDialect in interface FirebirdConnectionProperties

    getSqlRole

    public String getSqlRole()

    Deprecated. please use getRoleName() instead.


    getTotalSize

    public int getTotalSize()
                throws SQLException
    Specified by:
    getTotalSize in interface FirebirdPool
    Overrides:
    getTotalSize in interface AbstractConnectionPool

    getTpbMapping

    public String getTpbMapping()
    Specified by:
    getTpbMapping in interface FirebirdConnectionProperties

    getTransactionParameters

    public TransactionParameterBuffer getTransactionParameters(int isolation)
    Specified by:
    getTransactionParameters in interface FirebirdConnectionProperties

    getType

    public String getType()
    Specified by:
    getType in interface FirebirdConnectionProperties
    Returns:
    one of the following values:
    • "PURE_JAVA" for pure Java type 4 JDBC driver.
    • "NATIVE" for type 2 JDBC driver that will use Firebird client library.
    • "EMBEDDED" for type 2 JDBC driver that will use embedded engine.

    getUseTranslation

    public String getUseTranslation()
    Specified by:
    getUseTranslation in interface FirebirdConnectionProperties

    getUserName

    public String getUserName()
    Specified by:
    getUserName in interface FirebirdConnectionProperties

    getWorkingSize

    public int getWorkingSize()
                throws SQLException
    Specified by:
    getWorkingSize in interface FirebirdPool
    Overrides:
    getWorkingSize in interface AbstractConnectionPool

    getXAConnection

    public XAConnection getXAConnection()
                throws SQLException
    Get XA connection. This method will block until there will be free connection to return.
    Returns:
    instance of XAConnection.

    getXAConnection

    public XAConnection getXAConnection(String user,
                                        String password)
                throws SQLException
    Get XA connection for the specified user name and password.
    Parameters:
    user - user name.
    password - password corresponding to specified user name.
    Returns:
    instance of XAConnection for the specified credentials.

    isDefaultResultSetHoldable

    public boolean isDefaultResultSetHoldable()
    Specified by:
    isDefaultResultSetHoldable in interface FirebirdConnectionProperties

    isPingable

    public boolean isPingable()
    Check if this configuation defines a pingable connection JDBC pool.
    Specified by:
    isPingable in interface ConnectionPoolConfiguration
    Overrides:
    isPingable in interface BasicAbstractConnectionPool

    isTimestampUsesLocalTimezone

    public boolean isTimestampUsesLocalTimezone()
    Specified by:
    isTimestampUsesLocalTimezone in interface FirebirdConnectionProperties

    isUseStandardUdf

    public boolean isUseStandardUdf()
    Specified by:
    isUseStandardUdf in interface FirebirdConnectionProperties

    isUseStreamBlobs

    public boolean isUseStreamBlobs()
    Specified by:
    isUseStreamBlobs in interface FirebirdConnectionProperties

    physicalConnectionClosed

    public void physicalConnectionClosed(ConnectionEvent connectionEvent)
    Notify about physical connection being closed.
    Specified by:
    physicalConnectionClosed in interface PooledConnectionEventListener
    Parameters:
    connectionEvent - instance of ConnectionEvent.

    physicalConnectionDeallocated

    public void physicalConnectionDeallocated(ConnectionEvent connectionEvent)
    Notify about the deallocation of the physical connection.
    Specified by:
    physicalConnectionDeallocated in interface PooledConnectionEventListener
    Parameters:
    connectionEvent - instance of ConnectionEvent.

    processObjectInstance

    protected Object processObjectInstance(AbstractFBConnectionPoolDataSource ds,
                                           Reference ref)
                throws Exception

    setBlobBufferSize

    public void setBlobBufferSize(int blobBufferSize)
    Specified by:
    setBlobBufferSize in interface FirebirdConnectionProperties

    setBuffersNumber

    public void setBuffersNumber(int buffersNumber)
    Specified by:
    setBuffersNumber in interface FirebirdConnectionProperties

    setCharSet

    public void setCharSet(String charSet)
    Specified by:
    setCharSet in interface FirebirdConnectionProperties

    setConnectionProperties

    public void setConnectionProperties(FBConnectionProperties props)
    Set the connection properties in bulk. This method replaces the instance created in constructor, therefore, if the managed connection factory was already initialized with that instance, change will not be visible to it. In this case appropriate exception is thrown.
    Parameters:
    props - instance of FBConnectionProperties.

    setDatabase

    public void setDatabase(String database)
    Specified by:
    setDatabase in interface FirebirdConnectionProperties

    setDefaultIsolation

    public void setDefaultIsolation(String isolation)
    Specified by:
    setDefaultIsolation in interface FirebirdConnectionProperties

    setDefaultResultSetHoldable

    public void setDefaultResultSetHoldable(boolean isHoldable)
    Specified by:
    setDefaultResultSetHoldable in interface FirebirdConnectionProperties

    setDefaultTransactionIsolation

    public void setDefaultTransactionIsolation(int defaultIsolationLevel)
    Specified by:
    setDefaultTransactionIsolation in interface FirebirdConnectionProperties

    setEncoding

    public void setEncoding(String encoding)
    Specified by:
    setEncoding in interface FirebirdConnectionProperties

    setGDSType

    public void setGDSType(org.firebirdsql.gds.impl.GDSType gdsType)
    Set type of the JDBC driver to use.
    Parameters:
    gdsType - type of the JDBC driver.

    setLogWriter

    public void setLogWriter(PrintWriter out)
    Overrides:
    setLogWriter in interface BasicAbstractConnectionPool

    setLoginTimeout

    public void setLoginTimeout(int seconds)
    Set login timeout for new connection. Currently ignored.
    Overrides:
    setLoginTimeout in interface BasicAbstractConnectionPool
    Parameters:
    seconds - how long pool should wait until new connection is granted.

    setNonStandardProperty

    public void setNonStandardProperty(String propertyMapping)
    Method that allows setting non-standard property in the form "key=value" form. This method is needed by some containers to specify properties in the configuration.
    Specified by:
    setNonStandardProperty in interface FirebirdConnectionProperties
    Parameters:
    propertyMapping - mapping between property name (key) and its value. Name and value are separated with "=", ":" or whitespace character. Whitespace characters on the beginning of the string and between key and value are ignored. No escaping is possible: "\n" is backslash-en, not a new line mark.

    setNonStandardProperty

    public void setNonStandardProperty(String key,
                                       String value)
    Specified by:
    setNonStandardProperty in interface FirebirdConnectionProperties

    setPassword

    public void setPassword(String password)
    Specified by:
    setPassword in interface FirebirdConnectionProperties

    setProperties

    public void setProperties(Properties properties)
    Set JDBC properties that will be passed when opening a connection.
    Parameters:
    properties - instance of Properties containing properties of a connection to open.

    setRoleName

    public void setRoleName(String roleName)
    Specified by:
    setRoleName in interface FirebirdConnectionProperties

    setSocketBufferSize

    public void setSocketBufferSize(int socketBufferSize)
    Specified by:
    setSocketBufferSize in interface FirebirdConnectionProperties

    setSqlDialect

    public void setSqlDialect(String sqlDialect)
    Specified by:
    setSqlDialect in interface FirebirdConnectionProperties

    setSqlRole

    public void setSqlRole(String sqlRole)

    Deprecated. please use setRoleName(String) instead.


    setTimestampUsesLocalTimezone

    public void setTimestampUsesLocalTimezone(boolean timestampUsesLocalTimezone)
    Specified by:
    setTimestampUsesLocalTimezone in interface FirebirdConnectionProperties

    setTpbMapping

    public void setTpbMapping(String tpbMapping)
    Specified by:
    setTpbMapping in interface FirebirdConnectionProperties

    setTransactionParameters

    public void setTransactionParameters(int isolation,
                                         TransactionParameterBuffer tpb)
    Specified by:
    setTransactionParameters in interface FirebirdConnectionProperties

    setType

    public void setType(String type)
    Set type of JDBC driver to use.
    Specified by:
    setType in interface FirebirdConnectionProperties
    Parameters:
    type - type of driver to use. Possible values are (case insensitive):
    • "PURE_JAVA" or "TYPE4" for pure Java type 4 JDBC driver;
    • "NATIVE" or "TYPE2" for type 2 JDBC driver that will use Firebird client library.
    • "EMBEDDED" for type 2 JDBC driver that will use embedded version of the server.

    setUseStandardUdf

    public void setUseStandardUdf(boolean useStandardUdf)
    Specified by:
    setUseStandardUdf in interface FirebirdConnectionProperties

    setUseStreamBlobs

    public void setUseStreamBlobs(boolean useStreamBlobs)
    Specified by:
    setUseStreamBlobs in interface FirebirdConnectionProperties

    setUseTranslation

    public void setUseTranslation(String translationPath)
    Specified by:
    setUseTranslation in interface FirebirdConnectionProperties

    setUserName

    public void setUserName(String userName)
    Specified by:
    setUserName in interface FirebirdConnectionProperties

    Copyright B) 2001 David Jencks and other authors. All rights reserved.