org.firebirdsql.pool
Class FBConnectionPoolDataSource

java.lang.Object
  extended byorg.firebirdsql.pool.AbstractConnectionPool
      extended byorg.firebirdsql.pool.FBConnectionPoolDataSource
All Implemented Interfaces:
javax.sql.ConnectionEventListener, ConnectionPoolConfiguration, javax.sql.ConnectionPoolDataSource, java.util.EventListener, javax.naming.spi.ObjectFactory, PooledConnectionManager, PooledObjectListener, javax.naming.Referenceable, javax.resource.Referenceable, java.io.Serializable

public class FBConnectionPoolDataSource
extends AbstractConnectionPool
implements PooledConnectionManager, ConnectionPoolConfiguration, javax.sql.ConnectionPoolDataSource, javax.sql.ConnectionEventListener, java.io.Serializable, javax.resource.Referenceable, javax.naming.spi.ObjectFactory

Connection pool for Firebird JDBC driver.

Author:
Roman Rokytskyy
See Also:
Serialized Form

Field Summary
static java.lang.String BLOB_BUFFER_PROPERTY
           
static org.firebirdsql.pool.FBConnectionPoolDataSource.UserPasswordPair EMPTY_USER_PASSWORD
           
static java.lang.String ENCODING_PROPERTY
           
static java.lang.String PASSWORD_PROPERTY
           
static java.lang.String SOCKET_BUFFER_PROPERTY
           
static java.lang.String SQL_ROLE_PROPERTY
           
static java.lang.String TPB_MAPPING_PROPERTY
           
static java.lang.String USER_NAME_PROPERTY
           
 
Constructor Summary
FBConnectionPoolDataSource()
          Create instance of this class.
 
Method Summary
 PooledObject allocateConnection(java.lang.Object key)
          Allocate new physical connection for the specified user name and password.
 void connectionClosed(javax.sql.ConnectionEvent connectionEvent)
          Notify about connection being closed.
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
          Notify about serious error when using the connection.
 int getBlobBufferSize()
           
 int getBlockingTimeout()
          Get pool blocking timeout.
 java.lang.String getCharSet()
           
 ConnectionPoolConfiguration getConfiguration()
          Get configuration of this data source.
protected  PooledConnectionManager getConnectionManager()
          Get instance of PooledConnectionManager responsible for instantiating pooled connections.
 java.lang.String getDatabase()
          Get database to which we will connect.
 javax.naming.Reference getDefaultReference()
          Get default JNDI reference for this datasource.
 java.lang.String getEncoding()
           
 int getFreeSize()
          Get number of free connections in this pool.
 GDSType getGDSType()
          Get type of JDBC driver that is used.
 int getIdleTimeout()
          Get idle timeout.
protected  org.firebirdsql.logging.Logger getLogger()
          Get logger for this instance.
 int getLoginTimeout()
          Get login timeout.
 java.io.PrintWriter getLogWriter()
           
 int getMaxConnections()
          Get maximum number of physical connections in the pool.
 int getMinConnections()
          Get minimum number of open physical connections that are kept in pool.
 java.lang.String getNonStandardProperty(java.lang.String key)
           
 java.lang.Object getObjectInstance(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment)
          Get object instance for the specified name in the specified context.
 java.lang.String getPassword()
           
 int getPingInterval()
          Get time interval, after which connection is marked to be pinged on first request to it.
 java.lang.String getPingStatement()
          Get SQL statement that will be used to "ping" the connection.
 javax.sql.PooledConnection getPooledConnection()
          Get pooled connection.
protected  PooledObject getPooledConnection(org.firebirdsql.pool.PooledConnectionQueue queue)
          Get pooled connection from the pooled queue.
 javax.sql.PooledConnection getPooledConnection(java.lang.String user, java.lang.String password)
          Get pooled connection for the specified user name and password.
