org.firebirdsql.pool
Class FBConnectionPoolDataSource

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

public class FBConnectionPoolDataSource
extends BasicAbstractConnectionPool
implements PooledConnectionManager, javax.sql.ConnectionPoolDataSource, javax.sql.XADataSource, PooledConnectionEventListener, FirebirdPool

Connection pool for Firebird JDBC driver. Following properties are supported:

Author:
Roman Rokytskyy
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.firebirdsql.pool.AbstractConnectionPool
AbstractConnectionPool.UserPasswordPair
 
Field Summary
static java.lang.String BLOB_BUFFER_PROPERTY
           
static AbstractConnectionPool.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.
protected  BasicAbstractConnectionPool createObjectInstance()
           
 int getBlobBufferSize()
           
 java.lang.String getCharSet()
           
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.
protected  org.firebirdsql.logging.Logger getLogger()
          Get logger for this instance.
 int getLoginTimeout()
          Get login timeout.
 java.io.PrintWriter getLogWriter()
           
 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()
           
 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.
 java.lang.String getRoleName()
           
 int getSocketBufferSize()
           
 java.lang.String getSqlRole()
          Deprecated. please use getRoleName() instead.
 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.
 javax.sql.XAConnection getXAConnection()
          Get XA connection.
 javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String password)
          Get XA connection for the specified user name and password.
 boolean isPingable()
          Check if this configuation defines a pingable connection JDBC pool.
 void physicalConnectionClosed(javax.sql.ConnectionEvent connectionEvent)
          Notify about physical connection being closed.
 void physicalConnectionDeallocated(javax.sql.ConnectionEvent connectionEvent)
          Notify about the deallocation of the physical connection.
 void setBlobBufferSize(int blobBufferSize)
           
 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 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 setNonStandardProperty(java.lang.String propertyMapping)
          Method that allows setting non-standard property in the form "key=value" form.
 void setNonStandardProperty(java.lang.String key, java.lang.String value)
           
 void setPassword(java.lang.String password)
           
 void setProperties(java.util.Properties properties)
          Set JDBC properties that will be passed when opening a connection.
 void setRoleName(java.lang.String roleName)
           
 void setSocketBufferSize(int socketBufferSize)
           
 void setSqlRole(java.lang.String sqlRole)
          Deprecated. please use setRoleName(String) instead.
 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.BasicAbstractConnectionPool
deserialize, getBlockingTimeout, getConfiguration, getIdleTimeout, getIsolation, getMaxConnections, getMaxIdleTime, getMaxPoolSize, getMaxStatements, getMinConnections, getMinPoolSize, getPingInterval, getRefAddr, getReference, getRetryInterval, getTransactionIsolationLevel, isKeepStatements, isPooling, isStatementPooling, serialize, setBlockingTimeout, setIdleTimeout, setIsolation, setKeepStatements, setMaxConnections, setMaxIdleTime, setMaxPoolSize, setMaxStatements, setMinConnections, setMinPoolSize, setPingInterval, setPingStatement, setPooling, setReference, setRetryInterval, setStatementPooling, setTransactionIsolationLevel
 
Methods inherited from class org.firebirdsql.pool.AbstractConnectionPool
finalize, getQueue, physicalConnectionDeallocated, pooledObjectReleased, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.firebirdsql.pool.FirebirdPool
getBlockingTimeout, getIsolation, getMaxIdleTime, getMaxPoolSize, getMaxStatements, getMinPoolSize, getPingInterval, getTransactionIsolationLevel, isPooling, isStatementPooling, setBlockingTimeout, setIsolation, setMaxIdleTime, setMaxPoolSize, setMaxStatements, setMinPoolSize, setPingInterval, setPooling, setStatementPooling, setTransactionIsolationLevel, shutdown
 

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 AbstractConnectionPool.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.

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
Specified by:
getLogWriter in class BasicAbstractConnectionPool

setLogWriter

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

getLoginTimeout

public int getLoginTimeout()
Get login timeout.

Specified by:
getLoginTimeout in interface javax.sql.ConnectionPoolDataSource
Specified by:
getLoginTimeout in class BasicAbstractConnectionPool
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
Specified by:
setLoginTimeout in class BasicAbstractConnectionPool
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
Specified by:
getPooledConnection in class BasicAbstractConnectionPool
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
Specified by:
getPooledConnection in class BasicAbstractConnectionPool
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.

getXAConnection

