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

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

public class ConnectionPool
extends Object
implements DataSource

This class manages a database connection pool.
Connections are wrapped by a LuteceConnection to avoid explicit calls to Connection.close(). Connections are released to this pool when Connection.close() is called, and are not actually closed until release() call.

See Also:
LuteceConnection

Constructor Summary
ConnectionPool(String strName, String strUrl, String strUser, String strPassword, int nMaxConns, int nInitConns, int nTimeOut, org.apache.log4j.Logger logger, String strCheckValidConnectionSql)
          Constructor.
 
Method Summary
 void freeConnection(Connection conn)
          Returns a connection to pool.
 int getBusyConnectionCount()
          Returns the number of busy connections of the pool (available or busy)
 Connection getConnection()
          Returns a connection from the pool.
 Connection getConnection(String username, String password)
          Returns the connection of the pool.
 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()
          Get loging timeout.
 PrintWriter getLogWriter()
          Get the log.
 int getMaxConnectionCount()
          Returns the maximum number of connections of the pool
 Logger getParentLogger()
          Implementation of JDBC 4.1's getParentLogger method (Java 7)
 boolean isWrapperFor(Class<?> iface)
          Get the wrapper.
 void release()
          Releases the pool by closing all its connections.
 void setLoginTimeout(int seconds)
          Set Login Timeout.
 void setLogWriter(PrintWriter out)
          Set the log.
<T> T
unwrap(Class<T> iface)
          Get the unwrap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(String strName,
                      String strUrl,
                      String strUser,
                      String strPassword,
                      int nMaxConns,
                      int nInitConns,
                      int nTimeOut,
                      org.apache.log4j.Logger logger,
                      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 Connection getConnection()
                         throws SQLException
Returns a connection from the pool.

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

freeConnection

public void freeConnection(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 Connection getConnection(String username,
                                String password)
                         throws SQLException
Returns the connection of the pool.

Specified by:
getConnection in interface DataSource
Parameters:
username - the username
password - the password
Returns:
A connection
Throws:
SQLException - the sQL exception

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Get the log.

Specified by:
getLogWriter in interface CommonDataSource
Returns:
A log writer
Throws:
SQLException - the sQL exception

setLogWriter

public void setLogWriter(PrintWriter out)
                  throws SQLException
Set the log.

Specified by:
setLogWriter in interface CommonDataSource
Parameters:
out - the new log writer
Throws:
SQLException - the sQL exception

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws SQLException
Set Login Timeout.

Specified by:
setLoginTimeout in interface CommonDataSource
Parameters:
seconds - the new login timeout
Throws:
SQLException - the sQL exception

getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Get loging timeout.

Specified by:
getLoginTimeout in interface CommonDataSource
Returns:
A time out
Throws:
SQLException - the sQL exception

unwrap

public <T> T unwrap(Class<T> iface)
         throws SQLException
Get the unwrap.

Specified by:
unwrap in interface Wrapper
Type Parameters:
T - the generic type
Parameters:
iface - the iface
Returns:
null
Throws:
SQLException - the sQL exception

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
                     throws SQLException
Get the wrapper.

Specified by:
isWrapperFor in interface Wrapper
Parameters:
iface - the iface
Returns:
false
Throws:
SQLException - the sQL exception

getParentLogger

public Logger getParentLogger()
Implementation of JDBC 4.1's getParentLogger method (Java 7)

Returns:
the parent logger


Copyright © 2014 Mairie de Paris. All Rights Reserved.