protected  java.lang.String getPoolName()
          Get name of the connection queue.
 java.util.Properties getProperties()
          Get JDBC connection properties.
 javax.naming.Reference getReference()
          Get JDNI reference.
 int getRetryInterval()
          Get retry interval.
 int getSocketBufferSize()
           
 java.lang.String getSqlRole()
           
 int getTotalSize()
          Get total size of physical connections opened to the database.
 java.lang.String getTpbMapping()
           
 java.lang.String getType()
          Get type of JDBC driver that will be used.
 java.lang.String getUserName()
           
 int getWorkingSize()
          Get number of connections that are in use.
 boolean isPingable()
          Check if this configuation defines a pingable connection JDBC pool.
 void setBlobBufferSize(int blobBufferSize)
           
 void setBlockingTimeout(int blockingTimeout)
          Set blocking timeout.
 void setCharSet(java.lang.String charSet)
           
 void setDatabase(java.lang.String database)
          Set database name.
 void setEncoding(java.lang.String encoding)
           
 void setGDSType(GDSType gdsType)
          Set type of the JDBC driver to use.
 void setIdleTimeout(int idleTimeout)
          Set idle timeout.
 void setIntProperty(java.lang.String name, int value)
          Set specified property as integer value.
 void setLoginTimeout(int seconds)
          Set login timeout for new connection.
 void setLogWriter(java.io.PrintWriter out)
           
 void setMaxConnections(int maxConnections)
          Set maximum number of open physical connections in the pool.
 void setMinConnections(int minConnections)
          Set minimum number of open physical connections in the pool.
 void setNonStandardProperty(java.lang.String key, java.lang.String value)
           
 void setPassword(java.lang.String password)
           
 void setPingInterval(int pingInterval)
          Set ping interval for the connections.
 void setProperties(java.util.Properties properties)
          Set JDBC properties that will be passed when opening a connection.
 void setReference(javax.naming.Reference reference)
          Set JNDI reference for this data source.
 void setRetryInterval(int retryInterval)
          Set retry interval.
 void setSocketBufferSize(int socketBufferSize)
           
 void setSqlRole(java.lang.String sqlRole)
           
 void setTpbMapping(java.lang.String tpbMapping)
           
 void setType(java.lang.String type)
          Set type of JDBC driver to use.
 void setUserName(java.lang.String userName)
           
 
Methods inherited from class org.firebirdsql.pool.AbstractConnectionPool
finalize, getQueue, pooledObjectReleased, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_NAME_PROPERTY

public static final java.lang.String USER_NAME_PROPERTY
See Also:
Constant Field Values

PASSWORD_PROPERTY

public static final java.lang.String PASSWORD_PROPERTY
See Also:
Constant Field Values

TPB_MAPPING_PROPERTY

public static final java.lang.String TPB_MAPPING_PROPERTY
See Also:
Constant Field Values

BLOB_BUFFER_PROPERTY

public static final java.lang.String BLOB_BUFFER_PROPERTY
See Also:
Constant Field Values

ENCODING_PROPERTY

public static final java.lang.String ENCODING_PROPERTY
See Also:
Constant Field Values

SOCKET_BUFFER_PROPERTY

public static final java.lang.String SOCKET_BUFFER_PROPERTY
See Also:
Constant Field Values

SQL_ROLE_PROPERTY

public static final java.lang.String SQL_ROLE_PROPERTY
See Also:
Constant Field Values

EMPTY_USER_PASSWORD

public static final org.firebirdsql.pool.FBConnectionPoolDataSource.UserPasswordPair EMPTY_USER_PASSWORD
Constructor Detail

FBConnectionPoolDataSource

public FBConnectionPoolDataSource()
Create instance of this class.

Method Detail

getLogger

protected org.firebirdsql.logging.Logger getLogger()
Description copied from class: AbstractConnectionPool
Get logger for this instance. By default all log messages belong to this class. Subclasses can override this behavior.

Specified by:
getLogger in class AbstractConnectionPool
Returns:
instance of Logger.

getConfiguration

