com.opencms.dbpool
Class CmsPool

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.opencms.dbpool.CmsPool
All Implemented Interfaces:
Runnable

public class CmsPool
extends Thread

This class is used to create an connection-pool for opencms.

Author:
Andreas Schouten

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CmsPool(String poolname, String driver, String url, String user, String password, int minConn, int maxConn, int increasRate, int timeout, int maxage)
          Creates a new Pool.
CmsPool(String poolname, String driver, String url, String user, String password, int minConn, int maxConn, int increasRate, int timeout, int maxage, String conTestQuery)
          Creates a new Pool.
 
Method Summary
 Connection connect()
          Try to make a database connection to the given database.
 void destroy()
          Destroys this pool.
 void putConnection(CmsConnection con)
          Puts a connection back to the pool.
 void run()
          The run-method for the connection-guard
protected  boolean testConnection(Connection con)
          Test the connection by executing an select statement.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsPool

public CmsPool(String poolname,
               String driver,
               String url,
               String user,
               String password,
               int minConn,
               int maxConn,
               int increasRate,
               int timeout,
               int maxage)
        throws SQLException
Creates a new Pool.

Parameters:
poolname - - the name of this pool.
driver - - the classname of the driver.
url - - the url to connect to the database.
user - - the user to access the db.
password - - the password to connect to the db.
minConn - - the minimum amount Connections maintained in the pool.
maxConn - - the maximum amount Connections maintained in the pool.
timeout - - the timout after a unused connection has to be closed.
Throws:
SQLException - - if a SQL-Error occurs.

CmsPool

public CmsPool(String poolname,
               String driver,
               String url,
               String user,
               String password,
               int minConn,
               int maxConn,
               int increasRate,
               int timeout,
               int maxage,
               String conTestQuery)
        throws SQLException
Creates a new Pool.

Parameters:
poolname - - the name of this pool.
driver - - the classname of the driver.
url - - the url to connect to the database.
user - - the user to access the db.
password - - the password to connect to the db.
minConn - - the minimum amount Connections maintained in the pool.
maxConn - - the maximum amount Connections maintained in the pool.
timeout - - the timout after a unused connection has to be closed.
conTestQuery - - the test query to test a connection before delivering. If this is set to null, no test will be performed.
Throws:
SQLException - - if a SQL-Error occurs.
Method Detail

run

public void run()
The run-method for the connection-guard

Specified by:
run in interface Runnable
Overrides:
run in class Thread

connect

public Connection connect()
                   throws SQLException
Try to make a database connection to the given database.

Returns:
a Connection to the database
Throws:
SQLException - if a database-access error occurs.

putConnection

public void putConnection(CmsConnection con)
Puts a connection back to the pool.


toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Thread

destroy

public void destroy()
Destroys this pool.

Overrides:
destroy in class Thread

testConnection

protected boolean testConnection(Connection con)
Test the connection by executing an select statement. This is done only if the statement is defined in opencms.properties. Normally there is no need for this testing - but in difficult environments (like firewalls) you can use it to find out whats going wrong.

Parameters:
con - The connection to test.
Returns:
true if the connection could be tested without an SQLException. Returns true if there is no test-statement defined in opencms.properties. Returns false if there was an SQLException by executing the statement.