com.jolbox.bonecp.hooks
Class AbstractConnectionHook

java.lang.Object
  extended by com.jolbox.bonecp.hooks.AbstractConnectionHook
All Implemented Interfaces:
ConnectionHook

public abstract class AbstractConnectionHook
extends java.lang.Object
implements ConnectionHook

A no-op implementation of the ConnectionHook interface.

Author:
wallacew

Constructor Summary
AbstractConnectionHook()
           
 
Method Summary
 void onAcquire(ConnectionHandle connection)
          Called upon getting a new connection from the JDBC driver (and prior to inserting into the pool).
 boolean onAcquireFail(java.lang.Throwable t, AcquireFailConfig acquireConfig)
          Called on attempting (and failing) to acquire a connection.
 void onAfterStatementExecute(ConnectionHandle conn, StatementHandle statement, java.lang.String sql, java.util.Map<java.lang.Object,java.lang.Object> params)
          Called right after a statement has executed.
 void onBeforeStatementExecute(ConnectionHandle conn, StatementHandle statement, java.lang.String sql, java.util.Map<java.lang.Object,java.lang.Object> params)
          Called before a statement is about to execute.
 void onCheckIn(ConnectionHandle connection)
          Called when the connection is about to be returned to the pool.
 void onCheckOut(ConnectionHandle connection)
          Called when the connection is extracted from the pool and about to be given to the application.
 boolean onConnectionException(ConnectionHandle connection, java.lang.String state, java.lang.Throwable t)
          Called whenever an exception on a connection occurs.
 void onDestroy(ConnectionHandle connection)
          Called when the connection is about to be completely removed from the pool.
 void onQueryExecuteTimeLimitExceeded(ConnectionHandle handle, java.sql.Statement statement, java.lang.String sql, java.util.Map<java.lang.Object,java.lang.Object> logParams)
          Called when a query execute time limit has been set and an executing query took longer to than the limit to return control to the application.
 void onQueryExecuteTimeLimitExceeded(java.lang.String sql, java.util.Map<java.lang.Object,java.lang.Object> logParams)
          Deprecated. 
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractConnectionHook

public AbstractConnectionHook()
Method Detail

onAcquire

public void onAcquire(ConnectionHandle connection)
Description copied from interface: ConnectionHook
Called upon getting a new connection from the JDBC driver (and prior to inserting into the pool). You may call connection.getInternalConnection() to obtain a handle to the actual (unwrapped) connection obtained from the driver.

Specified by:
onAcquire in interface ConnectionHook
Parameters:
connection - Handle to the new connection

onCheckIn

public void onCheckIn(ConnectionHandle connection)
Description copied from interface: ConnectionHook
Called when the connection is about to be returned to the pool.

Specified by:
onCheckIn in interface ConnectionHook
Parameters:
connection - being returned to pool.

onCheckOut

public void onCheckOut(ConnectionHandle connection)
Description copied from interface: ConnectionHook
Called when the connection is extracted from the pool and about to be given to the application.

Specified by:
onCheckOut in interface ConnectionHook
Parameters:
connection - about to given to the app.

onDestroy

public void onDestroy(ConnectionHandle connection)
Description copied from interface: ConnectionHook
Called when the connection is about to be completely removed from the pool. Careful with this hook; the connection might be marked as being broken. Use connection.isPossiblyBroken() to determine if the connection has triggered an exception at some point.

Specified by:
onDestroy in interface ConnectionHook

onAcquireFail

public boolean onAcquireFail(java.lang.Throwable t,
                             AcquireFailConfig acquireConfig)
Description copied from interface: ConnectionHook
Called on attempting (and failing) to acquire a connection. Note that implementing this means that acquireRetry/delay logic will be overridden by this code.

Specified by:
onAcquireFail in interface ConnectionHook
Parameters:
t - Exception that occurred.
acquireConfig - handle containing retry delay, retry attempts etc.
Returns:
Return true to attempt the connection again.

onQueryExecuteTimeLimitExceeded