public ConnectionPoolConfiguration getConfiguration()
Description copied from class: AbstractConnectionPool
Get configuration of this data source.

Specified by:
getConfiguration in class AbstractConnectionPool
Returns:
instance of ConnectionPoolConfiguration describing this data source.

getConnectionManager

protected PooledConnectionManager getConnectionManager()
Description copied from class: AbstractConnectionPool
Get instance of PooledConnectionManager responsible for instantiating pooled connections.

Specified by:
getConnectionManager in class AbstractConnectionPool
Returns:
instance of PooledConnectionManager

allocateConnection

public PooledObject allocateConnection(java.lang.Object key)
                                throws java.sql.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.
Throws:
java.sql.SQLException - if connection cannot be allocated.

getPoolName

protected java.lang.String getPoolName()
Get name of the connection queue.

Specified by:
getPoolName in class AbstractConnectionPool
Returns:
name of the connection queue.
See Also:
AbstractConnectionPool.getPoolName()

getLogWriter

public java.io.PrintWriter getLogWriter()
Specified by:
getLogWriter in interface javax.sql.ConnectionPoolDataSource

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
Specified by:
setLogWriter in interface javax.sql.ConnectionPoolDataSource

getLoginTimeout

public int getLoginTimeout()
Get login timeout.

Specified by:
getLoginTimeout in interface javax.sql.ConnectionPoolDataSource
Returns:
value set in setLoginTimeout(int) method or 0.

setLoginTimeout

public void setLoginTimeout(int seconds)
Set login timeout for new connection. Currently ignored.

Specified by:
setLoginTimeout in interface javax.sql.ConnectionPoolDataSource
Parameters:
seconds - how long pool should wait until new connection is granted.

getPooledConnection

protected PooledObject getPooledConnection(org.firebirdsql.pool.PooledConnectionQueue queue)
                                    throws java.sql.SQLException
Get pooled connection from the pooled queue.

Overrides:
getPooledConnection in class AbstractConnectionPool
Parameters:
queue - instance of PooledConnectionQueue where connection will be obtained.
Returns:
instance of PooledObject.
Throws:
java.sql.SQLException - if pooled connection cannot be obtained.

getPooledConnection

public javax.sql.PooledConnection getPooledConnection()
                                               throws java.sql.SQLException
Get pooled connection. This method will block until there will be free connection to return.

Specified by:
getPooledConnection in interface javax.sql.ConnectionPoolDataSource
Returns:
instance of PooledConnection.
Throws:
java.sql.SQLException - if pooled connection cannot be obtained.

getPooledConnection

public javax.sql.PooledConnection getPooledConnection(java.lang.String user,
                                                      java.lang.String password)
                                               throws java.sql.SQLException
Get pooled connection for the specified user name and password.

Specified by:
getPooledConnection in interface javax.sql.ConnectionPoolDataSource
Parameters:
user - user name.
password - password corresponding to specified user name.
Returns:
instance of PooledConnection for the specified credentials.
Throws:
java.sql.SQLException - always, this method is not yet implemented.

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent connectionEvent)
Notify about connection being closed.

Specified by:
connectionClosed in interface javax.sql.ConnectionEventListener
Parameters:
connectionEvent - instance of ConnectionEvent.

connectionErrorOccurred

public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
Notify about serious error when using the connection. Currently these events are ignored.

Specified by:
connectionErrorOccurred in interface javax.sql.ConnectionEventListener
Parameters:
event - instance of ConnectionEvent containing information about an error.

getFreeSize

public int getFreeSize()
                throws java.sql.SQLException
Description copied from class: AbstractConnectionPool
Get number of free connections in this pool. This method returns the number of free open connections to the specified database. It might return 0, but this does not mean that next request will block. This will happen only if getMaxSize() != 0 && getMaxSize() == getWorkingSize(), meaning that we have allocated maximum number of connections and all of them are in use.

Specified by:
getFreeSize in class AbstractConnectionPool
Returns:
number of free connections left.
Throws:
java.sql.SQLException

