org.enhydra.jdbc.pool
Class StandardPoolDataSource

java.lang.Object
  extended byorg.enhydra.jdbc.util.JdbcUtil
      extended byorg.enhydra.jdbc.core.CoreDataSource
          extended byorg.enhydra.jdbc.pool.StandardPoolDataSource
All Implemented Interfaces:
javax.sql.ConnectionEventListener, javax.sql.DataSource, java.util.EventListener, javax.naming.spi.ObjectFactory, PoolHelper, javax.naming.Referenceable, java.io.Serializable
Direct Known Subclasses:
StandardXAPoolDataSource

public class StandardPoolDataSource
extends CoreDataSource
implements javax.sql.DataSource, PoolHelper, javax.sql.ConnectionEventListener

StandardPoolDataSource class allows to make some operations on PooledConnection. It implements PoolHelper for the 3 methods :

create : create a PooledConnection

create(user,password) : create a PooledConnection with an other user/password

testThisObject : check if the object is still valid

checkThisObject : check if the object is closed

expire : kill the object

See Also:
Serialized Form

Field Summary
 javax.sql.ConnectionPoolDataSource cpds
           
 java.lang.String dataSourceName
           
 org.apache.commons.logging.Log glog
           
 javax.naming.Context ictx
           
 java.lang.String jdbcTestStmt
           
 boolean onOff
           
 GenericPool pool
           
 
Fields inherited from class org.enhydra.jdbc.core.CoreDataSource
logWriter, password, user
 
Fields inherited from class org.enhydra.jdbc.util.JdbcUtil
log
 
Constructor Summary
StandardPoolDataSource()
          Constructor
StandardPoolDataSource(javax.sql.ConnectionPoolDataSource cc)
          Constructor
StandardPoolDataSource(javax.sql.ConnectionPoolDataSource cc, int initSize)
          Constructor
StandardPoolDataSource(int initSize)
          Constructor
 
