org.firebirdsql.pool

Class PingablePooledConnection

Implemented Interfaces:
PooledConnection, PooledObject, org.firebirdsql.pool.XConnectionManager, org.firebirdsql.pool.XPingableConnection, XStatementManager

public class PingablePooledConnection
extends java.lang.Object
implements PooledConnection, PooledObject, org.firebirdsql.pool.XConnectionManager, org.firebirdsql.pool.XPingableConnection, XStatementManager

This class implements javax.sql.PooledConnection interface.
Author:
Roman Rokytskyy

Field Summary

protected Connection
jdbcConnection

Constructor Summary

PingablePooledConnection(Connection connection, String pingStatement, int pingInterval, boolean statementPooling, int maxStatements, boolean keepStatements)
PingablePooledConnection(Connection connection, boolean statementPooling, int maxStatements, boolean keepStatements)

Method Summary

void
addConnectionEventListener(ConnectionEventListener listener)
Add connection listener to be notified about connection events.
void
close()
Close this pooled connection.
protected void
configureConnectionDefaults(Connection connection)
Configure default values for this connection.
void
connectionClosed(org.firebirdsql.pool.PooledConnectionHandler connection)
void
connectionCommitted(org.firebirdsql.pool.PooledConnectionHandler connection)
Notify this class that transaction was committed.
void
connectionErrorOccured(org.firebirdsql.pool.PooledConnectionHandler connection, SQLException ex)
void
connectionRolledBack(org.firebirdsql.pool.PooledConnectionHandler connection)
Notify this class that transaction was rolled back.
void
deallocate()
Deallocate this object.
Connection
getConnection()
Get JDBC connection corresponding to this pooled connection instance.
long
getLastPingTime()
Get the time when connection was pinged last time.
protected org.firebirdsql.logging.Logger
getLogChannel()
PreparedStatement
getPreparedStatement(String statement, int resultSetType, int resultSetConcurrency)
Handle Connection.prepareStatement(String) method call.
protected void
internalClose()
Close this connection.
boolean
isInPool()
Check whether this object is currently in pool or had been released to the application.
boolean
isKeepStatements()
boolean
isStatementPooling()
boolean
isValid()
Check if this pooled connection is still valid.
boolean
isValid(org.firebirdsql.pool.PooledConnectionHandler connection)
boolean
ping()
Ping connection by executing a ping statement.
org.firebirdsql.pool.XCachablePreparedStatement
prepareStatement(String statement, int resultSetType, int resultSetConcurrency, boolean cached)
Prepare the specified statement and wrap it with cache notification wrapper.
void
removeConnectionEventListener(ConnectionEventListener listener)
Remove connection listener from this pooled connection.
void
setDefaultTransactionIsolation(int isolation)
void
setInPool(boolean inPool)
Set the "inPool" flag to this object.
void
statementClosed(String statement, Object proxy)
Handle java.sql.PreparedStatement.close() method.

Field Details

jdbcConnection

protected Connection jdbcConnection

Constructor Details

PingablePooledConnection

protected PingablePooledConnection(Connection connection,
                                   String pingStatement,
                                   int pingInterval,
                                   boolean statementPooling,
                                   int maxStatements,
                                   boolean keepStatements)
            throws SQLException

PingablePooledConnection

protected PingablePooledConnection(Connection connection,
                                   boolean statementPooling,
                                   int maxStatements,
                                   boolean keepStatements)
            throws SQLException

Method Details

addConnectionEventListener

public void addConnectionEventListener(ConnectionEventListener listener)
Add connection listener to be notified about connection events.
Parameters:
listener - listener to add.

close

public void close()
            throws SQLException
Close this pooled connection. This operation closes physical connection to the database. Should not be called by applications directly.

configureConnectionDefaults

protected void configureConnectionDefaults(Connection connection)
            throws SQLException
Configure default values for this connection.
Parameters:
connection - instance of Connection to configure.

connectionClosed

public void connectionClosed(org.firebirdsql.pool.PooledConnectionHandler connection)
            throws SQLException
Specified by:
connectionClosed in interface org.firebirdsql.pool.XConnectionManager

connectionCommitted

public void connectionCommitted(org.firebirdsql.pool.PooledConnectionHandler connection)
            throws SQLException