getTotalSize

public int getTotalSize()
                 throws java.sql.SQLException
Description copied from class: AbstractConnectionPool
Get total size of physical connections opened to the database.

Specified by:
getTotalSize in class AbstractConnectionPool
Returns:
total number of opened connections to the database.
Throws:
java.sql.SQLException

getWorkingSize

public int getWorkingSize()
                   throws java.sql.SQLException
Description copied from class: AbstractConnectionPool
Get number of connections that are in use.

Specified by:
getWorkingSize in class AbstractConnectionPool
Returns:
number of working connections.
Throws:
java.sql.SQLException

getDatabase

public java.lang.String getDatabase()
Get database to which we will connect.

Returns:
path to the database to which we will connect.

getMinConnections

public int getMinConnections()
Get minimum number of open physical connections that are kept in pool.

Specified by:
getMinConnections in interface ConnectionPoolConfiguration
Returns:
minimum number of open JDBC connections to open at startup.
See Also:
ConnectionPoolConfiguration.getMinConnections()

getMaxConnections

public int getMaxConnections()
Get maximum number of physical connections in the pool.

Specified by:
getMaxConnections in interface ConnectionPoolConfiguration
Returns:
maximum number of simultaneously open physical database connections, 0 if no limit exists.
See Also:
ConnectionPoolConfiguration.getMaxConnections()

getProperties

public java.util.Properties getProperties()
Get JDBC connection properties.


isPingable

public boolean isPingable()
Check if this configuation defines a pingable connection JDBC pool.

Specified by:
isPingable in interface ConnectionPoolConfiguration
Returns:
true if this pool supports pingable connections.
See Also:
ConnectionPoolConfiguration.isPingable()

getPingStatement

public java.lang.String getPingStatement()
Get SQL statement that will be used to "ping" the connection.

Specified by:
getPingStatement in interface ConnectionPoolConfiguration
Returns:
SQL statement that will be used to ping connection.
See Also:
ConnectionPoolConfiguration.getPingStatement()

getPingInterval

public int getPingInterval()
Get time interval, after which connection is marked to be pinged on first request to it.

Specified by:
getPingInterval in interface ConnectionPoolConfiguration
Returns:
number of milliseconds in the ping interval.
See Also:
ConnectionPoolConfiguration.getPingInterval()

setDatabase

public void setDatabase(java.lang.String database)
Set database name.

Parameters:
database - connection URL without "jdbc:firebirdsql:" prefix ("//localhost:3050/c:/database/employee.gdb") for example).

setMaxConnections

public void setMaxConnections(int maxConnections)
Set maximum number of open physical connections in the pool.

Parameters:
maxConnections - maximum allowed number of open connections in the pool.
See Also:
getMaxConnections()

setMinConnections

public void setMinConnections(int minConnections)
Set minimum number of open physical connections in the pool.

Parameters:
minConnections - minimum number of open connections in the pool.
See Also:
getMinConnections()

setPingInterval

public void setPingInterval(int pingInterval)
Set ping interval for the connections.

Parameters:
pingInterval - number of milliseconds after which connection is marked to "ping" before getting it from the pool or 0 to remove "pingable" property of this pool.
See Also:
getPingInterval()

setProperties