public void onQueryExecuteTimeLimitExceeded(ConnectionHandle handle,
                                            java.sql.Statement statement,
                                            java.lang.String sql,
                                            java.util.Map<java.lang.Object,java.lang.Object> logParams)
Description copied from interface: ConnectionHook
Called when a query execute time limit has been set and an executing query took longer to than the limit to return control to the application.

Specified by:
onQueryExecuteTimeLimitExceeded in interface ConnectionHook
Parameters:
handle - handle to the connection
statement - statement handle.
sql - SQL statement that was used.
logParams - Parameters used in this statement.

onQueryExecuteTimeLimitExceeded

@Deprecated
public void onQueryExecuteTimeLimitExceeded(java.lang.String sql,
                                                       java.util.Map<java.lang.Object,java.lang.Object> logParams)
Deprecated. 

Description copied from interface: ConnectionHook
Deprecated. Use the similarly named hook having more parameters instead. Called when a query execute time limit has been set and an executing query took longer to than the limit to return control to the application.

Specified by:
onQueryExecuteTimeLimitExceeded in interface ConnectionHook
Parameters:
sql - SQL statement that was used.
logParams - Parameters used in this statement.

onConnectionException

public boolean onConnectionException(ConnectionHandle connection,
                                     java.lang.String state,
                                     java.lang.Throwable t)
Description copied from interface: ConnectionHook
Called whenever an exception on a connection occurs. This exception may be a connection failure, a DB failure or a non-fatal logical failure (eg Duplicate key exception).

SQLSTATE Value

Value Meaning

08001 The application requester is unable to establish the connection.

08002 The connection already exists.

08003 The connection does not exist.

08004 The application server rejected establishment of the connection.

08007 Transaction resolution unknown.

08502 The CONNECT statement issued by an application process running with a SYNCPOINT of TWOPHASE has failed, because no transaction manager is available.

08504 An error was encountered while processing the specified path rename configuration file.

SQL Failure codes 08001 & 08007 indicate that the database is broken/died (and thus all remaining connections are killed off).

Anything else will be taken as the connection (not the db) being broken.

Note: You may use pool.isConnectionHandleAlive(connection) to verify if the connection is in a usable state again. Note 2: As in all interceptor hooks, this method may be called concurrently so any implementation must be thread-safe.

Specified by:
onConnectionException in interface ConnectionHook
Parameters:
connection - The handle that triggered this error
state - the SQLState error code.
t - Exception that caused this failure.
Returns:
Returning true means: when you eventually close off this connection, test to see if the connection is still alive and discard it if not (this is the normal behaviour). Returning false pretends that the connection is still ok when the connection is closed (your application will still receive the original exception that was thrown).

onBeforeStatementExecute

public void onBeforeStatementExecute(ConnectionHandle conn,
                                     StatementHandle statement,
                                     java.lang.String sql,
                                     java.util.Map<java.lang.Object,java.lang.Object> params)
Description copied from interface: ConnectionHook
Called before a statement is about to execute. Tip: You may use PoolUtil.fillLogParams(...) to get the sql statement with the '?' replaced with the actual values.

Specified by:
onBeforeStatementExecute in interface ConnectionHook
Parameters:
conn - Connection handle
statement - Handle to the statement
sql - SQL statement about to be executed.
params - parameters currently bound to the statement

onAfterStatementExecute

public void onAfterStatementExecute(ConnectionHandle conn,
                                    StatementHandle statement,
                                    java.lang.String sql,
                                    java.util.Map<java.lang.Object,java.lang.Object> params)
Description copied from interface: ConnectionHook
Called right after a statement has executed. Tip: You may use PoolUtil.fillLogParams(...) to get the sql statement with the '?' replaced with the actual values.

Specified by:
onAfterStatementExecute in interface ConnectionHook
Parameters:
conn - Connection handle
statement - Handle to the statement
sql - SQL statement about to be executed.
params - parameters currently bound to the statement


Copyright © 2009-2011 JolBox. All Rights Reserved.