org.enhydra.jdbc.pool
Class StandardPoolDataSource

java.lang.Object
  |
  +--org.enhydra.jdbc.core.CoreDataSource
        |
        +--org.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
           
 javax.naming.Context ictx
           
 boolean onOff
           
 GenericPool pool
           
 
Fields inherited from class org.enhydra.jdbc.core.CoreDataSource
logWriter, password, user
 
Constructor Summary
StandardPoolDataSource()
          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()
           
 javax.naming.Reference getReference()
          Retrieves the Reference of this object.
 long getSleepTime()
           
 int getUnlockedObjectCount()
           
 void initContext()
           
 boolean isGC()
           
 void setCheckLevelObject(int checkLevelObject)
           
 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)
           
 void setDeadLockRetryWait(long loopWait)
           
 void setDebug(boolean debug)
           
 void setGC(boolean gc)
           
 void setGeneration(int generation)
           
 void setJdbcTestStmt(java.lang.String jdbcTestStmt)
           
 void setLifeTime(long lifeTime)
           
 void setLogWriter(java.io.PrintWriter logWriter)
          Set/Get methods
 void setMaxSize(int maxSize)
           
 void setMinSize(int minSize)
           
 void setSleepTime(long sleepTime)
           
 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, getObjectInstance, getPassword, getThreadFactory, getUser, isDebug, isVerbose, log, setDescription, setLoginTimeout, setPassword, setUser, setVerbose
 
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

onOff

public boolean onOff

ictx

public javax.naming.Context ictx
Constructor Detail

StandardPoolDataSource

public StandardPoolDataSource()
Constructor

StandardPoolDataSource

public StandardPoolDataSource(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

initContext

public void initContext()
                 throws java.sql.SQLException

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

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

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

create

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

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/Get methods
Specified by:
setLogWriter in interface javax.sql.DataSource
Overrides:
setLogWriter in class CoreDataSource

setDebug

public void setDebug(boolean debug)
Overrides:
setDebug in class CoreDataSource

setMinSize

public void setMinSize(int minSize)
                throws java.lang.Exception

setMaxSize

public void setMaxSize(int maxSize)
                throws java.lang.Exception

setLifeTime

public void setLifeTime(long lifeTime)

setSleepTime

public void setSleepTime(long sleepTime)

setGC

public void setGC(boolean gc)

setCheckLevelObject

public void setCheckLevelObject(int checkLevelObject)

setJdbcTestStmt

public void setJdbcTestStmt(java.lang.String jdbcTestStmt)

setGeneration

public void setGeneration(int generation)

setDeadLockMaxWait

public void setDeadLockMaxWait(long deadLock)

setDeadLockRetryWait

public void setDeadLockRetryWait(long loopWait)

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()
Overrides:
toString in class java.lang.Object

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.
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.

setThreadFactory

public void setThreadFactory(JdbcThreadFactory tf)
Override this so that the pool's tf gets set as well
Overrides:
setThreadFactory in class CoreDataSource