Method Summary
 boolean checkThisObject(java.lang.Object o)
          This method tests if a connection is closed or not
 void connectionClosed(javax.sql.ConnectionEvent event)
          Invoked when the application calls close() on its representation of the connection
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
          connectionErrorOccurred and connectionClosed are methods from ConnectionEventListener interface Invoked when a fatal connection error occurs, just before an SQLException is thrown to the application
 GenerationObject create()
           
 GenerationObject create(java.lang.String _user, java.lang.String _password)
           
 void expire(java.lang.Object o)
          object specific work to kill the object
 int getCheckLevelObject()
           
 java.sql.Connection getConnection()
          getConnection allows to get an object from the pool and returns it to the user.
 java.sql.Connection getConnection(java.lang.String _user, java.lang.String _password)
          getConnection allows to get an object from the pool and returns it to the user.
 java.lang.String getDataSourceName()
           
 long getDeadLockMaxWait()
           
 long getDeadLockRetryWait()
           
 int getGeneration()
           
 java.lang.String getJdbcTestStmt()
           
 long getLifeTime()
           
 int getLockedObjectCount()
           
 java.io.PrintWriter getLogWriter()
           
 int getMaxSize()
           
 int getMinSize()
           
 java.lang.Object getObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable env)
          Methods inherited from ObjectFactory
 javax.naming.Reference getReference()
          Retrieves the Reference of this object.
 long getSleepTime()
           
 int getUnlockedObjectCount()
           
 boolean isGC()
           
 void setCheckLevelObject(int checkLevelObject)
          set the check level of the pooled object before using them
 void setDataSourceName(java.lang.String dataSourceName)
          Set up the data source name, get the initial context, and lookup in JNDI to obtain a reference of the DataSourceName this method must be called before a getConnection (in this case an exception is returned
 void setDeadLockMaxWait(long deadLock)
          set the global time the pool can wait for a free object
 void setDeadLockRetryWait(long loopWait)
          set the time before 2 tries when trying to obtain an object from the pool
 void setDebug(boolean debug)
          set the debug flag
 void setGC(boolean gc)
          set the garbage collection option
 void setGeneration(int generation)
          set the generation number for future connection, the generation number is used to identify a group a created objects
 void setJdbcTestStmt(java.lang.String jdbcTestStmt)
          set the String to test the jdbc connection before using it
 void setLifeTime(long lifeTime)
          set the life time of the pooled objects
 void setLogWriter(java.io.PrintWriter logWriter)
          set the logwriter for the current object, the logwriter will be use by the current object and by the generic pool
 void setMaxSize(int maxSize)
          set the maximum size of the pool
 void setMinSize(int minSize)
          set the minimum size of the pool
 void setSleepTime(long sleepTime)
          set the sleep time of pooled objects
 void setThreadFactory(JdbcThreadFactory tf)
          Override this so that the pool's tf gets set as well
 void shutdown(boolean force)
          shutdown is a placeholder for datasources which should shut down any pools which they maintain.
 void stopPool()
          stop method to switch off the pool
 boolean testThisObject(java.lang.Object o)
          This method tests if a connection is valid or not
 java.lang.String toString()
           
 
Methods inherited from class org.enhydra.jdbc.core.CoreDataSource
getDescription, getLoginTimeout, getPassword, getThreadFactory, getUser, isDebug, isVerbose, setDescription, setLoginTimeout, setPassword, setUser, setVerbose
 
Methods inherited from class org.enhydra.jdbc.util.JdbcUtil
setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.sql.DataSource
getLoginTimeout, setLoginTimeout
 

Field Detail

cpds

public javax.sql.ConnectionPoolDataSource cpds

pool

public GenericPool pool

dataSourceName

public java.lang.String dataSourceName

jdbcTestStmt

public java.lang.String jdbcTestStmt

onOff

public boolean onOff

ictx

public javax.naming.Context ictx

glog

public org.apache.commons.logging.Log glog
Constructor Detail

StandardPoolDataSource

public StandardPoolDataSource()
Constructor


StandardPoolDataSource

public StandardPoolDataSource(int initSize)
Constructor


StandardPoolDataSource

public StandardPoolDataSource(javax.sql.ConnectionPoolDataSource cc)
Constructor


StandardPoolDataSource

public StandardPoolDataSource(javax.sql.ConnectionPoolDataSource cc,
                              int initSize)
Constructor

Method Detail

setDataSourceName

public void setDataSourceName(java.lang.String dataSourceName)
Set up the data source name, get the initial context, and lookup in JNDI to obtain a reference of the DataSourceName this method must be called before a getConnection (in this case an exception is returned


getDataSourceName

public java.lang.String getDataSourceName()

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
getConnection allows to get an object from the pool and returns it to the user. In this case, we return an PooledConnection

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String _user,
                                         java.lang.String _password)
                                  throws java.sql.SQLException
getConnection allows to get an object from the pool and returns it to the user. In this case, we return an PooledConnection

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

connectionErrorOccurred

public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
connectionErrorOccurred and connectionClosed are methods from ConnectionEventListener interface Invoked when a fatal connection error occurs, just before an SQLException is thrown to the application

Specified by:
connectionErrorOccurred in interface javax.sql.ConnectionEventListener

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent event)
Invoked when the application calls close() on its representation of the connection

Specified by:
connectionClosed in interface javax.sql.ConnectionEventListener

expire

public void expire(java.lang.Object o)
object specific work to kill the object

Specified by:
expire in interface PoolHelper

checkThisObject

public boolean checkThisObject(java.lang.Object o)
This method tests if a connection is closed or not

Specified by:
checkThisObject in interface PoolHelper

testThisObject

public boolean testThisObject(java.lang.Object o)
This method tests if a connection is valid or not

Specified by:
testThisObject in interface PoolHelper

create

public GenerationObject create()
                        throws java.sql.SQLException
Specified by:
create in interface PoolHelper
Throws:
java.sql.SQLException

create

public GenerationObject create(java.lang.String _user,
                               java.lang.String _password)
                        throws java.sql.SQLException
Specified by:
create in interface PoolHelper
Throws:
java.sql.SQLException

stopPool

public void stopPool()
stop method to switch off the pool


shutdown

public void shutdown(boolean force)
Description copied from class: CoreDataSource
shutdown is a placeholder for datasources which should shut down any pools which they maintain.

Overrides:
shutdown in class CoreDataSource

setLogWriter

public void setLogWriter(java.io.PrintWriter logWriter)
set the logwriter for the current object, the logwriter will be use by the current object and by the generic pool