Notify this class that transaction was committed.
Specified by:
connectionCommitted in interface org.firebirdsql.pool.XConnectionManager
Parameters:
connection - connection that was commited.
See Also:
XConnectionManager.connectionCommitted(PooledConnectionHandler)

connectionErrorOccured

public void connectionErrorOccured(org.firebirdsql.pool.PooledConnectionHandler connection,
                                   SQLException ex)
Specified by:
connectionErrorOccured in interface org.firebirdsql.pool.XConnectionManager

connectionRolledBack

public void connectionRolledBack(org.firebirdsql.pool.PooledConnectionHandler connection)
            throws SQLException
Notify this class that transaction was rolled back.
Specified by:
connectionRolledBack in interface org.firebirdsql.pool.XConnectionManager
Parameters:
connection - connection that was commited.
See Also:
XConnectionManager.connectionRolledBack(PooledConnectionHandler)

deallocate

public void deallocate()
Deallocate this object.
Specified by:
deallocate in interface PooledObject

getConnection

public Connection getConnection()
            throws SQLException
Get JDBC connection corresponding to this pooled connection instance.
Returns:
instance of Connection

getLastPingTime

public long getLastPingTime()
Get the time when connection was pinged last time.
Specified by:
getLastPingTime in interface org.firebirdsql.pool.XConnectionManager
getLastPingTime in interface org.firebirdsql.pool.XPingableConnection
Returns:
time of last ping time.

getLogChannel

protected org.firebirdsql.logging.Logger getLogChannel()

getPreparedStatement

public PreparedStatement getPreparedStatement(String statement,
                                              int resultSetType,
                                              int resultSetConcurrency)
            throws SQLException
Handle Connection.prepareStatement(String) method call. This method check internal cache first and returns prepared statement if found. Otherwise, it prepares statement and caches it.
Specified by:
getPreparedStatement in interface org.firebirdsql.pool.XConnectionManager
Parameters:
statement - statement to prepare.
Returns:
instance of PreparedStatement corresponding to the statement.

internalClose

protected void internalClose()
            throws SQLException
Close this connection.

isInPool

public boolean isInPool()
Check whether this object is currently in pool or had been released to the application.
Specified by:
isInPool in interface PooledObject
Returns:
true if the object is currently in pool.

isKeepStatements

public boolean isKeepStatements()

isStatementPooling

public boolean isStatementPooling()

isValid

public boolean isValid()
Check if this pooled connection is still valid.
Specified by:
isValid in interface PooledObject
Returns:
true if this pooled connection is still valid.

isValid

public boolean isValid(org.firebirdsql.pool.PooledConnectionHandler connection)
Specified by:
isValid in interface org.firebirdsql.pool.XConnectionManager

ping

public boolean ping()
Ping connection by executing a ping statement.
Specified by:
ping in interface org.firebirdsql.pool.XConnectionManager
ping in interface org.firebirdsql.pool.XPingableConnection

prepareStatement

public org.firebirdsql.pool.XCachablePreparedStatement prepareStatement(String statement,
                                                                        int resultSetType,
                                                                        int resultSetConcurrency,
                                                                        boolean cached)
            throws SQLException
Prepare the specified statement and wrap it with cache notification wrapper.
Specified by:
prepareStatement in interface XStatementManager
Parameters:
statement - sattement to prepare.
Returns:
prepared and wrapped statement.

removeConnectionEventListener

public void removeConnectionEventListener(ConnectionEventListener listener)
Remove connection listener from this pooled connection.
Parameters:
listener - listener to remove.

setDefaultTransactionIsolation

public void setDefaultTransactionIsolation(int isolation)

setInPool

public void setInPool(boolean inPool)
Set the "inPool" flag to this object. This method should be called only by the pool implementation.
Specified by:
setInPool in interface PooledObject
Parameters:
inPool - true if object is in pool, otherwise false.

statementClosed

public void statementClosed(String statement,
                            Object proxy)
            throws SQLException
Handle java.sql.PreparedStatement.close() method. This implementation dereferences proxy in cache.
Specified by:
statementClosed in interface XStatementManager
Parameters:
statement - SQL statement corresponding to the proxy.
proxy - proxy wrapping the connection.

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