Class ConnectionPool
- java.lang.Object
-
- 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 aLuteceConnectionto avoid explicit calls toConnection.close(). Connections are released to this pool whenConnection.close()is called, and are not actually closed untilrelease()call.- See Also:
LuteceConnection
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfreeConnection(Connection conn)Returns a connection to pool.intgetBusyConnectionCount()Returns the number of busy connections of the pool (available or busy)ConnectiongetConnection()Returns a connection from the pool.ConnectiongetConnection(String username, String password)Returns the connection of the pool.intgetConnectionCount()Returns the number of connections opened by the pool (available or busy)intgetFreeConnectionCount()Returns the number of free connections of the pool (available or busy)intgetLoginTimeout()Get loging timeout.PrintWritergetLogWriter()Get the log.intgetMaxConnectionCount()Returns the maximum number of connections of the poolLoggergetParentLogger()Implementation of JDBC 4.1's getParentLogger method (Java 7)booleanisWrapperFor(Class<?> iface)Get the wrapper.voidrelease()Releases the pool by closing all its connections.voidsetLoginTimeout(int seconds)Set Login Timeout.voidsetLogWriter(PrintWriter out)Set the log.<T> Tunwrap(Class<T> iface)Get the unwrap.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
Constructor Detail
-
ConnectionPool
public ConnectionPool(String strName, String strUrl, String strUser, String strPassword, int nMaxConns, int nInitConns, int nTimeOut, org.apache.logging.log4j.Logger logger, String strCheckValidConnectionSql)
Constructor.- Parameters:
strName- Nom du poolstrUrl- JDBC Data source URLstrUser- SQL UserstrPassword- SQL PasswordnMaxConns- Max connectionsnInitConns- Initials connectionsnTimeOut- Timeout to get a connectionlogger- the Logger objectstrCheckValidConnectionSql- The SQL syntax used for check connexion validatation
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
Returns a connection from the pool.- Specified by:
getConnectionin interfaceDataSource- 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:
getConnectionin interfaceDataSource- Parameters:
username- the usernamepassword- the password- Returns:
- A connection
- Throws:
SQLException- the sQL exception
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
Get the log.- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Returns:
- A log writer
- Throws:
SQLException- the sQL exception
-
setLogWriter
public void setLogWriter(PrintWriter out) throws SQLException
Set the log.- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Parameters:
out- the new log writer- Throws:
SQLException- the sQL exception
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLExceptionSet Login Timeout.- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Parameters:
seconds- the new login timeout- Throws:
SQLException- the sQL exception
-
getLoginTimeout
public int getLoginTimeout() throws SQLExceptionGet loging timeout.- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Returns:
- A time out
- Throws:
SQLException- the sQL exception
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
Get the unwrap.- Specified by:
unwrapin interfaceWrapper- 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:
isWrapperForin interfaceWrapper- 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)- Specified by:
getParentLoggerin interfaceCommonDataSource- Returns:
- the parent logger
-
-