Specified by:
setLogWriter in interface javax.sql.DataSource
Overrides:
setLogWriter in class CoreDataSource
Parameters:
logWriter - a PrintWriter object

setDebug

public void setDebug(boolean debug)
set the debug flag

Overrides:
setDebug in class CoreDataSource
Parameters:
debug - a boolean flag

setMinSize

public void setMinSize(int minSize)
                throws java.lang.Exception
set the minimum size of the pool

Parameters:
minSize - minimum size of the pool
Throws:
java.lang.Exception

setMaxSize

public void setMaxSize(int maxSize)
                throws java.lang.Exception
set the maximum size of the pool

Parameters:
maxSize - maximum size of the pool
Throws:
java.lang.Exception

setLifeTime

public void setLifeTime(long lifeTime)
set the life time of the pooled objects

Parameters:
lifeTime - life time of the pooled objects (in milliseconds)

setSleepTime

public void setSleepTime(long sleepTime)
set the sleep time of pooled objects

Parameters:
sleepTime - sleep time of the pooled objects (in milliseconds)

setGC

public void setGC(boolean gc)
set the garbage collection option

Parameters:
gc - true: the garbage collector will be launched when clean up of the pool, else false

setCheckLevelObject

public void setCheckLevelObject(int checkLevelObject)
set the check level of the pooled object before using them

Parameters:
checkLevelObject - (
0 = no special checking 1 = just a check on an object 2 = test the object 3 = just a check on an object (for all the objects) 4 = test the object (for all the objects)

setJdbcTestStmt

public void setJdbcTestStmt(java.lang.String jdbcTestStmt)
set the String to test the jdbc connection before using it

Parameters:
jdbcTestStmt - an sql statement

setGeneration

public void setGeneration(int generation)
set the generation number for future connection, the generation number is used to identify a group a created objects

Parameters:
generation - an integer value which represents a generation

setDeadLockMaxWait

public void setDeadLockMaxWait(long deadLock)
set the global time the pool can wait for a free object

Parameters:
deadLock - in milliseconds

setDeadLockRetryWait

public void setDeadLockRetryWait(long loopWait)
set the time before 2 tries when trying to obtain an object from the pool

Parameters:
loopWait - in milliseconds

getLogWriter

public java.io.PrintWriter getLogWriter()
Specified by:
getLogWriter in interface javax.sql.DataSource
Overrides:
getLogWriter in class CoreDataSource

getMinSize

public int getMinSize()

getMaxSize

public int getMaxSize()

getLifeTime

public long getLifeTime()

getSleepTime

public long getSleepTime()

getGeneration

public int getGeneration()

isGC

public boolean isGC()

getLockedObjectCount

public int getLockedObjectCount()

getUnlockedObjectCount

public int getUnlockedObjectCount()

getCheckLevelObject

public int getCheckLevelObject()

getJdbcTestStmt

public java.lang.String getJdbcTestStmt()

getDeadLockMaxWait

public long getDeadLockMaxWait()

getDeadLockRetryWait

public long getDeadLockRetryWait()

toString

public java.lang.String toString()
Specified by:
toString in interface PoolHelper
Overrides:
toString in class CoreDataSource

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Retrieves the Reference of this object. Used at binding time by JNDI to build a reference on this object.

Specified by:
getReference in interface javax.naming.Referenceable
Overrides:
getReference in class CoreDataSource
Returns:
The non-null Reference of this object.
Throws:
javax.naming.NamingException - If a naming exception was encountered while retrieving the reference.

getObjectInstance

public java.lang.Object getObjectInstance(java.lang.Object refObj,
                                          javax.naming.Name name,
                                          javax.naming.Context nameCtx,
                                          java.util.Hashtable env)
                                   throws java.lang.Exception
Description copied from class: CoreDataSource
Methods inherited from ObjectFactory

Specified by:
getObjectInstance in interface javax.naming.spi.ObjectFactory
Overrides:
getObjectInstance in class CoreDataSource
Throws:
java.lang.Exception

setThreadFactory

public void setThreadFactory(JdbcThreadFactory tf)
Override this so that the pool's tf gets set as well

Overrides:
setThreadFactory in class CoreDataSource