public void setProperties(java.util.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.
See Also:
getProperties()

setIntProperty

public void setIntProperty(java.lang.String name,
                           int value)
Set specified property as integer value.

Parameters:
name - name of the property.
value - value of the property.

getBlockingTimeout

public int getBlockingTimeout()
Get pool blocking timeout.

Specified by:
getBlockingTimeout in interface ConnectionPoolConfiguration
Returns:
pool blocking timeout in milliseconds, Integer.MAX_VALUE indicates blocking forever.
See Also:
ConnectionPoolConfiguration.getBlockingTimeout()

setBlockingTimeout

public void setBlockingTimeout(int blockingTimeout)
Set blocking timeout.

Parameters:
blockingTimeout - blocking timeout to set.
See Also:
ConnectionPoolConfiguration.getBlockingTimeout()

getRetryInterval

public int getRetryInterval()
Get retry interval.

Specified by:
getRetryInterval in interface ConnectionPoolConfiguration
Returns:
retry interval in milliseconds.
See Also:
ConnectionPoolConfiguration.getRetryInterval()

setRetryInterval

public void setRetryInterval(int retryInterval)
Set retry interval.

Parameters:
retryInterval - retry interval in milliseconds
See Also:
ConnectionPoolConfiguration.getBlockingTimeout()

getIdleTimeout

public int getIdleTimeout()
Get idle timeout.

Specified by:
getIdleTimeout in interface ConnectionPoolConfiguration
Returns:
idle timeout in milliseconds.

setIdleTimeout

public void setIdleTimeout(int idleTimeout)
Set idle timeout.

Parameters:
idleTimeout - idle timeout in milliseconds.

getType

public java.lang.String getType()
Get type of JDBC driver that will be used. Note, value returned by this method might be different from that used in setType(String) if you used synonym (either "TYPE4" or "TYPE2").

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.

setType

public void setType(java.lang.String type)
             throws java.sql.SQLException
Set type of JDBC driver to use.

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.
Throws:
java.sql.SQLException - if specified type is not known.

getGDSType

public GDSType getGDSType()
Get type of JDBC driver that is used.

Returns:
type of JDBC driver that is used.

setGDSType

public void setGDSType(GDSType gdsType)
Set type of the JDBC driver to use.

Parameters:
gdsType - type of the JDBC driver.

getNonStandardProperty

public java.lang.String getNonStandardProperty(java.lang.String key)

setNonStandardProperty

public void setNonStandardProperty(java.lang.String key,
                                   java.lang.String value)

getBlobBufferSize

public int getBlobBufferSize()

setBlobBufferSize

public void setBlobBufferSize(int blobBufferSize)

getEncoding

public java.lang.String getEncoding()

setEncoding

public void setEncoding(java.lang.String encoding)

getCharSet

public java.lang.String getCharSet()

setCharSet

public void setCharSet(java.lang.String charSet)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

getPassword

public java.lang.String getPassword()

setPassword

public void setPassword(java.lang.String password)

getSocketBufferSize

public int getSocketBufferSize()

setSocketBufferSize

public void setSocketBufferSize(int socketBufferSize)

getSqlRole

public java.lang.String getSqlRole()

setSqlRole

public void setSqlRole(java.lang.String sqlRole)

getTpbMapping

public java.lang.String getTpbMapping()

setTpbMapping

public void setTpbMapping(java.lang.String tpbMapping)

getUserName

public java.lang.String getUserName()

setUserName

public void setUserName(java.lang.String userName)

getObjectInstance

public java.lang.Object getObjectInstance(java.lang.Object obj,
                                          javax.naming.Name name,
                                          javax.naming.Context nameCtx,
                                          java.util.Hashtable environment)
                                   throws java.lang.Exception
Get object instance for the specified name in the specified context. This method constructs new datasource if obj represents Reference, whose factory class is equal to this class.

Specified by:
getObjectInstance in interface javax.naming.spi.ObjectFactory
Throws:
java.lang.Exception

getReference

public javax.naming.Reference getReference()
Get JDNI reference.

Specified by:
getReference in interface javax.naming.Referenceable
Returns:
instance of Reference.

setReference

public void setReference(javax.naming.Reference reference)
Set JNDI reference for this data source.

Specified by:
setReference in interface javax.resource.Referenceable
Parameters:
reference - JNDI reference.

getDefaultReference

public javax.naming.Reference getDefaultReference()
Get default JNDI reference for this datasource. This method is called if datasource is used in non-JCA environment.

Returns:
instance of Reference containing all information that allows to reconstruct the datasource.


Copyright © 2001 David Jencks and other authors. All rights reserved.