public javax.sql.XAConnection getXAConnection()
                                       throws java.sql.SQLException
Get XA connection. This method will block until there will be free connection to return.

Specified by:
getXAConnection in interface javax.sql.XADataSource
Returns:
instance of XAConnection.
Throws:
java.sql.SQLException - if pooled connection cannot be obtained.

getXAConnection

public javax.sql.XAConnection getXAConnection(java.lang.String user,
                                              java.lang.String password)
                                       throws java.sql.SQLException
Get XA connection for the specified user name and password.

Specified by:
getXAConnection in interface javax.sql.XADataSource
Parameters:
user - user name.
password - password corresponding to specified user name.
Returns:
instance of XAConnection 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.

physicalConnectionClosed

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

Specified by:
physicalConnectionClosed in interface PooledConnectionEventListener
Parameters:
connectionEvent - instance of ConnectionEvent.

physicalConnectionDeallocated

public void physicalConnectionDeallocated(javax.sql.ConnectionEvent connectionEvent)
Notify about the deallocation of the physical connection.

Specified by:
physicalConnectionDeallocated in interface PooledConnectionEventListener
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 interface FirebirdPool
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 interface FirebirdPool
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 interface FirebirdPool
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.

Specified by:
getDatabase in interface FirebirdPool
Returns:
path to the database to which we will connect.

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
Overrides:
isPingable in class BasicAbstractConnectionPool
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
Overrides:
getPingStatement in class BasicAbstractConnectionPool
See Also:
ConnectionPoolConfiguration.getPingStatement()

setDatabase

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

Specified by:
setDatabase in interface FirebirdPool
Parameters:
database - connection URL without "jdbc:firebirdsql:" prefix ("//localhost:3050/c:/database/employee.gdb") for example).

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.

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").

Specified by:
getType in interface FirebirdPool
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.

Specified by:
setType in interface FirebirdPool
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)
Specified by:
getNonStandardProperty in interface FirebirdPool

setNonStandardProperty

public void setNonStandardProperty(java.lang.String key,
                                   java.lang.String value)
Specified by:
setNonStandardProperty in interface FirebirdPool

setNonStandardProperty

public void setNonStandardProperty(java.lang.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 FirebirdPool
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.

getBlobBufferSize

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

setBlobBufferSize

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

getEncoding

public java.lang.String getEncoding()
Specified by:
getEncoding in interface FirebirdPool

setEncoding

public void setEncoding(java.lang.String encoding)
Specified by:
setEncoding in interface FirebirdPool

getCharSet

public java.lang.String getCharSet()
Specified by:
getCharSet in interface FirebirdPool

setCharSet

public void setCharSet(java.lang.String charSet)
                throws java.sql.SQLException
Specified by:
setCharSet in interface FirebirdPool
Throws:
java.sql.SQLException

getPassword

public java.lang.String getPassword()
Specified by:
getPassword in interface FirebirdPool

setPassword

public void setPassword(java.lang.String password)
Specified by:
setPassword in interface FirebirdPool

getSocketBufferSize

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

setSocketBufferSize

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

getRoleName

public java.lang.String getRoleName()
Specified by:
getRoleName in interface FirebirdPool

setRoleName

public void setRoleName(java.lang.String roleName)
Specified by:
setRoleName in interface FirebirdPool

getSqlRole

public java.lang.String getSqlRole()
Deprecated. please use getRoleName() instead.


setSqlRole

public void setSqlRole(java.lang.String sqlRole)
Deprecated. please use setRoleName(String) instead.


getTpbMapping

public java.lang.String getTpbMapping()
Specified by:
getTpbMapping in interface FirebirdPool

setTpbMapping

public void setTpbMapping(java.lang.String tpbMapping)
Specified by:
setTpbMapping in interface FirebirdPool

getUserName

public java.lang.String getUserName()
Specified by:
getUserName in interface FirebirdPool

setUserName

public void setUserName(java.lang.String userName)
Specified by:
setUserName in interface FirebirdPool

getDefaultReference

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

Overrides:
getDefaultReference in class BasicAbstractConnectionPool
Returns:
instance of Reference containing all information that allows to reconstruct the datasource.

createObjectInstance

protected BasicAbstractConnectionPool createObjectInstance()
Specified by:
createObjectInstance in class BasicAbstractConnectionPool

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
Description copied from class: BasicAbstractConnectionPool
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
Overrides:
getObjectInstance in class BasicAbstractConnectionPool
Throws:
java.lang.Exception


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