Intent

While programming databases it is important sometimes to prime the connection object. This is done by setting some additional attributes or parameters on a connection object using the "select" statements. As Aspire uses connection pools, the programmers rarely have control of the connection object directly (although it is possible). This facility is an attempt at providing a way to set these parameters using an event model.

The set of connection events generated by Aspire


public interface IConnectionEvents 
{
    public static String NAME = "aspire.db.connectionevents";
    public boolean onCreateConnection(Connection con) throws DBException;
    public boolean onPreCloseConnection(Connection con) throws DBException;
	
	//after getting the connection from the pool
    public boolean onGetConnection(Connection con) throws DBException;
	
	//before placing the connection in the pool
    public boolean onPutConnection(Connection con) throws DBException;
}

Property file entries on how to use this


request.aspire.db.connectionevents.classname=\
com.ai.db.events.ConnectionEventDistributor

request.aspire.db.connectionevents.eventHandlerList=\
handler1,handler2
 
#Log the connection events
request.handler1.classname=\
com.ai.db.events.ConnectionEventLogger
 
#Call a select statement to set certain connection properties
request.handler2.classname=\
com.ai.db.events.RequestBasedConnectionEventDemultiplexer

request.handler2.onCreateConnectionRequestName=stmt1
request.handler2.onPreCloseConnectionRequestName=stmt2
request.handler2.onGetConnectionRequestName=stmt3
request.handler2.onPutConnectionRequestName=stmt3
 
request.stmt1.classname=com.ai.db.DBRequestExecutor2
request.stmt1.stmt=some select statement
#Don't specify the usual .db here

Build information

Make sure you have build 22.1 to exercise this functionality.

What package is this implemented

com.ai.db.events.*;

General comments

In the example above the handler1 will log all the calls to all the connection based events. The handler2 actually allows you to specify select statements at each event level.

Satya - Tuesday, October 18, 2005 11:24:08 AM

Release 22.1 notes

Release 22.1 notes

Satya - Tuesday, October 18, 2005 1:20:49 PM

I forgot, You will need a new connection manager to make this work ...

com.ai.db.events.EventEnabledConnectionManager2

Locate the connection manager in aspire.properties and use this class instead. I think the current connection manager is called something like "ConnectionPoolConnectionManager1".