fr.paris.lutece.util.pool.service
Class ConnectionPool

java.lang.Object
  extended by fr.paris.lutece.util.pool.service.ConnectionPool
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

public class ConnectionPool
extends java.lang.Object
implements javax.sql.DataSource

This class manages a database connection pool.


Constructor Summary
ConnectionPool(java.lang.String strName, java.lang.String strUrl, java.lang.String strUser, java.lang.String strPassword, int nMaxConns, int nInitConns, int nTimeOut, org.apache.log4j.Logger logger, java.lang.String strCheckValidConnectionSql)
          Constructor
 
Method Summary
 void freeConnection(java.sql.Connection conn)
          Returns a connection to pool.
 int getBusyConnectionCount()
          Returns the number of busy connections of the pool (available or busy)
 java.sql.Connection getConnection()
          Returns a connection from the pool.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
           
 int getConnectionCount()
          Returns the number of connections opened by the pool (available or busy)
 int getFreeConnectionCount()
          Returns the number of free connections of the pool (available or busy)
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 int getMaxConnectionCount()
          Returns the maximum number of connections of the pool
 boolean isWrapperFor(java.lang.Class<?> iface)
           
 void release()
          Releases the pool by closing all its connections.
 void setLoginTimeout(int seconds)
           
 void setLogWriter(java.io.PrintWriter out)
           
<T> T
unwrap(java.lang.Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(java.lang.String strName,
                      java.lang.String strUrl,
                      java.lang.String strUser,
                      java.lang.String strPassword,
                      int nMaxConns,
                      int nInitConns,
                      int nTimeOut,
                      org.apache.log4j.Logger logger,
                      java.lang.String strCheckValidConnectionSql)
Constructor

Parameters:
strName - Nom du pool
strUrl - JDBC Data source URL
strUser - SQL User
strPassword - SQL Password
nMaxConns - Max connections
nInitConns - Initials connections
nTimeOut - Timeout to get a connection
logger - the Logger object
strCheckValidConnectionSql - The SQL syntax used for check connexion validatation
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns a connection from the pool.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
An open connection
Throws:
java.sql.SQLException - The SQL exception

freeConnection

public void freeConnection(java.sql.Connection conn)
Returns a connection to pool.

Parameters:
conn - The released connection to return to pool

release

public void release()
Releases the pool by closing all its connections.


getConnectionCount

public int getConnectionCount()
Returns the number of connections opened by the pool (available or busy)

Returns:
A connection count

getFreeConnectionCount

public int getFreeConnectionCount()
Returns the number of free connections of the pool (available or busy)

Returns:
A connection count

getBusyConnectionCount

public int getBusyConnectionCount()
Returns the number of busy connections of the pool (available or busy)

Returns:
A connection count

getMaxConnectionCount

public int getMaxConnectionCount()
Returns the maximum number of connections of the pool

Returns:
A connection count

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Specified by:
getLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Specified by:
setLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException


Copyright © 2010 Mairie de Paris. All Rights Reserved.