org.logicalcobwebs.proxool
Class ConnectionResetter

java.lang.Object
  extended by org.logicalcobwebs.proxool.ConnectionResetter

public class ConnectionResetter
extends java.lang.Object

Responsible for resetting a Connection to its default state when it is returned to the pool. It must be initialised by the first Connection that is made (for each pool) so that we don't make any assumptions about what the default values are.

Since:
Proxool 0.5
Version:
$Revision: 1.15 $, $Date: 2005/10/07 08:21:53 $
Author:
Bill Horsman (bill@logicalcobwebs.co.uk), $Author: billhorsman $ (current maintainer)

Field Summary
private  java.util.Map accessorMutatorMap
           
private  java.util.Map defaultValues
           
private  java.lang.String driverName
           
private  boolean initialised
           
private  Log log
           
protected static java.lang.String MUTATOR_PREFIX
          We use this to guess if we are changing a property that will need resetting
protected static boolean triggerResetException
           
 
Constructor Summary
protected ConnectionResetter(Log log, java.lang.String driverName)
          Pass in the log to use
 
Method Summary
private  void addReset(java.lang.String accessorName, java.lang.String mutatorName)
          Add a pair of methods that need resetting each time a connection is put back in the pool
protected  void initialise(java.sql.Connection connection)
          This gets called every time we make a Connection.
private static boolean isTriggerResetException()
           
protected  boolean reset(java.sql.Connection connection, java.lang.String id)
          Reset this connection to its default values.
protected static void setTriggerResetException(boolean triggerResetException)
          Called by a unit test.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private Log log

initialised

private boolean initialised
See Also:
initialise(java.sql.Connection)

accessorMutatorMap

private java.util.Map accessorMutatorMap
See Also:
addReset(java.lang.String, java.lang.String), reset(java.sql.Connection, java.lang.String)

defaultValues

private java.util.Map defaultValues
See Also:
addReset(java.lang.String, java.lang.String), reset(java.sql.Connection, java.lang.String)

MUTATOR_PREFIX

protected static final java.lang.String MUTATOR_PREFIX
We use this to guess if we are changing a property that will need resetting

See Also:
Constant Field Values

driverName

private java.lang.String driverName

triggerResetException

protected static boolean triggerResetException
See Also:
isTriggerResetException()
Constructor Detail

ConnectionResetter

protected ConnectionResetter(Log log,
                             java.lang.String driverName)
Pass in the log to use

Parameters:
log - debug information sent here
Method Detail

addReset

private void addReset(java.lang.String accessorName,
                      java.lang.String mutatorName)
Add a pair of methods that need resetting each time a connection is put back in the pool

Parameters:
accessorName - the name of the "getter" method (e.g. getAutoCommit)
mutatorName - teh name of the "setter" method (e.g. setAutoCommit)

initialise

protected void initialise(java.sql.Connection connection)
This gets called every time we make a Connection. Not that often really, so it's ok to synchronize a bit.

Parameters:
connection - this will be used to get all the default values

reset

protected boolean reset(java.sql.Connection connection,
                        java.lang.String id)
Reset this connection to its default values. If anything goes wrong, it is logged as a warning or info but it silently continues.

Parameters:
connection - to be reset
id - used in log messages
Returns:
true if the reset was error free, or false if it encountered errors. (in which case it should probably not be reused)

isTriggerResetException

private static boolean isTriggerResetException()

setTriggerResetException

protected static void setTriggerResetException(boolean triggerResetException)
Called by a unit test.

Parameters:
triggerResetException - true it we should trigger a pretend exception.
See Also:
isTriggerResetException()